[Python-checkins] python/dist/src/Lib pickle.py,1.85,1.86
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Mon, 27 Jan 2003 16:48:11 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv10017/Lib
Modified Files:
pickle.py
Log Message:
save(): Fiddled the control flow to put the normal case where it
belongs. This is a much smaller change than it may appear: the bulk
of the function merely got unindented by one level.
Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.85
retrieving revision 1.86
diff -C2 -d -r1.85 -r1.86
*** pickle.py 28 Jan 2003 00:43:26 -0000 1.85
--- pickle.py 28 Jan 2003 00:48:09 -0000 1.86
***************
*** 271,329 ****
f = self.dispatch[t]
except KeyError:
! try:
! issc = issubclass(t, TypeType)
! except TypeError: # t is not a class
! issc = 0
! if issc:
! self.save_global(object)
! return
try:
! reduce = dispatch_table[t]
! except KeyError:
! try:
! reduce = object.__reduce__
! except AttributeError:
! raise PicklingError, \
! "can't pickle %s object: %s" % (`t.__name__`,
! `object`)
! else:
! tup = reduce()
else:
! tup = reduce(object)
!
! if type(tup) is StringType:
! self.save_global(object, tup)
! return
! if type(tup) is not TupleType:
! raise PicklingError, "Value returned by %s must be a " \
! "tuple" % reduce
! l = len(tup)
! if (l != 2) and (l != 3):
! raise PicklingError, "tuple returned by %s must contain " \
! "only two or three elements" % reduce
! callable = tup[0]
! arg_tup = tup[1]
! if l > 2:
! state = tup[2]
! else:
! state = None
! if type(arg_tup) is not TupleType and arg_tup is not None:
! raise PicklingError, "Second element of tuple returned " \
! "by %s must be a tuple" % reduce
! self.save_reduce(callable, arg_tup, state)
! memo_len = len(memo)
! self.write(self.put(memo_len))
! memo[d] = (memo_len, object)
! return
! f(self, object)
def persistent_id(self, object):
--- 271,332 ----
f = self.dispatch[t]
except KeyError:
! pass
! else:
! f(self, object)
! return
+ # The dispatch table doesn't know about type t.
+ try:
+ issc = issubclass(t, TypeType)
+ except TypeError: # t is not a class
+ issc = 0
+ if issc:
+ self.save_global(object)
+ return
+
+ try:
+ reduce = dispatch_table[t]
+ except KeyError:
try:
! reduce = object.__reduce__
! except AttributeError:
! raise PicklingError, \
! "can't pickle %s object: %s" % (`t.__name__`,
! `object`)
else:
! tup = reduce()
! else:
! tup = reduce(object)
! if type(tup) is StringType:
! self.save_global(object, tup)
! return
! if type(tup) is not TupleType:
! raise PicklingError, "Value returned by %s must be a " \
! "tuple" % reduce
! l = len(tup)
! if (l != 2) and (l != 3):
! raise PicklingError, "tuple returned by %s must contain " \
! "only two or three elements" % reduce
! callable = tup[0]
! arg_tup = tup[1]
! if l > 2:
! state = tup[2]
! else:
! state = None
! if type(arg_tup) is not TupleType and arg_tup is not None:
! raise PicklingError, "Second element of tuple returned " \
! "by %s must be a tuple" % reduce
! self.save_reduce(callable, arg_tup, state)
! memo_len = len(memo)
! self.write(self.put(memo_len))
! memo[d] = (memo_len, object)
def persistent_id(self, object):