[Python-checkins] python/nondist/sandbox/pickletools pickletools.py,1.8,1.9
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Sat, 25 Jan 2003 20:27:06 -0800
Update of /cvsroot/python/python/nondist/sandbox/pickletools
In directory sc8-pr-cvs1:/tmp/cvs-serv31194
Modified Files:
pickletools.py
Log Message:
TRUE and FALSE aren't really opcodes -- got rid of them, and documented
the trick in the INT opcode.
Index: pickletools.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/pickletools/pickletools.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** pickletools.py 26 Jan 2003 04:03:27 -0000 1.8
--- pickletools.py 26 Jan 2003 04:27:03 -0000 1.9
***************
*** 259,263 ****
# It's not necessarily true that the result fits in a Python short int:
! # the pickle may have been written on a 64-bit box.
try:
return int(s)
--- 259,269 ----
# It's not necessarily true that the result fits in a Python short int:
! # the pickle may have been written on a 64-bit box. There's also a hack
! # for True and False here.
! if s == "00":
! return False
! elif s == "01":
! return True
!
try:
return int(s)
***************
*** 412,419 ****
doc="A long (as opposed to short) Python integer object.")
! pyinteger = StackObject(
! name='integer',
! obtype=(int, long),
! doc="A Python integer object, short or long.")
pyfloat = StackObject(
--- 418,426 ----
doc="A long (as opposed to short) Python integer object.")
! pyinteger_or_bool = StackObject(
! name='int_or_bool',
! obtype=(int, long, bool),
! doc="A Python integer object (short or long), or "
! "a Python bool.")
pyfloat = StackObject(
***************
*** 531,535 ****
args=[decimalnl_short],
stack_before=[],
! stack_after=[pyinteger],
proto=0,
doc="""Newline-terminated decimal integer literal.
--- 538,542 ----
args=[decimalnl_short],
stack_before=[],
! stack_after=[pyinteger_or_bool],
proto=0,
doc="""Newline-terminated decimal integer literal.
***************
*** 540,543 ****
--- 547,558 ----
and LONG then is that INT skips a trailing 'L', and produces a short
int whenever possible.
+
+ Another difference is due to that, when bool was introduced as a
+ distinct type in 2.3, builtin int singletons True and False were
+ also added to 2.2.2. For compatibility in both directions, True gets
+ pickled as INT + "I01\\n", and False as INT + "I00\\n". Leading zeroes
+ are never produced for a genuine integer. The 2.3 (and later)
+ unpicklers special-case these and return bool instead; earlier
+ unpicklers ignore the leading "0" and return the int.
"""),
***************
*** 639,643 ****
stack_after=[pynone],
proto=0,
! doc="Push None on the stack"),
# Stack manipulation.
--- 654,658 ----
stack_after=[pynone],
proto=0,
! doc="Push None on the stack."),
# Stack manipulation.
***************
*** 997,1022 ****
I(name='SETITEMS',
code='u',
- args=[],
- stack_before=[],
- stack_after=[],
- proto=0,
- doc="""XXX One-line description goes here.
-
- XXX Doc body goes here.
- """),
-
- I(name='TRUE',
- code='I01\n',
- args=[],
- stack_before=[],
- stack_after=[],
- proto=0,
- doc="""XXX One-line description goes here.
-
- XXX Doc body goes here.
- """),
-
- I(name='FALSE',
- code='I00\n',
args=[],
stack_before=[],
--- 1012,1015 ----