当前位置: 首页>>代码示例>>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;未经允许,请勿转载。