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


Python pickletools.genops方法代码示例

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


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

示例1: count_opcode

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import genops [as 别名]
def count_opcode(code, pickle):
    n = 0
    for op, dummy, dummy in pickletools.genops(pickle):
        if op.code == code:
            n += 1
    return n

# We can't very well test the extension registry without putting known stuff
# in it, but we have to be careful to restore its original state.  Code
# should do this:
#
#     e = ExtensionSaver(extension_code)
#     try:
#         fiddle w/ the extension registry's stuff for extension_code
#     finally:
#         e.restore() 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:18,代码来源:pickletester.py

示例2: check_frame_opcodes

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import genops [as 别名]
def check_frame_opcodes(self, pickled):
        """
        Check the arguments of FRAME opcodes in a protocol 4+ pickle.
        """
        frame_opcode_size = 9
        last_arg = last_pos = None
        for op, arg, pos in pickletools.genops(pickled):
            if op.name != 'FRAME':
                continue
            if last_pos is not None:
                # The previous frame's size should be equal to the number
                # of bytes up to the current frame.
                frame_size = pos - last_pos - frame_opcode_size
                self.assertEqual(frame_size, last_arg)
            last_arg, last_pos = arg, pos
        # The last frame's size should be equal to the number of bytes up
        # to the pickle's end.
        frame_size = len(pickled) - last_pos - frame_opcode_size
        self.assertEqual(frame_size, last_arg) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:pickletester.py

示例3: opcode_in_pickle

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import genops [as 别名]
def opcode_in_pickle(code, pickle):
    for op, dummy, dummy in pickletools.genops(pickle):
        if op.code == code:
            return True
    return False

# Return the number of times opcode code appears in pickle. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:pickletester.py

示例4: count_opcode

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import genops [as 别名]
def count_opcode(code, pickle):
    n = 0
    for op, dummy, dummy in pickletools.genops(pickle):
        if op.code == code:
            n += 1
    return n 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:pickletester.py

示例5: opcode_in_pickle

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import genops [as 别名]
def opcode_in_pickle(code, pickle):
    for op, dummy, dummy in pickletools.genops(pickle):
        if op.code == code.decode("latin-1"):
            return True
    return False

# Return the number of times opcode code appears in pickle. 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:pickletester.py

示例6: count_opcode

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import genops [as 别名]
def count_opcode(code, pickle):
    n = 0
    for op, dummy, dummy in pickletools.genops(pickle):
        if op.code == code.decode("latin-1"):
            n += 1
    return n 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:pickletester.py

示例7: test_optional_frames

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import genops [as 别名]
def test_optional_frames(self):
        if pickle.HIGHEST_PROTOCOL < 4:
            return

        def remove_frames(pickled, keep_frame=None):
            """Remove frame opcodes from the given pickle."""
            frame_starts = []
            # 1 byte for the opcode and 8 for the argument
            frame_opcode_size = 9
            for opcode, _, pos in pickletools.genops(pickled):
                if opcode.name == 'FRAME':
                    frame_starts.append(pos)

            newpickle = bytearray()
            last_frame_end = 0
            for i, pos in enumerate(frame_starts):
                if keep_frame and keep_frame(i):
                    continue
                newpickle += pickled[last_frame_end:pos]
                last_frame_end = pos + frame_opcode_size
            newpickle += pickled[last_frame_end:]
            return newpickle

        frame_size = self.FRAME_SIZE_TARGET
        num_frames = 20
        obj = [bytes([i]) * frame_size for i in range(num_frames)]

        for proto in range(4, pickle.HIGHEST_PROTOCOL + 1):
            pickled = self.dumps(obj, proto)

            frameless_pickle = remove_frames(pickled)
            self.assertEqual(count_opcode(pickle.FRAME, frameless_pickle), 0)
            self.assertEqual(obj, self.loads(frameless_pickle))

            some_frames_pickle = remove_frames(pickled, lambda i: i % 2)
            self.assertLess(count_opcode(pickle.FRAME, some_frames_pickle),
                            count_opcode(pickle.FRAME, pickled))
            self.assertEqual(obj, self.loads(some_frames_pickle)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:40,代码来源:pickletester.py

示例8: set_pickle

# 需要导入模块: import pickletools [as 别名]
# 或者: from pickletools import genops [as 别名]
def set_pickle(self, pickle):
        self.pickle = pickle
        self.ops = pickletools.genops(BytesIO(pickle)) 
开发者ID:newtdb,项目名称:db,代码行数:5,代码来源:jsonpickle.py


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