[Python-checkins] python/dist/src/Lib pickle.py,1.113,1.114
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Tue, 28 Jan 2003 09:55:09 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv2961
Modified Files:
pickle.py
Log Message:
Some experimental support for generating NEWOBJ with proto=2, and
fixed a bug in load_newobj().
Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.113
retrieving revision 1.114
diff -C2 -d -r1.113 -r1.114
*** pickle.py 28 Jan 2003 16:58:41 -0000 1.113
--- pickle.py 28 Jan 2003 17:55:01 -0000 1.114
***************
*** 78,81 ****
--- 78,82 ----
self.value = value
+ # Jython has PyStringMap; it's a dict subclass with string keys
try:
from org.python.core import PyStringMap
***************
*** 83,86 ****
--- 84,88 ----
PyStringMap = None
+ # UnicodeType may or may not be exported (normally imported from types)
try:
UnicodeType
***************
*** 250,254 ****
return GET + `i` + '\n'
! def save(self, obj):
# Check for persistent id (defined by a subclass)
pid = self.persistent_id(obj)
--- 252,259 ----
return GET + `i` + '\n'
! def save(self, obj,
! _builtin_type = (int, long, float, complex, str, unicode,
! tuple, list, dict),
! ):
# Check for persistent id (defined by a subclass)
pid = self.persistent_id(obj)
***************
*** 279,282 ****
--- 284,311 ----
return
+ # Check for instance of subclass of common built-in types
+ # XXX This block is experimental code that will go away!
+ if self.proto >= 2:
+ if isinstance(obj, _builtin_type):
+ assert t not in _builtin_type # Proper subclass
+ args = ()
+ getnewargs = getattr(obj, "__getnewargs__", None)
+ if getnewargs:
+ args = getnewargs() # This better not reference obj
+ self.save_global(t)
+ self.save(args)
+ self.write(NEWOBJ)
+ self.memoize(obj)
+ getstate = getattr(obj, "__getstate__", None)
+ if getstate:
+ state = getstate()
+ else:
+ state = getattr(obj, "__dict__", None)
+ # XXX What about __slots__?
+ if state is not None:
+ self.save(state)
+ self.write(BUILD)
+ return
+
# Check copy_reg.dispatch_table
reduce = dispatch_table.get(t)
***************
*** 971,975 ****
cls = self.stack[-1]
obj = cls.__new__(cls, *args)
! self.stack[-1:] = obj
dispatch[NEWOBJ] = load_newobj
--- 1000,1004 ----
cls = self.stack[-1]
obj = cls.__new__(cls, *args)
! self.stack[-1] = obj
dispatch[NEWOBJ] = load_newobj