當前位置: 首頁>>代碼示例>>Python>>正文


Python cPickle.Unpickler方法代碼示例

本文整理匯總了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 
開發者ID:danvk,項目名稱:oldnyc,代碼行數:20,代碼來源:record.py

示例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 
開發者ID:apple,項目名稱:ccs-calendarserver,代碼行數:19,代碼來源:memcacheclient.py

示例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 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:11,代碼來源:shelve.py

示例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()) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:6,代碼來源:shelve.py

示例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()) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:6,代碼來源:shelve.py

示例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()) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:6,代碼來源:shelve.py

示例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()) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:6,代碼來源:shelve.py

示例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()) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:shelve.py

示例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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_cpickle.py

示例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 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:35,代碼來源:test_cPickle.py


注:本文中的cPickle.Unpickler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。