_quotes = ["'", '"']
+
+# Pickling machinery
+
class Pickler:
def __init__(self, file, proto=1):
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):
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.
return name
+# Unpickling machinery
+
class Unpickler:
def __init__(self, file):