summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-01-28 00:48:09 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-01-28 00:48:09 (GMT)
commitb32a8317d7a9c47bf9e6a863f0cc3112a252c66e (patch)
tree5f6368aec9703a7b1d6ebeb94f82dbc37b21b04c
parentc9d7c4a656592950987f1db31a0871c31705c325 (diff)
downloadcpython-b32a8317d7a9c47bf9e6a863f0cc3112a252c66e.zip
cpython-b32a8317d7a9c47bf9e6a863f0cc3112a252c66e.tar.gz
cpython-b32a8317d7a9c47bf9e6a863f0cc3112a252c66e.tar.bz2
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.
-rw-r--r--Lib/pickle.py91
1 files changed, 47 insertions, 44 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 2805dfb..58c4ba0 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -270,61 +270,64 @@ class Pickler:
try:
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
+ 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 = 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()
+ reduce = object.__reduce__
+ except AttributeError:
+ raise PicklingError, \
+ "can't pickle %s object: %s" % (`t.__name__`,
+ `object`)
else:
- tup = reduce(object)
-
- if type(tup) is StringType:
- self.save_global(object, tup)
- return
+ tup = reduce()
+ else:
+ tup = reduce(object)
- if type(tup) is not TupleType:
- raise PicklingError, "Value returned by %s must be a " \
- "tuple" % reduce
+ if type(tup) is StringType:
+ self.save_global(object, tup)
+ return
- l = len(tup)
+ if type(tup) is not TupleType:
+ raise PicklingError, "Value returned by %s must be a " \
+ "tuple" % reduce
- if (l != 2) and (l != 3):
- raise PicklingError, "tuple returned by %s must contain " \
- "only two or three elements" % reduce
+ l = len(tup)
- callable = tup[0]
- arg_tup = tup[1]
+ if (l != 2) and (l != 3):
+ raise PicklingError, "tuple returned by %s must contain " \
+ "only two or three elements" % reduce
- if l > 2:
- state = tup[2]
- else:
- state = None
+ callable = tup[0]
+ arg_tup = tup[1]
- 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
+ if l > 2:
+ state = tup[2]
+ else:
+ state = None
- self.save_reduce(callable, arg_tup, state)
- memo_len = len(memo)
- self.write(self.put(memo_len))
- memo[d] = (memo_len, object)
- return
+ 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
- f(self, object)
+ 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):
return None