summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-01-31 19:42:31 (GMT)
committerGuido van Rossum <guido@python.org>2003-01-31 19:42:31 (GMT)
commit7eff63abce7b1e464ef45ea163a7f6bd15ee1d4a (patch)
treecc13097231174443459641b633e189cdbe2ecf03
parent25cb7dfb0f0c32b51a813869f4ef3ab25cba5b2a (diff)
downloadcpython-7eff63abce7b1e464ef45ea163a7f6bd15ee1d4a.zip
cpython-7eff63abce7b1e464ef45ea163a7f6bd15ee1d4a.tar.gz
cpython-7eff63abce7b1e464ef45ea163a7f6bd15ee1d4a.tar.bz2
Change the default protocol back to 0.
Add a feature suggested by Tim: a negative protocol value means to use the largest protocol value supported.
-rw-r--r--Lib/pickle.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index da7bdb6..45bc38c 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -167,25 +167,29 @@ del x
class Pickler:
- def __init__(self, file, proto=1):
+ def __init__(self, file, proto=0):
"""This takes a file-like object for writing a pickle data stream.
The optional proto argument tells the pickler to use the given
protocol; supported protocols are 0, 1, 2. The default
- protocol is 1 (in previous Python versions the default was 0).
+ protocol is 0, to be backwards compatible. (Protocol 0 is the
+ only protocol that can be written to a file opened in text
+ mode and read back successfully.)
Protocol 1 is more efficient than protocol 0; protocol 2 is
- more efficient than protocol 1. Protocol 2 is not the default
- because it is not supported by older Python versions.
+ more efficient than protocol 1.
- XXX Protocol 2 is not yet implemented.
+ Specifying a negative protocol version selects the highest
+ protocol version supported.
The file parameter must have a write() method that accepts a single
string argument. It can thus be an open file object, a StringIO
object, or any other custom object that meets this interface.
"""
- if proto not in (0, 1, 2):
+ if proto < 0:
+ proto = 2
+ elif proto not in (0, 1, 2):
raise ValueError, "pickle protocol must be 0, 1 or 2"
self.write = file.write
self.memo = {}
@@ -1455,10 +1459,10 @@ try:
except ImportError:
from StringIO import StringIO
-def dump(obj, file, proto=1):
+def dump(obj, file, proto=0):
Pickler(file, proto).dump(obj)
-def dumps(obj, proto=1):
+def dumps(obj, proto=0):
file = StringIO()
Pickler(file, proto).dump(obj)
return file.getvalue()