mirror of
https://github.com/python/cpython
synced 2026-09-28 07:38:20 +03:00
Restore two features of the original 1.4 pickle:
- which_module() search __main__ last; - load_inst() no longer checks that the classname really refers to a class.
This commit is contained in:
parent
faeae5cd78
commit
8be9a11617
1 changed files with 6 additions and 5 deletions
|
|
@ -128,7 +128,7 @@ the old value, not the modified one. (XXX There are two problems here:
|
||||||
I have no answers. Garbage Collection may also become a problem here.)
|
I have no answers. Garbage Collection may also become a problem here.)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = "1.7" # Code version
|
__version__ = "1.8" # Code version
|
||||||
|
|
||||||
from types import *
|
from types import *
|
||||||
from copy_reg import *
|
from copy_reg import *
|
||||||
|
|
@ -538,7 +538,8 @@ def whichmodule(cls, clsname):
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
for name, module in sys.modules.items():
|
for name, module in sys.modules.items():
|
||||||
if hasattr(module, clsname) and \
|
if name != '__main__' and \
|
||||||
|
hasattr(module, clsname) and \
|
||||||
getattr(module, clsname) is cls:
|
getattr(module, clsname) is cls:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|
@ -677,9 +678,9 @@ class Unpickler:
|
||||||
module = self.readline()[:-1]
|
module = self.readline()[:-1]
|
||||||
name = self.readline()[:-1]
|
name = self.readline()[:-1]
|
||||||
klass = self.find_class(module, name)
|
klass = self.find_class(module, name)
|
||||||
if (type(klass) is not ClassType):
|
## if (type(klass) is not ClassType):
|
||||||
raise SystemError, "Imported object %s from module %s is " \
|
## raise SystemError, "Imported object %s from module %s is " \
|
||||||
"not a class" % (name, module)
|
## "not a class" % (name, module)
|
||||||
|
|
||||||
value = apply(klass, args)
|
value = apply(klass, args)
|
||||||
self.append(value)
|
self.append(value)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue