[Python-checkins] python/dist/src/Lib pickle.py,1.132,1.133

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Fri, 31 Jan 2003 09:17:57 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv3262

Modified Files:
	pickle.py 
Log Message:
Pass the object to save_reduce(), so the memoize() call can go into
save_reduce(), before the state is pickled.  This makes it possible
for an object to be referenced from its own (mutable) state.


Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.132
retrieving revision 1.133
diff -C2 -d -r1.132 -r1.133
*** pickle.py	31 Jan 2003 16:51:45 -0000	1.132
--- pickle.py	31 Jan 2003 17:17:49 -0000	1.133
***************
*** 330,335 ****
  
          # Save the reduce() output and finally memoize the object
!         self.save_reduce(func, args, state)
!         self.memoize(obj)
  
      def persistent_id(self, obj):
--- 330,334 ----
  
          # Save the reduce() output and finally memoize the object
!         self.save_reduce(func, args, state, obj)
  
      def persistent_id(self, obj):
***************
*** 345,349 ****
              self.write(PERSID + str(pid) + '\n')
  
!     def save_reduce(self, func, args, state=None):
          # This API is be called by some subclasses
  
--- 344,348 ----
              self.write(PERSID + str(pid) + '\n')
  
!     def save_reduce(self, func, args, state=None, obj=None):
          # This API is be called by some subclasses
  
***************
*** 398,401 ****
--- 397,403 ----
                  raise PicklingError(
                      "args[0] from __newobj__ args has no __new__")
+             if obj is not None and cls is not obj.__class__:
+                 raise PicklingError(
+                     "args[0] from __newobj__ args has the wrong class")
              args = args[1:]
              save(cls)
***************
*** 406,409 ****
--- 408,414 ----
              save(args)
              write(REDUCE)
+ 
+         if obj is not None:
+             self.memoize(obj)
  
          if state is not None: