Kaydet (Commit) b32a8317 authored tarafından Tim Peters's avatar Tim Peters

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.
üst c9d7c4a6
...@@ -270,61 +270,64 @@ class Pickler: ...@@ -270,61 +270,64 @@ class Pickler:
try: try:
f = self.dispatch[t] f = self.dispatch[t]
except KeyError: except KeyError:
try: pass
issc = issubclass(t, TypeType) else:
except TypeError: # t is not a class f(self, object)
issc = 0 return
if issc:
self.save_global(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: try:
reduce = dispatch_table[t] reduce = object.__reduce__
except KeyError: except AttributeError:
try: raise PicklingError, \
reduce = object.__reduce__ "can't pickle %s object: %s" % (`t.__name__`,
except AttributeError: `object`)
raise PicklingError, \
"can't pickle %s object: %s" % (`t.__name__`,
`object`)
else:
tup = reduce()
else: else:
tup = reduce(object) tup = reduce()
else:
if type(tup) is StringType: tup = reduce(object)
self.save_global(object, tup)
return
if type(tup) is not TupleType: if type(tup) is StringType:
raise PicklingError, "Value returned by %s must be a " \ self.save_global(object, tup)
"tuple" % reduce 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): l = len(tup)
raise PicklingError, "tuple returned by %s must contain " \
"only two or three elements" % reduce
callable = tup[0] if (l != 2) and (l != 3):
arg_tup = tup[1] raise PicklingError, "tuple returned by %s must contain " \
"only two or three elements" % reduce
if l > 2: callable = tup[0]
state = tup[2] arg_tup = tup[1]
else:
state = None
if type(arg_tup) is not TupleType and arg_tup is not None: if l > 2:
raise PicklingError, "Second element of tuple returned " \ state = tup[2]
"by %s must be a tuple" % reduce else:
state = None
self.save_reduce(callable, arg_tup, state) if type(arg_tup) is not TupleType and arg_tup is not None:
memo_len = len(memo) raise PicklingError, "Second element of tuple returned " \
self.write(self.put(memo_len)) "by %s must be a tuple" % reduce
memo[d] = (memo_len, object)
return
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): def persistent_id(self, object):
return None return None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment