[Python-checkins] python/dist/src/Lib pickle.py,1.78,1.79 pickletools.py,1.5,1.6

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Mon, 27 Jan 2003 14:48:00 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv25095

Modified Files:
	pickle.py pickletools.py 
Log Message:
Begin the change from 'binary vs. text mode' to 'protocol 0, 1, 2'.
The protocol now defaults to 1.  Protocol 2 is still unimplemented.


Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.78
retrieving revision 1.79
diff -C2 -d -r1.78 -r1.79
*** pickle.py	27 Jan 2003 21:44:24 -0000	1.78
--- pickle.py	27 Jan 2003 22:47:45 -0000	1.79
***************
*** 37,42 ****
             "Unpickler", "dump", "dumps", "load", "loads"]
  
! format_version = "1.3"                     # File format version we write
! compatible_formats = ["1.0", "1.1", "1.2"] # Old format versions we can read
  
  mdumps = marshal.dumps
--- 37,48 ----
             "Unpickler", "dump", "dumps", "load", "loads"]
  
! # These are purely informational; no code usues these
! format_version = "2.0"                  # File format version we write
! compatible_formats = ["1.0",            # Original protocol 0
!                       "1.1",            # Protocol 0 with class supprt added
!                       "1.2",            # Original protocol 1
!                       "1.3",            # Protocol 1 with BINFLOAT added
!                       "2.0",            # Protocol 2
!                       ]                 # Old format versions we can read
  
  mdumps = marshal.dumps
***************
*** 152,161 ****
  class Pickler:
  
!     def __init__(self, file, bin = 0):
          """This takes a file-like object for writing a pickle data stream.
  
!         The optional bin parameter if true, tells the pickler to use the more
!         efficient binary pickle format, otherwise the ASCII format is used
!         (this is the default).
  
          The file parameter must have a write() method that accepts a single
--- 158,173 ----
  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
***************
*** 166,170 ****
          self.write = file.write
          self.memo = {}
!         self.bin = bin
  
      def clear_memo(self):
--- 178,183 ----
          self.write = file.write
          self.memo = {}
!         self.proto = proto
!         self.bin = proto >= 1
  
      def clear_memo(self):
***************
*** 1071,1080 ****
      from StringIO import StringIO
  
! def dump(object, file, bin = 0):
!     Pickler(file, bin).dump(object)
  
! def dumps(object, bin = 0):
      file = StringIO()
!     Pickler(file, bin).dump(object)
      return file.getvalue()
  
--- 1084,1093 ----
      from StringIO import StringIO
  
! def dump(object, file, proto=1):
!     Pickler(file, proto).dump(object)
  
! def dumps(object, proto=1):
      file = StringIO()
!     Pickler(file, proto).dump(object)
      return file.getvalue()
  

Index: pickletools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickletools.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** pickletools.py	27 Jan 2003 21:44:25 -0000	1.5
--- pickletools.py	27 Jan 2003 22:47:53 -0000	1.6
***************
*** 1903,1907 ****
  >>> import pickle
  >>> x = [1, 2, (3, 4), {'abc': u"def"}]
! >>> pik = pickle.dumps(x)
  >>> dis(pik)
      0: ( MARK
--- 1903,1907 ----
  >>> import pickle
  >>> x = [1, 2, (3, 4), {'abc': u"def"}]
! >>> pik = pickle.dumps(x, 0)
  >>> dis(pik)
      0: ( MARK
***************
*** 1956,1960 ****
  
  >>> import random
! >>> dis(pickle.dumps(random.random))
      0: c GLOBAL     'random random'
     15: p PUT        0
--- 1956,1960 ----
  
  >>> import random
! >>> dis(pickle.dumps(random.random, 0))
      0: c GLOBAL     'random random'
     15: p PUT        0
***************
*** 1962,1966 ****
  
  >>> x = [pickle.PicklingError()] * 2
! >>> dis(pickle.dumps(x))
      0: ( MARK
      1: l     LIST       (MARK at 0)
--- 1962,1966 ----
  
  >>> x = [pickle.PicklingError()] * 2
! >>> dis(pickle.dumps(x, 0))
      0: ( MARK
      1: l     LIST       (MARK at 0)
***************
*** 2017,2021 ****
  >>> T[0][0] is T
  True
! >>> dis(pickle.dumps(L))
      0: ( MARK
      1: l     LIST       (MARK at 0)
--- 2017,2021 ----
  >>> T[0][0] is T
  True
! >>> dis(pickle.dumps(L, 0))
      0: ( MARK
      1: l     LIST       (MARK at 0)
***************
*** 2044,2048 ****
  pickle would require the disassembler to emulate the stack.
  
! >>> dis(pickle.dumps(T))
      0: ( MARK
      1: (     MARK
--- 2044,2048 ----
  pickle would require the disassembler to emulate the stack.
  
! >>> dis(pickle.dumps(T, 0))
      0: ( MARK
      1: (     MARK