summaryrefslogtreecommitdiff
path: root/Lib/pickletools.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-01-31 16:43:39 +0000
committerTim Peters <tim.peters@gmail.com>2003-01-31 16:43:39 +0000
commit81b82843eb6fd7cb49cd4ba8d25eae3ac75754b2 (patch)
treee2730ae6664f19c93ee0dff35eae05888719eb27 /Lib/pickletools.py
parent86f193964af1b1b15629c75da192ae3c793bbd62 (diff)
downloadcpython-81b82843eb6fd7cb49cd4ba8d25eae3ac75754b2.tar.gz
It's Official: for LONG1/LONG4, a "byte count" of 0 is taken as a
shortcut meaning 0L. This allows LONG1 to encode 0L in two bytes total.
Diffstat (limited to 'Lib/pickletools.py')
-rw-r--r--Lib/pickletools.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/pickletools.py b/Lib/pickletools.py
index 74ba8d964f..f9ef8df95e 100644
--- a/Lib/pickletools.py
+++ b/Lib/pickletools.py
@@ -620,6 +620,8 @@ from pickle import decode_long
def read_long1(f):
r"""
>>> import StringIO
+ >>> read_long1(StringIO.StringIO("\x00"))
+ 0L
>>> read_long1(StringIO.StringIO("\x02\xff\x00"))
255L
>>> read_long1(StringIO.StringIO("\x02\xff\x7f"))
@@ -628,7 +630,6 @@ def read_long1(f):
-256L
>>> read_long1(StringIO.StringIO("\x02\x00\x80"))
-32768L
- >>>
"""
n = read_uint1(f)
@@ -645,6 +646,7 @@ long1 = ArgumentDescriptor(
This first reads one byte as an unsigned size, then reads that
many bytes and interprets them as a little-endian 2's-complement long.
+ If the size is 0, that's taken as a shortcut for the long 0L.
""")
def read_long4(f):
@@ -658,7 +660,8 @@ def read_long4(f):
-256L
>>> read_long4(StringIO.StringIO("\x02\x00\x00\x00\x00\x80"))
-32768L
- >>>
+ >>> read_long1(StringIO.StringIO("\x00\x00\x00\x00"))
+ 0L
"""
n = read_int4(f)
@@ -677,7 +680,9 @@ long4 = ArgumentDescriptor(
This first reads four bytes as a signed size (but requires the
size to be >= 0), then reads that many bytes and interprets them
- as a little-endian 2's-complement long.
+ as a little-endian 2's-complement long. If the size is 0, that's taken
+ as a shortcut for the long 0L, although LONG1 should really be used
+ then instead (and in any case where # of bytes < 256).
""")