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


Python pickle.STOP属性代码示例

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


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

示例1: test_proto

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import STOP [as 别名]
def test_proto(self):
        build_none = pickle.NONE + pickle.STOP
        for proto in protocols:
            expected = build_none
            if proto >= 2:
                expected = pickle.PROTO + chr(proto) + expected
            p = self.dumps(None, proto)
            self.assertEqual(p, expected)

        oob = protocols[-1] + 1     # a future protocol
        badpickle = pickle.PROTO + chr(oob) + build_none
        try:
            self.loads(badpickle)
        except ValueError, detail:
            self.assertTrue(str(detail).startswith(
                                            "unsupported pickle protocol")) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:pickletester.py

示例2: test_proto

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import STOP [as 别名]
def test_proto(self):
        for proto in protocols:
            pickled = self.dumps(None, proto)
            if proto >= 2:
                proto_header = pickle.PROTO + bytes([proto])
                self.assertTrue(pickled.startswith(proto_header))
            else:
                self.assertEqual(count_opcode(pickle.PROTO, pickled), 0)

        oob = protocols[-1] + 1     # a future protocol
        build_none = pickle.NONE + pickle.STOP
        badpickle = pickle.PROTO + bytes([oob]) + build_none
        try:
            self.loads(badpickle)
        except ValueError as err:
            self.assertIn("unsupported pickle protocol", str(err))
        else:
            self.fail("expected bad protocol number to raise ValueError") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:pickletester.py

示例3: test_proto

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import STOP [as 别名]
def test_proto(self):
        build_none = pickle.NONE + pickle.STOP
        for proto in protocols:
            expected = build_none
            if proto >= 2:
                expected = pickle.PROTO + chr(proto) + expected
            p = self.dumps(None, proto)
            self.assertEqual(p, expected)

        oob = protocols[-1] + 1     # a future protocol
        badpickle = pickle.PROTO + chr(oob) + build_none
        try:
            self.loads(badpickle)
        except ValueError, detail:
            self.failUnless(str(detail).startswith(
                                            "unsupported pickle protocol")) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:18,代码来源:pickletester.py

示例4: test_load_classic_instance_error

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import STOP [as 别名]
def test_load_classic_instance_error(self):
        # Issue #28925.
        # Protocol 0 (text mode pickle):
        """
         0: (    MARK
         1: i        INST       '__main__ I' (MARK at 0)
        13: (    MARK
        14: d        DICT       (MARK at 13)
        15: b    BUILD
        16: .    STOP
        """
        pickle0 = ('(i__main__\n'
                   'I\n'
                   '(db.')
        self.assertRaises(MyErr, self.loads, pickle0)

        # Protocol 1 (binary mode pickle)
        """
         0: (    MARK
         1: c        GLOBAL     '__main__ I'
        13: o        OBJ        (MARK at 0)
        14: }    EMPTY_DICT
        15: b    BUILD
        16: .    STOP
        """
        pickle1 = ('(c__main__\n'
                   'I\n'
                   'o}b.')
        self.assertRaises(MyErr, self.loads, pickle1) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:31,代码来源:pickletester.py

示例5: test_bad_stack

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import STOP [as 别名]
def test_bad_stack(self):
        badpickles = [
            '.',                        # STOP
            '0',                        # POP
            '1',                        # POP_MARK
            '2',                        # DUP
            # '(2',                     # PyUnpickler doesn't raise
            'R',                        # REDUCE
            ')R',
            'a',                        # APPEND
            'Na',
            'b',                        # BUILD
            'Nb',
            'd',                        # DICT
            'e',                        # APPENDS
            # '(e',                     # PyUnpickler raises AttributeError
            'i__builtin__\nlist\n',     # INST
            'l',                        # LIST
            'o',                        # OBJ
            '(o',
            'p1\n',                     # PUT
            'q\x00',                    # BINPUT
            'r\x00\x00\x00\x00',        # LONG_BINPUT
            's',                        # SETITEM
            'Ns',
            'NNs',
            't',                        # TUPLE
            'u',                        # SETITEMS
            # '(u',                     # PyUnpickler doesn't raise
            '}(Nu',
            '\x81',                     # NEWOBJ
            ')\x81',
            '\x85',                     # TUPLE1
            '\x86',                     # TUPLE2
            'N\x86',
            '\x87',                     # TUPLE3
            'N\x87',
            'NN\x87',
        ]
        for p in badpickles:
            self.check_unpickling_error(self.bad_stack_errors, p) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:43,代码来源:pickletester.py

