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.
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 @@
'''
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 @@
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 @@
""")
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 @@
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 @@
del d
def assure_pickle_consistency(verbose=False):
- import pickle, re
copy = code2op.copy()
for name in pickle.__all__:
@@ -1803,7 +1806,7 @@
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 @@
_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