MCPcopy Index your code
hub / github.com/python/cpython / produce_global_ext

Method produce_global_ext

Lib/test/pickletester.py:3513–3539  ·  view source on GitHub ↗
(self, extcode, opcode)

Source from the content-addressed store, hash-verified

3511 # (EXT[124]) under proto 2, and not in proto 1.
3512
3513 def produce_global_ext(self, extcode, opcode):
3514 e = ExtensionSaver(extcode)
3515 try:
3516 copyreg.add_extension(MyList.__module__, "MyList", extcode)
3517 x = MyList([1, 2, 3])
3518 x.foo = 42
3519 x.bar = "hello"
3520
3521 # Dump using protocol 1 for comparison.
3522 s1 = self.dumps(x, 1)
3523 self.assertIn(MyList.__module__.encode(), s1)
3524 self.assertIn(b"MyList", s1)
3525 self.assertFalse(opcode_in_pickle(opcode, s1))
3526
3527 y = self.loads(s1)
3528 self.assert_is_copy(x, y)
3529
3530 # Dump using protocol 2 for test.
3531 s2 = self.dumps(x, 2)
3532 self.assertNotIn(MyList.__module__.encode(), s2)
3533 self.assertNotIn(b"MyList", s2)
3534 self.assertEqual(opcode_in_pickle(opcode, s2), True, repr(s2))
3535
3536 y = self.loads(s2)
3537 self.assert_is_copy(x, y)
3538 finally:
3539 e.restore()
3540
3541 def test_global_ext1(self):
3542 self.produce_global_ext(0x00000001, pickle.EXT1) # smallest EXT1 code

Callers 3

test_global_ext1Method · 0.95
test_global_ext2Method · 0.95
test_global_ext4Method · 0.95

Calls 12

restoreMethod · 0.95
ExtensionSaverClass · 0.85
opcode_in_pickleFunction · 0.85
assertInMethod · 0.80
assertFalseMethod · 0.80
assert_is_copyMethod · 0.80
assertNotInMethod · 0.80
MyListClass · 0.70
dumpsMethod · 0.45
encodeMethod · 0.45
loadsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected