Commit 1be31759 authored by Guido van Rossum's avatar Guido van Rossum

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.
parent 3a41c61d
...@@ -158,6 +158,9 @@ del x ...@@ -158,6 +158,9 @@ del x
_quotes = ["'", '"'] _quotes = ["'", '"']
# Pickling machinery
class Pickler: class Pickler:
def __init__(self, file, proto=1): def __init__(self, file, proto=1):
...@@ -178,11 +181,11 @@ class Pickler: ...@@ -178,11 +181,11 @@ class Pickler:
object, or any other custom object that meets this interface. 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" raise ValueError, "pickle protocol must be 0, 1 or 2"
self.write = file.write self.write = file.write
self.memo = {} self.memo = {}
self.proto = proto self.proto = int(proto)
self.bin = proto >= 1 self.bin = proto >= 1
def clear_memo(self): def clear_memo(self):
...@@ -639,6 +642,7 @@ class Pickler: ...@@ -639,6 +642,7 @@ class Pickler:
dispatch[BuiltinFunctionType] = save_global dispatch[BuiltinFunctionType] = save_global
dispatch[TypeType] = save_global dispatch[TypeType] = save_global
# Pickling helpers
def _keep_alive(x, memo): def _keep_alive(x, memo):
"""Keeps a reference to the object x in the memo. """Keeps a reference to the object x in the memo.
...@@ -683,6 +687,8 @@ def whichmodule(func, funcname): ...@@ -683,6 +687,8 @@ def whichmodule(func, funcname):
return name return name
# Unpickling machinery
class Unpickler: class Unpickler:
def __init__(self, file): def __init__(self, file):
......
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