本文整理汇总了Python中pickle.Unpickler.persistent_load方法的典型用法代码示例。如果您正苦于以下问题:Python Unpickler.persistent_load方法的具体用法?Python Unpickler.persistent_load怎么用?Python Unpickler.persistent_load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pickle.Unpickler
的用法示例。
在下文中一共展示了Unpickler.persistent_load方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loads
# 需要导入模块: from pickle import Unpickler [as 别名]
# 或者: from pickle.Unpickler import persistent_load [as 别名]
def loads(self, s):
up = Unpickler(BytesIO(s))
up.persistent_load = self._get_object
try:
return up.load()
except KeyError as e:
raise UnpicklingError("Could not find Node class for %s" % e)
示例2: unpack
# 需要导入模块: from pickle import Unpickler [as 别名]
# 或者: from pickle.Unpickler import persistent_load [as 别名]
def unpack(self, packet):
from pickle import Unpickler
from io import BytesIO
buffer = BytesIO(packet)
delegate = Unpickler(buffer)
delegate.persistent_load = lambda id: self.world.get_token(int(id))
return delegate.load()
示例3: loads
# 需要导入模块: from pickle import Unpickler [as 别名]
# 或者: from pickle.Unpickler import persistent_load [as 别名]
def loads(self, data):
dst = StringIO(data)
unpickler = Unpickler(dst)
unpickler.persistent_load = self.persistent_load
return unpickler.load()