summaryrefslogtreecommitdiffstats
path: root/Lib/pickletools.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-11-06 21:34:58 (GMT)
committerGuido van Rossum <guido@python.org>2007-11-06 21:34:58 (GMT)
commit98297ee7815939b124156e438b22bd652d67b5db (patch)
treea9d239ebd87c73af2571ab48003984c4e18e27e5 /Lib/pickletools.py
parenta19f80c6df2df5e8a5d0cff37131097835ef971e (diff)
downloadcpython-98297ee7815939b124156e438b22bd652d67b5db.zip
cpython-98297ee7815939b124156e438b22bd652d67b5db.tar.gz
cpython-98297ee7815939b124156e438b22bd652d67b5db.tar.bz2
Merging the py3k-pep3137 branch back into the py3k branch.
No detailed change log; just check out the change log for the py3k-pep3137 branch. The most obvious changes: - str8 renamed to bytes (PyString at the C level); - bytes renamed to buffer (PyBytes at the C level); - PyString and PyUnicode are no longer compatible. I.e. we now have an immutable bytes type and a mutable bytes type. The behavior of PyString was modified quite a bit, to make it more bytes-like. Some changes are still on the to-do list.
Diffstat (limited to 'Lib/pickletools.py')
-rw-r--r--Lib/pickletools.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/Lib/pickletools.py b/Lib/pickletools.py
index b1337c4..af84c1f 100644
--- a/Lib/pickletools.py
+++ b/Lib/pickletools.py
@@ -11,11 +11,15 @@ dis(pickle, out=None, memo=None, indentlevel=4)
'''
import codecs
+import pickle
+import re
__all__ = ['dis',
'genops',
]
+bytes_types = pickle.bytes_types
+
# Other ideas:
#
# - A pickle verifier: read a pickle and check it exhaustively for
@@ -307,7 +311,7 @@ def read_stringnl(f, decode=True, stripquotes=True):
raise ValueError("no string quotes around %r" % data)
if decode:
- data = str(codecs.escape_decode(data)[0])
+ data = codecs.escape_decode(data)[0].decode("ascii")
return data
stringnl = ArgumentDescriptor(
@@ -321,7 +325,7 @@ stringnl = ArgumentDescriptor(
""")
def read_stringnl_noescape(f):
- return read_stringnl(f, decode=False, stripquotes=False)
+ return read_stringnl(f, stripquotes=False)
stringnl_noescape = ArgumentDescriptor(
name='stringnl_noescape',
@@ -744,14 +748,14 @@ pyfloat = StackObject(
doc="A Python float object.")
pystring = StackObject(
- name='str',
- obtype=str,
- doc="A Python string object.")
+ name='bytes',
+ obtype=bytes,
+ doc="A Python bytes object.")
pyunicode = StackObject(
- name='unicode',
+ name='str',
obtype=str,
- doc="A Python Unicode string object.")
+ doc="A Python string object.")
pynone = StackObject(
name="None",
@@ -1735,7 +1739,6 @@ for d in opcodes:
del d
def assure_pickle_consistency(verbose=False):
- import pickle, re
copy = code2op.copy()
for name in pickle.__all__:
@@ -1803,7 +1806,7 @@ def genops(pickle):
to query its current position) pos is None.
"""
- if isinstance(pickle, bytes):
+ if isinstance(pickle, bytes_types):
import io
pickle = io.BytesIO(pickle)
@@ -1978,7 +1981,7 @@ class _Example:
_dis_test = r"""
>>> import pickle
->>> x = [1, 2, (3, 4), {str8(b'abc'): "def"}]
+>>> x = [1, 2, (3, 4), {bytes(b'abc'): "def"}]
>>> pkl = pickle.dumps(x, 0)
>>> dis(pkl)
0: ( MARK