[Python-checkins] python/dist/src/Lib pickle.py,1.135,1.136

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
2003年1月31日 11:42:35 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv2775
Modified Files:
	pickle.py 
Log Message:
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.
Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.135
retrieving revision 1.136
diff -C2 -d -r1.135 -r1.136
*** pickle.py	31 Jan 2003 18:53:21 -0000	1.135
--- pickle.py	31 Jan 2003 19:42:31 -0000	1.136
***************
*** 168,183 ****
 class Pickler:
 
! def __init__(self, file, proto=1):
 """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 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.
 
! XXX Protocol 2 is not yet implemented.
 
 The file parameter must have a write() method that accepts a single
--- 168,185 ----
 class Pickler:
 
! 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 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.
 
! Specifying a negative protocol version selects the highest
! protocol version supported.
 
 The file parameter must have a write() method that accepts a single
***************
*** 186,190 ****
 
 """
! if proto not in (0, 1, 2):
 raise ValueError, "pickle protocol must be 0, 1 or 2"
 self.write = file.write
--- 188,194 ----
 
 """
! 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
***************
*** 1456,1463 ****
 from StringIO import StringIO
 
! def dump(obj, file, proto=1):
 Pickler(file, proto).dump(obj)
 
! def dumps(obj, proto=1):
 file = StringIO()
 Pickler(file, proto).dump(obj)
--- 1460,1467 ----
 from StringIO import StringIO
 
! def dump(obj, file, proto=0):
 Pickler(file, proto).dump(obj)
 
! def dumps(obj, proto=0):
 file = StringIO()
 Pickler(file, proto).dump(obj)

AltStyle によって変換されたページ (->オリジナル) /