本文整理匯總了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