[Python-checkins] python/dist/src/Lib pickle.py,1.117,1.118

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Tue, 28 Jan 2003 14:29:20 -0800


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

Modified Files:
	pickle.py 
Log Message:
Get rid of __safe_for_unpickling__ and safe_constructors.

Also tidied up a few lines, got rid of apply(), added a comment.


Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.117
retrieving revision 1.118
diff -C2 -d -r1.117 -r1.118
*** pickle.py	28 Jan 2003 22:01:16 -0000	1.117
--- pickle.py	28 Jan 2003 22:29:13 -0000	1.118
***************
*** 28,32 ****
  
  from types import *
! from copy_reg import dispatch_table, safe_constructors, _reconstructor
  import marshal
  import sys
--- 28,32 ----
  
  from types import *
! from copy_reg import dispatch_table, _reconstructor
  import marshal
  import sys
***************
*** 376,381 ****
              args = getnewargs()         # This bette not reference obj
          else:
!             for cls in int, long, float, complex, str, unicode, tuple:
!                 if isinstance(obj, cls):
                      args = (cls(obj),)
                      break
--- 376,381 ----
              args = getnewargs()         # This bette not reference obj
          else:
!             for cls in int, long, float, complex, str, UnicodeType, tuple:
!                 if cls and isinstance(obj, cls):
                      args = (cls(obj),)
                      break
***************
*** 1031,1038 ****
          if not instantiated:
              try:
!                 if not hasattr(klass, '__safe_for_unpickling__'):
!                     raise UnpicklingError('%s is not safe for unpickling' %
!                                           klass)
!                 value = apply(klass, args)
              except TypeError, err:
                  raise TypeError, "in constructor for %s: %s" % (
--- 1031,1035 ----
          if not instantiated:
              try:
!                 value = klass(*args)
              except TypeError, err:
                  raise TypeError, "in constructor for %s: %s" % (
***************
*** 1060,1064 ****
                  pass
          if not instantiated:
!             value = apply(klass, args)
          self.append(value)
      dispatch[OBJ] = load_obj
--- 1057,1061 ----
                  pass
          if not instantiated:
!             value = klass(*args)
          self.append(value)
      dispatch[OBJ] = load_obj
***************
*** 1079,1082 ****
--- 1076,1080 ----
  
      def find_class(self, module, name):
+         # Subclasses may override this
          __import__(module)
          mod = sys.modules[module]
***************
*** 1086,1113 ****
      def load_reduce(self):
          stack = self.stack
! 
!         callable = stack[-2]
!         arg_tup  = stack[-1]
!         del stack[-2:]
! 
!         if type(callable) is not ClassType:
!             if not callable in safe_constructors:
!                 try:
!                     safe = callable.__safe_for_unpickling__
!                 except AttributeError:
!                     safe = None
! 
!                 if not safe:
!                     raise UnpicklingError, "%s is not safe for " \
!                                            "unpickling" % callable
! 
!         if arg_tup is None:
              # A hack for Jim Fulton's ExtensionClass, now deprecated
              warnings.warn("__basicnew__ special case is deprecated",
                            DeprecationWarning)
!             value = callable.__basicnew__()
          else:
!             value = apply(callable, arg_tup)
!         self.append(value)
      dispatch[REDUCE] = load_reduce
  
--- 1084,1097 ----
      def load_reduce(self):
          stack = self.stack
!         args = stack.pop()
!         func = stack[-1]
!         if args is None:
              # A hack for Jim Fulton's ExtensionClass, now deprecated
              warnings.warn("__basicnew__ special case is deprecated",
                            DeprecationWarning)
!             value = func.__basicnew__()
          else:
!             value = func(*args)
!         stack[-1] = value
      dispatch[REDUCE] = load_reduce