[Python-checkins] python/dist/src/Lib pickle.py,1.122,1.123

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Wed, 29 Jan 2003 09:58:46 -0800


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

Modified Files:
	pickle.py 
Log Message:
Implement appropriate __getnewargs__ for all immutable subclassable builtin
types.  The special handling for these can now be removed from save_newobj().
Add some testing for this.

Also add support for setting the 'fast' flag on the Python Pickler class,
which suppresses use of the memo.

Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.122
retrieving revision 1.123
diff -C2 -d -r1.122 -r1.123
*** pickle.py	29 Jan 2003 06:16:12 -0000	1.122
--- pickle.py	29 Jan 2003 17:58:43 -0000	1.123
***************
*** 192,195 ****
--- 192,196 ----
          self.proto = int(proto)
          self.bin = proto >= 1
+         self.fast = 0
  
      def clear_memo(self):
***************
*** 231,234 ****
--- 232,237 ----
          # scheme allows the Unpickler memo to be implemented as a plain (but
          # growable) array, indexed by memo key.
+         if self.fast:
+             return
          memo_len = len(self.memo)
          self.write(self.put(memo_len))
***************
*** 379,390 ****
              args = getnewargs()         # This bette not reference obj
          else:
!             # XXX These types should each grow a __getnewargs__
!             # implementation so this special-casing is unnecessary.
!             for cls in int, long, float, complex, str, UnicodeType, tuple:
!                 if cls and isinstance(obj, cls):
!                     args = (cls(obj),)
!                     break
!             else:
!                 args = ()
  
          save = self.save
--- 382,386 ----
              args = getnewargs()         # This bette not reference obj
          else:
!             args = ()
  
          save = self.save