Lines Matching refs:pickle
7 import pickle
24 from pickle import bytes_types
32 protocols = range(pickle.HIGHEST_PROTOCOL + 1)
36 def opcode_in_pickle(code, pickle): argument
37 for op, dummy, dummy in pickletools.genops(pickle):
43 def count_opcode(code, pickle): argument
45 for op, dummy, dummy in pickletools.genops(pickle):
834 self.assertEqual(self.loads(pickle.BINSTRING +
836 b'x' * 300 + pickle.STOP,
863 self.check_unpickling_error((pickle.UnpicklingError, OverflowError),
870 self.check_unpickling_error((pickle.UnpicklingError, OverflowError),
893 self.check_unpickling_error((pickle.UnpicklingError, OverflowError),
899 self.check_unpickling_error((pickle.UnpicklingError, OverflowError),
956 self.check_unpickling_error(pickle.UnpicklingError, p)
1222 results.append(pickle.loads(pickle_bytes))
1347 for proto in range(4, pickle.HIGHEST_PROTOCOL + 1):
1358 for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
1368 for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
1379 for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
1501 pickle = self.dumps(n, proto)
1502 got = self.loads(pickle)
1523 pickle = self.dumps(value, proto)
1524 got = self.loads(pickle)
1555 copyreg.pickle(pickling_metaclass, pickling_metaclass.__reduce__)
1609 proto_header = pickle.PROTO + bytes([proto])
1612 self.assertEqual(count_opcode(pickle.PROTO, pickled), 0)
1615 build_none = pickle.NONE + pickle.STOP
1616 badpickle = pickle.PROTO + bytes([oob]) + build_none
1630 self.assertEqual(opcode_in_pickle(pickle.LONG1, s), proto >= 2)
1638 self.assertEqual(opcode_in_pickle(pickle.LONG4, s), proto >= 2)
1642 expected_opcode = {(0, 0): pickle.TUPLE,
1643 (0, 1): pickle.TUPLE,
1644 (0, 2): pickle.TUPLE,
1645 (0, 3): pickle.TUPLE,
1646 (0, 4): pickle.TUPLE,
1648 (1, 0): pickle.EMPTY_TUPLE,
1649 (1, 1): pickle.TUPLE,
1650 (1, 2): pickle.TUPLE,
1651 (1, 3): pickle.TUPLE,
1652 (1, 4): pickle.TUPLE,
1654 (2, 0): pickle.EMPTY_TUPLE,
1655 (2, 1): pickle.TUPLE1,
1656 (2, 2): pickle.TUPLE2,
1657 (2, 3): pickle.TUPLE3,
1658 (2, 4): pickle.TUPLE,
1660 (3, 0): pickle.EMPTY_TUPLE,
1661 (3, 1): pickle.TUPLE1,
1662 (3, 2): pickle.TUPLE2,
1663 (3, 3): pickle.TUPLE3,
1664 (3, 4): pickle.TUPLE,
1681 expected_opcode = {(0, None): pickle.NONE,
1682 (1, None): pickle.NONE,
1683 (2, None): pickle.NONE,
1684 (3, None): pickle.NONE,
1686 (0, True): pickle.INT,
1687 (1, True): pickle.INT,
1688 (2, True): pickle.NEWTRUE,
1689 (3, True): pickle.NEWTRUE,
1691 (0, False): pickle.INT,
1692 (1, False): pickle.INT,
1693 (2, False): pickle.NEWFALSE,
1694 (3, False): pickle.NEWFALSE,
1762 self.assertRaises((TypeError, pickle.UnpicklingError), self.loads, b)
1799 self.produce_global_ext(0x00000001, pickle.EXT1) # smallest EXT1 code
1800 self.produce_global_ext(0x000000ff, pickle.EXT1) # largest EXT1 code
1803 self.produce_global_ext(0x00000100, pickle.EXT2) # smallest EXT2 code
1804 self.produce_global_ext(0x0000ffff, pickle.EXT2) # largest EXT2 code
1805 self.produce_global_ext(0x0000abcd, pickle.EXT2) # check endianness
1808 self.produce_global_ext(0x00010000, pickle.EXT4) # smallest EXT4 code
1809 self.produce_global_ext(0x7fffffff, pickle.EXT4) # largest EXT4 code
1810 self.produce_global_ext(0x12abcdef, pickle.EXT4) # check endianness
1819 num_appends = count_opcode(pickle.APPENDS, s)
1828 num_appends = count_opcode(pickle.APPENDS, s)
1842 num_setitems = count_opcode(pickle.SETITEMS, s)
1851 num_setitems = count_opcode(pickle.SETITEMS, s)
1864 num_additems = count_opcode(pickle.ADDITEMS, s)
1876 num_additems = count_opcode(pickle.ADDITEMS, s)
1892 self.assertEqual(opcode_in_pickle(pickle.NEWOBJ, s),
1894 self.assertFalse(opcode_in_pickle(pickle.NEWOBJ_EX, s))
1912 self.assertEqual(opcode_in_pickle(pickle.NEWOBJ, s),
1914 self.assertFalse(opcode_in_pickle(pickle.NEWOBJ_EX, s))
1932 self.assertFalse(opcode_in_pickle(pickle.NEWOBJ, s))
1933 self.assertEqual(opcode_in_pickle(pickle.NEWOBJ_EX, s),
2014 except pickle.PicklingError:
2018 except pickle.PicklingError:
2078 self.assertFalse(opcode_in_pickle(pickle.LONG, p))
2091 self._check_pickling_with_opcode(obj, pickle.APPEND, proto)
2093 self._check_pickling_with_opcode(obj, pickle.APPENDS, proto)
2099 self._check_pickling_with_opcode(obj, pickle.SETITEM, proto)
2101 self._check_pickling_with_opcode(obj, pickle.SETITEMS, proto)
2156 for proto in range(4, pickle.HIGHEST_PROTOCOL + 1):
2162 count_opcode(pickle.FRAME, pickled))
2173 for proto in range(4, pickle.HIGHEST_PROTOCOL + 1):
2195 n_frames = count_opcode(pickle.FRAME, pickled)
2202 if pickle.HIGHEST_PROTOCOL < 4:
2230 for proto in range(4, pickle.HIGHEST_PROTOCOL + 1):
2234 self.assertEqual(count_opcode(pickle.FRAME, frameless_pickle), 0)
2238 self.assertLess(count_opcode(pickle.FRAME, some_frames_pickle),
2239 count_opcode(pickle.FRAME, pickled))
2252 for proto in range(4, pickle.HIGHEST_PROTOCOL + 1):
2314 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
2326 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
2370 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
2410 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
2440 for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
2441 with self.assertRaises((AttributeError, pickle.PicklingError)):
2446 for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
2447 with self.assertRaises((AttributeError, pickle.PicklingError)):
2451 for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
2452 with self.assertRaises((AttributeError, pickle.PicklingError)):
2487 header = (pickle.BINBYTES +
2514 header = (pickle.BINBYTES8 +
2538 header = (pickle.BINUNICODE +
2569 header = (pickle.BINUNICODE8 +
2739 self.assertEqual(pickle.HIGHEST_PROTOCOL, 4)
2760 self.assertRaises(pickle.PicklingError, BadPickler().dump, 0)
2761 self.assertRaises(pickle.UnpicklingError, BadUnpickler().load)
2828 self.assertRaises(pickle.PicklingError, self.dumps, non_ascii_str, 0)
2829 pickled = pickle.PERSID + non_ascii_str.encode('utf-8') + b'\n.'
2830 self.assertRaises(pickle.UnpicklingError, self.loads, pickled)
3040 return pickle.loads(dumps(obj, 0))
3043 return pickle.loads(pickle.dumps(obj, 0))
3090 for i in range(pickle.HIGHEST_PROTOCOL+1):
3091 p = pickle.dumps(x, i)