示例6: test_bad_mark

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import STOP [as 别名]
def test_bad_mark(self):
        badpickles = [
            # 'N(.',                      # STOP
            'N(2',                      # DUP
            'c__builtin__\nlist\n)(R',  # REDUCE
            'c__builtin__\nlist\n()R',
            ']N(a',                     # APPEND
                                        # BUILD
            'c__builtin__\nValueError\n)R}(b',
            'c__builtin__\nValueError\n)R(}b',
            '(Nd',                      # DICT
            'N(p1\n',                   # PUT
            'N(q\x00',                  # BINPUT
            'N(r\x00\x00\x00\x00',      # LONG_BINPUT
            '}NN(s',                    # SETITEM
            '}N(Ns',
            '}(NNs',
            '}((u',                     # SETITEMS
                                        # NEWOBJ
            'c__builtin__\nlist\n)(\x81',
            'c__builtin__\nlist\n()\x81',
            'N(\x85',                   # TUPLE1
            'NN(\x86',                  # TUPLE2
            'N(N\x86',
            'NNN(\x87',                 # TUPLE3
            'NN(N\x87',
            'N(NN\x87',
        ]
        for p in badpickles:
            self.check_unpickling_error(self.bad_mark_errors, p) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:32,代码来源:pickletester.py

示例7: test_load_long_python2_str_as_bytes

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import STOP [as 别名]
def test_load_long_python2_str_as_bytes(self):
        # From Python 2: pickle.dumps('x' * 300, protocol=1)
        self.assertEqual(self.loads(pickle.BINSTRING +
                                    struct.pack("<I", 300) +
                                    b'x' * 300 + pickle.STOP,
                                    encoding='bytes'), b'x' * 300) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:pickletester.py

示例8: test_frame_readline

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import STOP [as 别名]
def test_frame_readline(self):
        pickled = b'\x80\x04\x95\x05\x00\x00\x00\x00\x00\x00\x00I42\n.'
        #    0: \x80 PROTO      4
        #    2: \x95 FRAME      5
        #   11: I    INT        42
        #   15: .    STOP
        self.assertEqual(self.loads(pickled), 42) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:pickletester.py

示例9: test_bad_mark

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import STOP [as 别名]
def test_bad_mark(self):
        badpickles = [
            # b'N(.',                     # STOP
            b'N(2',                     # DUP
            b'cbuiltins\nlist\n)(R',    # REDUCE
            b'cbuiltins\nlist\n()R',
            b']N(a',                    # APPEND
                                        # BUILD
            b'cbuiltins\nValueError\n)R}(b',
            b'cbuiltins\nValueError\n)R(}b',
            b'(Nd',                     # DICT
            b'N(p1\n',                  # PUT
            b'N(q\x00',                 # BINPUT
            b'N(r\x00\x00\x00\x00',     # LONG_BINPUT
            b'}NN(s',                   # SETITEM
            b'}N(Ns',
            b'}(NNs',
            b'}((u',                    # SETITEMS
            b'cbuiltins\nlist\n)(\x81', # NEWOBJ
            b'cbuiltins\nlist\n()\x81',
            b'N(\x85',                  # TUPLE1
            b'NN(\x86',                 # TUPLE2
            b'N(N\x86',
            b'NNN(\x87',                # TUPLE3
            b'NN(N\x87',
            b'N(NN\x87',
            b']((\x90',                 # ADDITEMS
                                        # NEWOBJ_EX
            b'cbuiltins\nlist\n)}(\x92',
            b'cbuiltins\nlist\n)(}\x92',
            b'cbuiltins\nlist\n()}\x92',
                                        # STACK_GLOBAL
            b'Vbuiltins\n(Vlist\n\x93',
            b'Vbuiltins\nVlist\n(\x93',
            b'N(\x94',                  # MEMOIZE
        ]
        for p in badpickles:
            self.check_unpickling_error(self.bad_mark_errors, p) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:40,代码来源:pickletester.py

