summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-01-28 15:19:53 (GMT)
committerGuido van Rossum <guido@python.org>2003-01-28 15:19:53 (GMT)
commit1be31759929c67a3f0b8d11ac8a48ab881760fa8 (patch)
tree46150719c3e4ce7377af7250bf220f1bdd8f0e99
parent3a41c61dd4f4d9e891df7d3cd5094990f8be4676 (diff)
downloadcpython-1be31759929c67a3f0b8d11ac8a48ab881760fa8.zip
cpython-1be31759929c67a3f0b8d11ac8a48ab881760fa8.tar.gz
cpython-1be31759929c67a3f0b8d11ac8a48ab881760fa8.tar.bz2
Add a few comments. Change the way the protocol is checked (it must
be one of 0, 1 or 2). I should note that the previous checkin also added NEWOBJ support to the unpickler -- but there's nothing yet that generates this.
-rw-r--r--Lib/pickle.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index dffdc2c..6045c84 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -158,6 +158,9 @@ del x
_quotes = ["'", '"']
+
+# Pickling machinery
+
class Pickler:
def __init__(self, file, proto=1):
@@ -178,11 +181,11 @@ class Pickler:
object, or any other custom object that meets this interface.
"""
- if not 0 <= proto <= 2:
+ if proto not in (0, 1, 2):
raise ValueError, "pickle protocol must be 0, 1 or 2"
self.write = file.write
self.memo = {}
- self.proto = proto
+ self.proto = int(proto)
self.bin = proto >= 1
def clear_memo(self):
@@ -639,6 +642,7 @@ class Pickler:
dispatch[BuiltinFunctionType] = save_global
dispatch[TypeType] = save_global
+# Pickling helpers
def _keep_alive(x, memo):
"""Keeps a reference to the object x in the memo.
@@ -683,6 +687,8 @@ def whichmodule(func, funcname):
return name
+# Unpickling machinery
+
class Unpickler:
def __init__(self, file):