当前位置: 首页>>代码示例>>Python>>正文


Python pickle.Pickler方法代码示例

本文整理汇总了Python中pickle.Pickler方法的典型用法代码示例。如果您正苦于以下问题:Python pickle.Pickler方法的具体用法?Python pickle.Pickler怎么用?Python pickle.Pickler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pickle的用法示例。


在下文中一共展示了pickle.Pickler方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [as 别名]
def save(self, obj):
        # Remove the tag.trace attribute from Variable and Apply nodes
        if isinstance(obj, theano.gof.utils.scratchpad):
            for tag in self.tag_to_remove:
                if hasattr(obj, tag):
                    del obj.__dict__[tag]
        # Remove manually-added docstring of Elemwise ops
        elif (isinstance(obj, theano.tensor.Elemwise)):
            if '__doc__' in obj.__dict__:
                del obj.__dict__['__doc__']

        return Pickler.save(self, obj)


# Make an unpickler that tries encoding byte streams before raising TypeError.
# This is useful with python 3, in order to unpickle files created with
# python 2.
# This code is taken from Pandas, https://github.com/pydata/pandas,
# under the same 3-clause BSD license. 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:21,代码来源:pkl_utils.py

示例2: save

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [as 别名]
def save(self, obj):
        if isinstance(obj, (types.MethodType, type({}.pop))):
            # the Pickler cannot pickle instance methods; here we decompose
            # them into components that make them uniquely identifiable
            if hasattr(obj, '__func__'):
                func_name = obj.__func__.__name__
            else:
                func_name = obj.__name__
            inst = obj.__self__
            if type(inst) == type(pickle):
                obj = _MyHash(func_name, inst.__name__)
            elif inst is None:
                # type(None) or type(module) do not pickle
                obj = _MyHash(func_name, inst)
            else:
                cls = obj.__self__.__class__
                obj = _MyHash(func_name, inst, cls)
        Pickler.save(self, obj) 
开发者ID:fridiculous,项目名称:estimators,代码行数:20,代码来源:hashing.py

示例3: save_global

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [as 别名]
def save_global(self, obj, name=None, pack=struct.pack):
        # We have to override this method in order to deal with objects
        # defined interactively in IPython that are not injected in
        # __main__
        kwargs = dict(name=name, pack=pack)
        if sys.version_info >= (3, 4):
            del kwargs['pack']
        try:
            Pickler.save_global(self, obj, **kwargs)
        except pickle.PicklingError:
            Pickler.save_global(self, obj, **kwargs)
            module = getattr(obj, "__module__", None)
            if module == '__main__':
                my_name = name
                if my_name is None:
                    my_name = obj.__name__
                mod = sys.modules[module]
                if not hasattr(mod, my_name):
                    # IPython doesn't inject the variables define
                    # interactively in __main__
                    setattr(mod, my_name, obj) 
开发者ID:fridiculous,项目名称:estimators,代码行数:23,代码来源:hashing.py

示例4: test_priming_pickler_memo

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [as 别名]
def test_priming_pickler_memo(self):
        # Verify that we can set the Pickler's memo attribute.
        data = ["abcdefg", "abcdefg", 44]
        f = io.BytesIO()
        pickler = self.pickler_class(f)

        pickler.dump(data)
        first_pickled = f.getvalue()

        f = io.BytesIO()
        primed = self.pickler_class(f)
        primed.memo = pickler.memo

        primed.dump(data)
        primed_pickled = f.getvalue()

        self.assertNotEqual(first_pickled, primed_pickled) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:pickletester.py

示例5: getClient

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [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

示例6: RMUserData_adaptToSQLite

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [as 别名]
def RMUserData_adaptToSQLite(userData):
    if userData == None:
        return None

    outputStream = StringIO()
    pickler = pickle.Pickler(outputStream)
    pickler.dump(userData)
    return outputStream.getvalue() 
开发者ID:sprinkler,项目名称:rainmachine-developer-resources,代码行数:10,代码来源:rmParserUserData.py

示例7: RMParserParams_adaptToSQLite

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [as 别名]
def RMParserParams_adaptToSQLite(params):
    if params == None:
        return None

    outputStream = StringIO()
    pickler = pickle.Pickler(outputStream)
    pickler.dump(params)
    return outputStream.getvalue() 
开发者ID:sprinkler,项目名称:rainmachine-developer-resources,代码行数:10,代码来源:rmParserParams.py

示例8: __setitem__

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [as 别名]
def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        f = StringIO()
        p = Pickler(f, self._protocol)
        p.dump(value)
        self.dict[key] = f.getvalue() 
开发者ID:glmcdona,项目名称:meddle,代码行数:9,代码来源:shelve.py

示例9: dumps

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [as 别名]
def dumps(self, arg, proto=0, fast=0):
        f = StringIO()
        p = pickle.Pickler(f, proto)
        if fast:
            p.fast = fast
        p.dump(arg)
        f.seek(0)
        return f.read() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_pickle.py

示例10: test_pers_load

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [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

示例11: __init__

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [as 别名]
def __init__(self, file, protocol=0, extra_tag_to_remove=None):
        # Can't use super as Pickler isn't a new style class
        Pickler.__init__(self, file, protocol)
        self.tag_to_remove = ['trace', 'test_value']
        if extra_tag_to_remove:
            self.tag_to_remove.extend(extra_tag_to_remove) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:8,代码来源:pkl_utils.py

示例12: __init__

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [as 别名]
def __init__(self, hash_name='md5'):
        self.stream = io.BytesIO()
        # By default we want a pickle protocol that only changes with
        # the major python version and not the minor one
        protocol = (pickle.DEFAULT_PROTOCOL if PY3_OR_LATER
                    else pickle.HIGHEST_PROTOCOL)
        Pickler.__init__(self, self.stream, protocol=protocol)
        # Initialise the hash obj
        self._hash = hashlib.new(hash_name) 
开发者ID:fridiculous,项目名称:estimators,代码行数:11,代码来源:hashing.py

示例13: memoize

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [as 别名]
def memoize(self, obj):
        # We want hashing to be sensitive to value instead of reference.
        # For example we want ['aa', 'aa'] and ['aa', 'aaZ'[:2]]
        # to hash to the same value and that's why we disable memoization
        # for strings
        if isinstance(obj, _bytes_or_unicode):
            return
        Pickler.memoize(self, obj)

    # The dispatch table of the pickler is not accessible in Python
    # 3, as these lines are only bugware for IPython, we skip them. 
开发者ID:fridiculous,项目名称:estimators,代码行数:13,代码来源:hashing.py

示例14: _batch_setitems

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import Pickler [as 别名]
def _batch_setitems(self, items):
        # forces order of keys in dict to ensure consistent hash.
        try:
            # Trying first to compare dict assuming the type of keys is
            # consistent and orderable.
            # This fails on python 3 when keys are unorderable
            # but we keep it in a try as it's faster.
            Pickler._batch_setitems(self, iter(sorted(items)))
        except TypeError:
            # If keys are unorderable, sorting them using their hash. This is
            # slower but works in any case.
            Pickler._batch_setitems(self, iter(sorted((hash(k), v)
                                                      for k, v in items))) 
开发者ID:fridiculous,项目名称:estimators,代码行数:15,代码来源:hashing.py


注:本文中的pickle.Pickler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。