示例10: test_load_classic_instance

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import STOP [as 别名]
def test_load_classic_instance(self):
        # See issue5180.  Test loading 2.x pickles that
        # contain an instance of old style class.
        for X, args in [(C, ()), (D, ('x',)), (E, ())]:
            xname = X.__name__.encode('ascii')
            # Protocol 0 (text mode pickle):
            """
             0: (    MARK
             1: i        INST       '__main__ X' (MARK at 0)
            13: p    PUT        0
            16: (    MARK
            17: d        DICT       (MARK at 16)
            18: p    PUT        1
            21: b    BUILD
            22: .    STOP
            """
            pickle0 = ("(i__main__\n"
                       "X\n"
                       "p0\n"
                       "(dp1\nb.").replace('X', xname)
            self.assert_is_copy(X(*args), self.loads(pickle0))

            # Protocol 1 (binary mode pickle)
            """
             0: (    MARK
             1: c        GLOBAL     '__main__ X'
            13: q        BINPUT     0
            15: o        OBJ        (MARK at 0)
            16: q    BINPUT     1
            18: }    EMPTY_DICT
            19: q    BINPUT     2
            21: b    BUILD
            22: .    STOP
            """
            pickle1 = ('(c__main__\n'
                       'X\n'
                       'q\x00oq\x01}q\x02b.').replace('X', xname)
            self.assert_is_copy(X(*args), self.loads(pickle1))

            # Protocol 2 (pickle2 = '\x80\x02' + pickle1)
            """
             0: \x80 PROTO      2
             2: (    MARK
             3: c        GLOBAL     '__main__ X'
            15: q        BINPUT     0
            17: o        OBJ        (MARK at 2)
            18: q    BINPUT     1
            20: }    EMPTY_DICT
            21: q    BINPUT     2
            23: b    BUILD
            24: .    STOP
            """
            pickle2 = ('\x80\x02(c__main__\n'
                       'X\n'
                       'q\x00oq\x01}q\x02b.').replace('X', xname)
            self.assert_is_copy(X(*args), self.loads(pickle2)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:58,代码来源:pickletester.py

示例11: test_load_classic_instance

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import STOP [as 别名]
def test_load_classic_instance(self):
        # See issue5180.  Test loading 2.x pickles that
        # contain an instance of old style class.
        for X, args in [(C, ()), (D, ('x',)), (E, ())]:
            xname = X.__name__.encode('ascii')
            # Protocol 0 (text mode pickle):
            """
             0: (    MARK
             1: i        INST       '__main__ X' (MARK at 0)
            13: p    PUT        0
            16: (    MARK
            17: d        DICT       (MARK at 16)
            18: p    PUT        1
            21: b    BUILD
            22: .    STOP
            """
            pickle0 = (b"(i__main__\n"
                       b"X\n"
                       b"p0\n"
                       b"(dp1\nb.").replace(b'X', xname)
            self.assert_is_copy(X(*args), self.loads(pickle0))

            # Protocol 1 (binary mode pickle)
            """
             0: (    MARK
             1: c        GLOBAL     '__main__ X'
            13: q        BINPUT     0
            15: o        OBJ        (MARK at 0)
            16: q    BINPUT     1
            18: }    EMPTY_DICT
            19: q    BINPUT     2
            21: b    BUILD
            22: .    STOP
            """
            pickle1 = (b'(c__main__\n'
                       b'X\n'
                       b'q\x00oq\x01}q\x02b.').replace(b'X', xname)
            self.assert_is_copy(X(*args), self.loads(pickle1))

            # Protocol 2 (pickle2 = b'\x80\x02' + pickle1)
            """
             0: \x80 PROTO      2
             2: (    MARK
             3: c        GLOBAL     '__main__ X'
            15: q        BINPUT     0
            17: o        OBJ        (MARK at 2)
            18: q    BINPUT     1
            20: }    EMPTY_DICT
            21: q    BINPUT     2
            23: b    BUILD
            24: .    STOP
            """
            pickle2 = (b'\x80\x02(c__main__\n'
                       b'X\n'
                       b'q\x00oq\x01}q\x02b.').replace(b'X', xname)
            self.assert_is_copy(X(*args), self.loads(pickle2)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:58,代码来源:pickletester.py

示例12: test_bad_stack

# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import STOP [as 别名]
def test_bad_stack(self):
        badpickles = [
            b'.',                       # STOP
            b'0',                       # POP
            b'1',                       # POP_MARK
            b'2',                       # DUP
            # b'(2',                    # PyUnpickler doesn't raise
            b'R',                       # REDUCE
            b')R',
            b'a',                       # APPEND
            b'Na',
            b'b',                       # BUILD
            b'Nb',
            b'd',                       # DICT
            b'e',                       # APPENDS
            # b'(e',                    # PyUnpickler raises AttributeError
            b'ibuiltins\nlist\n',       # INST
            b'l',                       # LIST
            b'o',                       # OBJ
            b'(o',
            b'p1\n',                    # PUT
            b'q\x00',                   # BINPUT
            b'r\x00\x00\x00\x00',       # LONG_BINPUT
            b's',                       # SETITEM
            b'Ns',
            b'NNs',
            b't',                       # TUPLE
            b'u',                       # SETITEMS
            # b'(u',                    # PyUnpickler doesn't raise
            b'}(Nu',
            b'\x81',                    # NEWOBJ
            b')\x81',
            b'\x85',                    # TUPLE1
            b'\x86',                    # TUPLE2
            b'N\x86',
            b'\x87',                    # TUPLE3
            b'N\x87',
            b'NN\x87',
            b'\x90',                    # ADDITEMS
            # b'(\x90',                 # PyUnpickler raises AttributeError
            b'\x91',                    # FROZENSET
            b'\x92',                    # NEWOBJ_EX
            b')}\x92',
            b'\x93',                    # STACK_GLOBAL
            b'Vlist\n\x93',
            b'\x94',                    # MEMOIZE
        ]
        for p in badpickles:
            self.check_unpickling_error(self.bad_stack_errors, p) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:51,代码来源:pickletester.py


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