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


Python pickletools.optimize方法代码示例

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


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

示例1: test_optimize_binput_and_memoize

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import optimize [as 别名]
def test_optimize_binput_and_memoize(self):
        pickled = (b'\x80\x04\x95\x15\x00\x00\x00\x00\x00\x00\x00'
                   b']\x94(\x8c\x04spamq\x01\x8c\x03ham\x94h\x02e.')
        #    0: \x80 PROTO      4
        #    2: \x95 FRAME      21
        #   11: ]    EMPTY_LIST
        #   12: \x94 MEMOIZE
        #   13: (    MARK
        #   14: \x8c     SHORT_BINUNICODE 'spam'
        #   20: q        BINPUT     1
        #   22: \x8c     SHORT_BINUNICODE 'ham'
        #   27: \x94     MEMOIZE
        #   28: h        BINGET     2
        #   30: e        APPENDS    (MARK at 13)
        #   31: .    STOP
        self.assertIn(pickle.BINPUT, pickled)
        unpickled = pickle.loads(pickled)
        self.assertEqual(unpickled, ['spam', 'ham', 'ham'])
        self.assertIs(unpickled[1], unpickled[2])

        pickled2 = pickletools.optimize(pickled)
        unpickled2 = pickle.loads(pickled2)
        self.assertEqual(unpickled2, ['spam', 'ham', 'ham'])
        self.assertIs(unpickled2[1], unpickled2[2])
        self.assertNotIn(pickle.BINPUT, pickled2) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:27,代码来源:test_pickletools.py

示例2: dumps

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import optimize [as 别名]
def dumps(self, arg, proto=0, fast=0):
        return pickletools.optimize(pickle.dumps(arg, proto)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_pickletools.py

示例3: optimize

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import optimize [as 别名]
def optimize(picklestring):
        return picklestring

    # There is no HIGHEST_PROTOCOL in cerealizer. 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:6,代码来源:crash.py

示例4: dumps

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import optimize [as 别名]
def dumps(obj, protocol=HIGHEST_PROTOCOL):
        return zlib.compress(optimize(pickle.dumps(obj)), 9) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:4,代码来源:crash.py

示例5: dumps

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import optimize [as 别名]
def dumps(self, arg, proto=None):
        return pickletools.optimize(pickle.dumps(arg, proto)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:4,代码来源:test_pickletools.py

示例6: test_optimize_long_binget

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import optimize [as 别名]
def test_optimize_long_binget(self):
        data = [str(i) for i in range(257)]
        data.append(data[-1])
        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            pickled = pickle.dumps(data, proto)
            unpickled = pickle.loads(pickled)
            self.assertEqual(unpickled, data)
            self.assertIs(unpickled[-1], unpickled[-2])

            pickled2 = pickletools.optimize(pickled)
            unpickled2 = pickle.loads(pickled2)
            self.assertEqual(unpickled2, data)
            self.assertIs(unpickled2[-1], unpickled2[-2])
            self.assertNotIn(pickle.LONG_BINGET, pickled2)
            self.assertNotIn(pickle.LONG_BINPUT, pickled2) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:test_pickletools.py

示例7: serialize

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import optimize [as 别名]
def serialize(vector):
        """ Serializer a vector using pickle.

        :param np.array vector:
        :return bytes:
        """
        return pickletools.optimize(pickle.dumps(vector, pickle.HIGHEST_PROTOCOL)) 
开发者ID:ThoughtRiver,项目名称:lmdb-embeddings,代码行数:9,代码来源:serializers.py

示例8: marshall_value

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import optimize [as 别名]
def marshall_value(self, value, storeMemoryMap = False):
        """
        Marshalls a Crash object to be used in the database.
        By default the C{memoryMap} member is B{NOT} stored here.

        @warning: Setting the C{storeMemoryMap} argument to C{True} can lead to
            a severe performance penalty!

        @type  value: L{Crash}
        @param value: Object to convert.

        @type  storeMemoryMap: bool
        @param storeMemoryMap: C{True} to store the memory map, C{False}
            otherwise.

        @rtype:  str
        @return: Converted object.
        """
        if hasattr(value, 'memoryMap'):
            crash = value
            memoryMap = crash.memoryMap
            try:
                crash.memoryMap = None
                if storeMemoryMap and memoryMap is not None:
                    # convert the generator to a list
                    crash.memoryMap = list(memoryMap)
                if self.optimizeValues:
                    value = pickle.dumps(crash, protocol = HIGHEST_PROTOCOL)
                    value = optimize(value)
                else:
                    value = pickle.dumps(crash, protocol = 0)
            finally:
                crash.memoryMap = memoryMap
                del memoryMap
                del crash
        if self.compressValues:
            value = zlib.compress(value, zlib.Z_BEST_COMPRESSION)
        if self.escapeValues:
            value = value.encode('hex')
        if self.binaryValues:
            value = buffer(value)
        return value 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:44,代码来源:crash.py


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