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.
This commit is contained in:
Guido van Rossum 2007-11-06 21:34:58 +00:00
parent a19f80c6df
commit 98297ee781
148 changed files with 2533 additions and 3517 deletions

View file

@ -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