mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Three independent changes:
- Don't use "from copy_reg import *". - Use cls.__module__ instead of calling whichobject(cls, cls.__name__); also try __module__ in whichmodule(), just in case. - After calling save_reduce(), add the object to the memo.
This commit is contained in:
parent
7cc56eb524
commit
4fb5b28dfc
1 changed files with 10 additions and 5 deletions
|
@ -131,7 +131,7 @@ I have no answers. Garbage Collection may also become a problem here.)
|
||||||
__version__ = "1.8" # Code version
|
__version__ = "1.8" # Code version
|
||||||
|
|
||||||
from types import *
|
from types import *
|
||||||
from copy_reg import *
|
from copy_reg import dispatch_table, safe_constructors
|
||||||
import string, marshal
|
import string, marshal
|
||||||
|
|
||||||
format_version = "1.2" # File format version we write
|
format_version = "1.2" # File format version we write
|
||||||
|
@ -290,6 +290,9 @@ class Pickler:
|
||||||
"by %s must be a tuple" % reduce
|
"by %s must be a tuple" % reduce
|
||||||
|
|
||||||
self.save_reduce(callable, arg_tup, state)
|
self.save_reduce(callable, arg_tup, state)
|
||||||
|
memo_len = len(memo)
|
||||||
|
self.write(self.put(memo_len))
|
||||||
|
memo[d] = (memo_len, object)
|
||||||
return
|
return
|
||||||
|
|
||||||
f(self, object)
|
f(self, object)
|
||||||
|
@ -489,9 +492,7 @@ class Pickler:
|
||||||
if (self.bin):
|
if (self.bin):
|
||||||
write(OBJ + self.put(memo_len))
|
write(OBJ + self.put(memo_len))
|
||||||
else:
|
else:
|
||||||
module = whichmodule(cls, cls.__name__)
|
write(INST + cls.__module__ + '\n' + cls.__name__ + '\n' +
|
||||||
name = cls.__name__
|
|
||||||
write(INST + module + '\n' + name + '\n' +
|
|
||||||
self.put(memo_len))
|
self.put(memo_len))
|
||||||
|
|
||||||
memo[d] = (memo_len, object)
|
memo[d] = (memo_len, object)
|
||||||
|
@ -514,7 +515,10 @@ class Pickler:
|
||||||
if (name is None):
|
if (name is None):
|
||||||
name = object.__name__
|
name = object.__name__
|
||||||
|
|
||||||
module = whichmodule(object, name)
|
try:
|
||||||
|
module = object.__module__
|
||||||
|
except AttributeError:
|
||||||
|
module = whichmodule(object, name)
|
||||||
|
|
||||||
memo_len = len(memo)
|
memo_len = len(memo)
|
||||||
write(GLOBAL + module + '\n' + name + '\n' +
|
write(GLOBAL + module + '\n' + name + '\n' +
|
||||||
|
@ -544,6 +548,7 @@ def _keep_alive(x, memo):
|
||||||
|
|
||||||
classmap = {}
|
classmap = {}
|
||||||
|
|
||||||
|
# This is no longer used to find classes, but still for functions
|
||||||
def whichmodule(cls, clsname):
|
def whichmodule(cls, clsname):
|
||||||
"""Figure out the module in which a class occurs.
|
"""Figure out the module in which a class occurs.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue