mirror of
https://github.com/python/cpython.git
synced 2026-01-06 23:42:34 +00:00
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:
parent
a19f80c6df
commit
98297ee781
148 changed files with 2533 additions and 3517 deletions
|
|
@ -33,13 +33,13 @@ def __init__(self):
|
|||
# A UnicodeDecodeError object without an end attribute
|
||||
class NoEndUnicodeDecodeError(UnicodeDecodeError):
|
||||
def __init__(self):
|
||||
UnicodeDecodeError.__init__(self, "ascii", b"", 0, 1, "bad")
|
||||
UnicodeDecodeError.__init__(self, "ascii", buffer(b""), 0, 1, "bad")
|
||||
del self.end
|
||||
|
||||
# A UnicodeDecodeError object with a bad object attribute
|
||||
class BadObjectUnicodeDecodeError(UnicodeDecodeError):
|
||||
def __init__(self):
|
||||
UnicodeDecodeError.__init__(self, "ascii", b"", 0, 1, "bad")
|
||||
UnicodeDecodeError.__init__(self, "ascii", buffer(b""), 0, 1, "bad")
|
||||
self.object = []
|
||||
|
||||
# A UnicodeTranslateError object without a start attribute
|
||||
|
|
@ -181,7 +181,7 @@ def test_charmapencode(self):
|
|||
# mapped through the encoding again. This means, that
|
||||
# to be able to use e.g. the "replace" handler, the
|
||||
# charmap has to have a mapping for "?".
|
||||
charmap = dict((ord(c), str8(2*c.upper(), 'ascii')) for c in "abcdefgh")
|
||||
charmap = dict((ord(c), bytes(2*c.upper(), 'ascii')) for c in "abcdefgh")
|
||||
sin = "abc"
|
||||
sout = b"AABBCC"
|
||||
self.assertEquals(codecs.charmap_encode(sin, "strict", charmap)[0], sout)
|
||||
|
|
@ -189,7 +189,7 @@ def test_charmapencode(self):
|
|||
sin = "abcA"
|
||||
self.assertRaises(UnicodeError, codecs.charmap_encode, sin, "strict", charmap)
|
||||
|
||||
charmap[ord("?")] = str8(b"XYZ")
|
||||
charmap[ord("?")] = b"XYZ"
|
||||
sin = "abcDEF"
|
||||
sout = b"AABBCCXYZXYZXYZ"
|
||||
self.assertEquals(codecs.charmap_encode(sin, "replace", charmap)[0], sout)
|
||||
|
|
@ -309,7 +309,7 @@ def check_exceptionobjectargs(self, exctype, args, msg):
|
|||
# check with one argument too much
|
||||
self.assertRaises(TypeError, exctype, *(args + ["too much"]))
|
||||
# check with one argument of the wrong type
|
||||
wrongargs = [ "spam", str8(b"eggs"), b"spam", 42, 1.0, None ]
|
||||
wrongargs = [ "spam", b"eggs", b"spam", 42, 1.0, None ]
|
||||
for i in range(len(args)):
|
||||
for wrongarg in wrongargs:
|
||||
if type(wrongarg) is type(args[i]):
|
||||
|
|
@ -363,12 +363,12 @@ def test_unicodeencodeerror(self):
|
|||
def test_unicodedecodeerror(self):
|
||||
self.check_exceptionobjectargs(
|
||||
UnicodeDecodeError,
|
||||
["ascii", b"g\xfcrk", 1, 2, "ouch"],
|
||||
["ascii", buffer(b"g\xfcrk"), 1, 2, "ouch"],
|
||||
"'ascii' codec can't decode byte 0xfc in position 1: ouch"
|
||||
)
|
||||
self.check_exceptionobjectargs(
|
||||
UnicodeDecodeError,
|
||||
["ascii", b"g\xfcrk", 1, 3, "ouch"],
|
||||
["ascii", buffer(b"g\xfcrk"), 1, 3, "ouch"],
|
||||
"'ascii' codec can't decode bytes in position 1-2: ouch"
|
||||
)
|
||||
|
||||
|
|
@ -442,7 +442,7 @@ def test_badandgoodignoreexceptions(self):
|
|||
)
|
||||
self.assertEquals(
|
||||
codecs.ignore_errors(
|
||||
UnicodeDecodeError("ascii", b"\xff", 0, 1, "ouch")),
|
||||
UnicodeDecodeError("ascii", buffer(b"\xff"), 0, 1, "ouch")),
|
||||
("", 1)
|
||||
)
|
||||
self.assertEquals(
|
||||
|
|
@ -482,7 +482,7 @@ def test_badandgoodreplaceexceptions(self):
|
|||
)
|
||||
self.assertEquals(
|
||||
codecs.replace_errors(
|
||||
UnicodeDecodeError("ascii", b"\xff", 0, 1, "ouch")),
|
||||
UnicodeDecodeError("ascii", buffer(b"\xff"), 0, 1, "ouch")),
|
||||
("\ufffd", 1)
|
||||
)
|
||||
self.assertEquals(
|
||||
|
|
@ -508,7 +508,7 @@ def test_badandgoodxmlcharrefreplaceexceptions(self):
|
|||
self.assertRaises(
|
||||
TypeError,
|
||||
codecs.xmlcharrefreplace_errors,
|
||||
UnicodeDecodeError("ascii", b"\xff", 0, 1, "ouch")
|
||||
UnicodeDecodeError("ascii", buffer(b"\xff"), 0, 1, "ouch")
|
||||
)
|
||||
self.assertRaises(
|
||||
TypeError,
|
||||
|
|
@ -542,7 +542,7 @@ def test_badandgoodbackslashreplaceexceptions(self):
|
|||
self.assertRaises(
|
||||
TypeError,
|
||||
codecs.backslashreplace_errors,
|
||||
UnicodeDecodeError("ascii", b"\xff", 0, 1, "ouch")
|
||||
UnicodeDecodeError("ascii", buffer(b"\xff"), 0, 1, "ouch")
|
||||
)
|
||||
self.assertRaises(
|
||||
TypeError,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue