[Python-checkins] CVS: python/dist/src/Lib pickle.py,1.59,1.60
Guido van Rossum
gvanrossum@users.sourceforge.net
Fri, 05 Apr 2002 11:30:10 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv8192/Lib
Modified Files:
pickle.py
Log Message:
Implement an idea by Paul Rubin:
Change pickling format for bools to use a backwards compatible
encoding. This means you can pickle True or False on Python 2.3
and Python 2.2 or before will read it back as 1 or 0. The code
used for pickling bools before would create pickles that could
not be read in previous Python versions.
Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.59
retrieving revision 1.60
diff -C2 -d -r1.59 -r1.60
*** pickle.py 3 Apr 2002 22:41:50 -0000 1.59
--- pickle.py 5 Apr 2002 19:30:07 -0000 1.60
***************
*** 102,107 ****
SETITEMS = 'u'
BINFLOAT = 'G'
! TRUE = 'Z'
! FALSE = 'z'
--- 102,107 ----
SETITEMS = 'u'
BINFLOAT = 'G'
! TRUE = 'I01\n'
! FALSE = 'I00\n'
***************
*** 640,657 ****
dispatch[NONE] = load_none
- def load_false(self):
- self.append(False)
- dispatch[FALSE] = load_false
-
- def load_true(self):
- self.append(True)
- dispatch[TRUE] = load_true
-
def load_int(self):
data = self.readline()
! try:
! self.append(int(data))
! except ValueError:
! self.append(long(data))
dispatch[INT] = load_int
--- 640,655 ----
dispatch[NONE] = load_none
def load_int(self):
data = self.readline()
! if data == FALSE[1:]:
! val = False
! elif data == TRUE[1:]:
! val = True
! else:
! try:
! val = int(data)
! except ValueError:
! val = long(data)
! self.append(val)
dispatch[INT] = load_int