本文整理汇总了Python中cPickle.Unpickler方法的典型用法代码示例。如果您正苦于以下问题:Python cPickle.Unpickler方法的具体用法?Python cPickle.Unpickler怎么用?Python cPickle.Unpickler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cPickle
的用法示例。
在下文中一共展示了cPickle.Unpickler方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AllRecords
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import Unpickler [as 别名]
def AllRecords(path=None):
"""Reads all records from the pickled file and returns a list."""
if not path:
path = os.path.join(os.path.dirname(__file__), 'records.pickle')
unpickler = cPickle.Unpickler(open(path, 'r'))
count = 0
rs = []
try:
while True:
r = unpickler.load()
rs.append(r)
count += 1
except EOFError:
pass
sys.stderr.write("Loaded %d records\n" % count)
return rs
示例2: getClient
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import Unpickler [as 别名]
def getClient(
cls, servers, debug=0, pickleProtocol=0,
pickler=pickle.Pickler, unpickler=pickle.Unpickler,
pload=None, pid=None
):
if cls.allowTestCache:
return TestClient(
servers, debug=debug,
pickleProtocol=pickleProtocol, pickler=pickler,
unpickler=unpickler, pload=pload, pid=pid)
elif config.Memcached.Pools.Default.ClientEnabled:
return Client(
servers, debug=debug, pickleProtocol=pickleProtocol,
pickler=pickler, unpickler=unpickler, pload=pload, pid=pid)
else:
return None
示例3: __getitem__
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import Unpickler [as 别名]
def __getitem__(self, key):
try:
value = self.cache[key]
except KeyError:
f = StringIO(self.dict[key])
value = Unpickler(f).load()
if self.writeback:
self.cache[key] = value
return value
示例4: set_location
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import Unpickler [as 别名]
def set_location(self, key):
(key, value) = self.dict.set_location(key)
f = StringIO(value)
return (key, Unpickler(f).load())
示例5: next
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import Unpickler [as 别名]
def next(self):
(key, value) = self.dict.next()
f = StringIO(value)
return (key, Unpickler(f).load())
示例6: previous
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import Unpickler [as 别名]
def previous(self):
(key, value) = self.dict.previous()
f = StringIO(value)
return (key, Unpickler(f).load())
示例7: first
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import Unpickler [as 别名]
def first(self):
(key, value) = self.dict.first()
f = StringIO(value)
return (key, Unpickler(f).load())
示例8: last
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import Unpickler [as 别名]
def last(self):
(key, value) = self.dict.last()
f = StringIO(value)
return (key, Unpickler(f).load())
示例9: loads
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import Unpickler [as 别名]
def loads(self, buf):
f = self.input(buf)
try:
p = cPickle.Unpickler(f)
return p.load()
finally:
self.close(f)
示例10: test_pers_load
# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import Unpickler [as 别名]
def test_pers_load(self):
for binary in [True, False]:
src = StringIO()
p = cPickle.Pickler(src)
p.persistent_id = persistent_id
p.binary = binary
value = MyData('abc')
p.dump(value)
up = cPickle.Unpickler(StringIO(src.getvalue()))
up.persistent_load = persistent_load
res = up.load()
self.assertEqual(res.value, value.value)
# errors
src = StringIO()
p = cPickle.Pickler(src)
p.persistent_id = persistent_id
p.binary = binary
value = MyData('abc')
p.dump(value)
up = cPickle.Unpickler(StringIO(src.getvalue()))
# exceptions vary betwee cPickle & Pickle
try:
up.load()
self.assertUnreachable()
except Exception, e:
pass