summaryrefslogtreecommitdiffstats
path: root/Lib/copy_reg.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-02-18 22:05:12 (GMT)
committerGuido van Rossum <guido@python.org>2003-02-18 22:05:12 (GMT)
commitc53f009f94a5758530e6f35d8e7ed64c8efcb74b (patch)
treee39099602182ef895a382a640dc49872619d64b7 /Lib/copy_reg.py
parent2b0643a95db568ef9293cc51708d72b121c5d734 (diff)
downloadcpython-c53f009f94a5758530e6f35d8e7ed64c8efcb74b.zip
cpython-c53f009f94a5758530e6f35d8e7ed64c8efcb74b.tar.gz
cpython-c53f009f94a5758530e6f35d8e7ed64c8efcb74b.tar.bz2
Introducing __reduce_ex__, which is called with a protocol number argument
if it exists in preference over __reduce__. Now Tim can go implement this in cPickle.c.
Diffstat (limited to 'Lib/copy_reg.py')
-rw-r--r--Lib/copy_reg.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/copy_reg.py b/Lib/copy_reg.py
index 6dc52c2..fa4ce72 100644
--- a/Lib/copy_reg.py
+++ b/Lib/copy_reg.py
@@ -109,6 +109,17 @@ def _better_reduce(obj):
dictitems = obj.iteritems()
return __newobj__, (cls,) + args, state, listitems, dictitems
+# Extended reduce:
+
+def _reduce_ex(obj, proto=0):
+ obj_reduce = getattr(obj, "__reduce__", None)
+ if obj_reduce and obj.__class__.__reduce__ is not object.__reduce__:
+ return obj_reduce()
+ elif proto < 2:
+ return _reduce(obj)
+ else:
+ return _better_reduce(obj)
+
def _slotnames(cls):
"""Return a list of slot names for a given class.