Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r51960:124b3b5cc7ac
Date: 2012-01-28 18:41 +0100
http://bitbucket.org/pypy/pypy/changeset/124b3b5cc7ac/

Log:    Fix syntax errors in test_codecs

diff --git a/pypy/module/_codecs/test/test_codecs.py 
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -12,7 +12,7 @@
         raises(TypeError, _codecs.register, 1)
 
     def test_bigU_codecs(self):
-        u = u'\U00010001\U00020002\U00030003\U00040004\U00050005'
+        u = '\U00010001\U00020002\U00030003\U00040004\U00050005'
         for encoding in ('utf-8', 'utf-16', 'utf-16-le', 'utf-16-be',
                          'utf-32', 'utf-32-le', 'utf-32-be',
                          'raw_unicode_escape',
@@ -20,20 +20,20 @@
             assert str(u.encode(encoding),encoding) == u
 
     def test_ucs4(self):
-        x = u'\U00100000'
+        x = '\U00100000'
         y = x.encode("raw-unicode-escape").decode("raw-unicode-escape")
         assert x == y 
 
     def test_named_unicode(self):
-        assert str(b'\\N{SPACE}','unicode-escape') == u" "
+        assert str(b'\\N{SPACE}','unicode-escape') == " "
         raises( UnicodeDecodeError, str,b'\\N{SPACE','unicode-escape')
         raises( UnicodeDecodeError, str,b'\\NSPACE}','unicode-escape')
         raises( UnicodeDecodeError, str,b'\\NSPACE','unicode-escape')
         raises( UnicodeDecodeError, str,b'\\N','unicode-escape')
-        assert  str(b'\\N{SPACE}\\N{SPACE}','unicode-escape') == u"  " 
-        assert  str(b'\\N{SPACE}a\\N{SPACE}','unicode-escape') == u" a " 
-        assert b"\\N{foo}xx".decode("unicode-escape", "ignore") == u"xx"
-        assert 1 <= len(u"\N{CJK UNIFIED IDEOGRAPH-20000}") <= 2
+        assert  str(b'\\N{SPACE}\\N{SPACE}','unicode-escape') == "  " 
+        assert  str(b'\\N{SPACE}a\\N{SPACE}','unicode-escape') == " a " 
+        assert b"\\N{foo}xx".decode("unicode-escape", "ignore") == "xx"
+        assert 1 <= len("\N{CJK UNIFIED IDEOGRAPH-20000}") <= 2
 
     def test_literals(self):
         raises(SyntaxError, eval, 'u\'\\Uffffffff\'')
@@ -65,40 +65,40 @@
     def test_unicodetranslateerror(self):
         import sys
         assert str(UnicodeTranslateError(
-            u"g\xfcrk", 1, 2, "ouch"))== "can't translate character u'\\xfc' 
in position 1: ouch"
+            "g\xfcrk", 1, 2, "ouch"))== "can't translate character '\\xfc' in 
position 1: ouch"
         
         assert str(UnicodeTranslateError(
-            u"g\u0100rk", 1, 2, "ouch"))== "can't translate character 
u'\\u0100' in position 1: ouch"
+            "g\u0100rk", 1, 2, "ouch"))== "can't translate character '\\u0100' 
in position 1: ouch"
         
         assert str(UnicodeTranslateError(
-            u"g\uffffrk", 1, 2, "ouch"))== "can't translate character 
u'\\uffff' in position 1: ouch"
+            "g\uffffrk", 1, 2, "ouch"))== "can't translate character '\\uffff' 
in position 1: ouch"
         
         if sys.maxunicode > 0xffff and len(chr(0x10000)) == 1:
             assert str(UnicodeTranslateError(
-                u"g\U00010000rk", 1, 2, "ouch"))== "can't translate character 
u'\\U00010000' in position 1: ouch"
+                "g\U00010000rk", 1, 2, "ouch"))== "can't translate character 
'\\U00010000' in position 1: ouch"
             
         assert str(UnicodeTranslateError(
-            u"g\xfcrk", 1, 3, "ouch"))=="can't translate characters in 
position 1-2: ouch"
+            "g\xfcrk", 1, 3, "ouch"))=="can't translate characters in position 
1-2: ouch"
 
     def test_unicodeencodeerror(self):
         import sys
         assert str(UnicodeEncodeError(
-            "ascii", u"g\xfcrk", 1, 2, "ouch"))=="'ascii' codec can't encode 
character u'\\xfc' in position 1: ouch"
+            "ascii", "g\xfcrk", 1, 2, "ouch"))=="'ascii' codec can't encode 
character '\\xfc' in position 1: ouch"
             
         assert str(UnicodeEncodeError(
-            "ascii", u"g\xfcrk", 1, 4, "ouch"))== "'ascii' codec can't encode 
characters in position 1-3: ouch"
+            "ascii", "g\xfcrk", 1, 4, "ouch"))== "'ascii' codec can't encode 
characters in position 1-3: ouch"
             
         assert str(UnicodeEncodeError(
-            "ascii", u"\xfcx", 0, 1, "ouch"))=="'ascii' codec can't encode 
character u'\\xfc' in position 0: ouch"
+            "ascii", "\xfcx", 0, 1, "ouch"))=="'ascii' codec can't encode 
character '\\xfc' in position 0: ouch"
 
         assert str(UnicodeEncodeError(
-            "ascii", u"\u0100x", 0, 1, "ouch"))=="'ascii' codec can't encode 
character u'\\u0100' in position 0: ouch"
+            "ascii", "\u0100x", 0, 1, "ouch"))=="'ascii' codec can't encode 
character '\\u0100' in position 0: ouch"
        
         assert str(UnicodeEncodeError(
-            "ascii", u"\uffffx", 0, 1, "ouch"))=="'ascii' codec can't encode 
character u'\\uffff' in position 0: ouch"
+            "ascii", "\uffffx", 0, 1, "ouch"))=="'ascii' codec can't encode 
character '\\uffff' in position 0: ouch"
         if sys.maxunicode > 0xffff and len(chr(0x10000)) == 1:
             assert str(UnicodeEncodeError(
-                "ascii", u"\U00010000x", 0, 1, "ouch")) =="'ascii' codec can't 
encode character u'\\U00010000' in position 0: ouch"
+                "ascii", "\U00010000x", 0, 1, "ouch")) =="'ascii' codec can't 
encode character '\\U00010000' in position 0: ouch"
     
     def test_indexerror(self):
         import _codecs
@@ -110,17 +110,17 @@
         import sys
         assert charmap_decode(b'', 'strict', 'blablabla') == ('', 0)
         assert charmap_decode(b'xxx') == ('xxx', 3)
-        assert charmap_decode(b'xxx', 'strict', {ord('x'): u'XX'}) == 
('XXXXXX', 3)
+        assert charmap_decode(b'xxx', 'strict', {ord('x'): 'XX'}) == 
('XXXXXX', 3)
         map = tuple([chr(i) for i in range(256)])
-        assert charmap_decode(b'xxx\xff', 'strict', map) == (u'xxx\xff', 4)
+        assert charmap_decode(b'xxx\xff', 'strict', map) == ('xxx\xff', 4)
 
         raises(TypeError, charmap_decode, '\xff', "replace",  {0xff: 0x10001})
 
     def test_unicode_escape(self):
         from _codecs import unicode_escape_encode, unicode_escape_decode
-        assert unicode_escape_encode(u'abc') == 
(u'abc'.encode('unicode_escape'), 3)
+        assert unicode_escape_encode('abc') == 
('abc'.encode('unicode_escape'), 3)
         assert unicode_escape_decode(b'abc') == 
(b'abc'.decode('unicode_escape'), 3)
-        assert unicode_escape_decode(b'\\x61\\x62\\x63') == (u'abc', 12)
+        assert unicode_escape_decode(b'\\x61\\x62\\x63') == ('abc', 12)
 
 class AppTestPartialEvaluation:
 
@@ -132,22 +132,22 @@
         import _codecs
         encoding = 'utf-8'
         check_partial = [
-                u"\x00",
-                u"\x00",
-                u"\x00\xff",
-                u"\x00\xff",
-                u"\x00\xff\u07ff",
-                u"\x00\xff\u07ff",
-                u"\x00\xff\u07ff",
-                u"\x00\xff\u07ff\u0800",
-                u"\x00\xff\u07ff\u0800",
-                u"\x00\xff\u07ff\u0800",
-                u"\x00\xff\u07ff\u0800\uffff",
+                "\x00",
+                "\x00",
+                "\x00\xff",
+                "\x00\xff",
+                "\x00\xff\u07ff",
+                "\x00\xff\u07ff",
+                "\x00\xff\u07ff",
+                "\x00\xff\u07ff\u0800",
+                "\x00\xff\u07ff\u0800",
+                "\x00\xff\u07ff\u0800",
+                "\x00\xff\u07ff\u0800\uffff",
             ]
             
         buffer = b''
-        result = u""
-        for (c, partialresult) in 
zip(u"\x00\xff\u07ff\u0800\uffff".encode(encoding), check_partial):
+        result = ""
+        for (c, partialresult) in 
zip("\x00\xff\u07ff\u0800\uffff".encode(encoding), check_partial):
             buffer += bytes([c])
             res = _codecs.utf_8_decode(buffer,'strict',False)
             if res[1] >0 :
@@ -159,20 +159,20 @@
         import _codecs
         encoding = 'utf-16'
         check_partial = [
-                    u"", # first byte of BOM read
-                    u"", # second byte of BOM read => byteorder known
-                    u"",
-                    u"\x00",
-                    u"\x00",
-                    u"\x00\xff",
-                    u"\x00\xff",
-                    u"\x00\xff\u0100",
-                    u"\x00\xff\u0100",
-                    u"\x00\xff\u0100\uffff",
+                    "", # first byte of BOM read
+                    "", # second byte of BOM read => byteorder known
+                    "",
+                    "\x00",
+                    "\x00",
+                    "\x00\xff",
+                    "\x00\xff",
+                    "\x00\xff\u0100",
+                    "\x00\xff\u0100",
+                    "\x00\xff\u0100\uffff",
                 ]
         buffer = b''
-        result = u""
-        for (c, partialresult) in 
zip(u"\x00\xff\u0100\uffff".encode(encoding), check_partial):
+        result = ""
+        for (c, partialresult) in zip("\x00\xff\u0100\uffff".encode(encoding), 
check_partial):
             buffer += bytes([c])
             res = _codecs.utf_16_decode(buffer,'strict',False)
             if res[1] >0 :
@@ -184,9 +184,9 @@
 
         import codecs, io
         self.encoding = 'utf-8'
-        s1 = u"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\r\n"
-        s2 = u"offending line: ladfj askldfj klasdj fskla dfzaskdj fasklfj 
laskd fjasklfzzzzaa%whereisthis!!!\r\n"
-        s3 = u"next line.\r\n"
+        s1 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\r\n"
+        s2 = "offending line: ladfj askldfj klasdj fskla dfzaskdj fasklfj 
laskd fjasklfzzzzaa%whereisthis!!!\r\n"
+        s3 = "next line.\r\n"
        
         s = (s1+s2+s3).encode(self.encoding)
         stream = io.BytesIO(s)
@@ -194,16 +194,16 @@
         assert reader.readline() == s1
         assert reader.readline() == s2
         assert reader.readline() == s3
-        assert reader.readline() == u""
+        assert reader.readline() == ""
 
     def test_bug1098990_b(self):
         import codecs, io
         self.encoding = 'utf-8'
-        s1 = u"aaaaaaaaaaaaaaaaaaaaaaaa\r\n"
-        s2 = u"bbbbbbbbbbbbbbbbbbbbbbbb\r\n"
-        s3 = u"stillokay:bbbbxx\r\n"
-        s4 = u"broken!!!!badbad\r\n"
-        s5 = u"againokay.\r\n"
+        s1 = "aaaaaaaaaaaaaaaaaaaaaaaa\r\n"
+        s2 = "bbbbbbbbbbbbbbbbbbbbbbbb\r\n"
+        s3 = "stillokay:bbbbxx\r\n"
+        s4 = "broken!!!!badbad\r\n"
+        s5 = "againokay.\r\n"
 
         s = (s1+s2+s3+s4+s5).encode(self.encoding)
         stream = io.BytesIO(s)
@@ -213,13 +213,13 @@
         assert reader.readline() == s3
         assert reader.readline() == s4
         assert reader.readline() == s5
-        assert reader.readline() == u""    
+        assert reader.readline() == ""    
     
     def test_seek_utf16le(self):
         # all codecs should be able to encode these
         import codecs, io
         encoding = 'utf-16-le'
-        s = u"%s\n%s\n" % (10*u"abc123", 10*u"def456")
+        s = "%s\n%s\n" % (10*"abc123", 10*"def456")
         reader = codecs.getreader(encoding)(io.BytesIO(s.encode(encoding)))
         for t in range(5):
             # Test that calling seek resets the internal codec state and 
buffers
@@ -232,15 +232,15 @@
         import sys
         class U(str):
             pass
-        enc = U(u"a").encode("unicode_internal")
+        enc = U("a").encode("unicode_internal")
         if sys.maxunicode == 65535: # UCS2 build
             if sys.byteorder == "big":
                 assert enc == b"\x00a"
             else:
                 assert enc == b"a\x00"
-        elif len(u"\U00010098") == 1:
+        elif len("\U00010098") == 1:
             # UCS4 build on a UCS4 CPython
-            enc2 = u"\U00010098".encode("unicode_internal")
+            enc2 = "\U00010098".encode("unicode_internal")
             if sys.byteorder == "big":
                 assert enc == b"\x00\x00\x00a"
                 assert enc2 == b"\x00\x01\x00\x98"
@@ -268,12 +268,12 @@
             else:
                 bytes = b"a\x00\x00\x00"
                 bytes2 = b"\x98\x00\x01\x00"
-            assert bytes2.decode("unicode_internal") == u"\U00010098"
-        assert bytes.decode("unicode_internal") == u"a"
+            assert bytes2.decode("unicode_internal") == "\U00010098"
+        assert bytes.decode("unicode_internal") == "a"
 
     def test_raw_unicode_escape(self):
-        assert str(b"\u0663", "raw-unicode-escape") == u"\u0663"
-        assert u"\u0663".encode("raw-unicode-escape") == b"\u0663"
+        assert str(b"\u0663", "raw-unicode-escape") == "\u0663"
+        assert "\u0663".encode("raw-unicode-escape") == b"\u0663"
 
     def test_escape_decode(self):
         import _codecs
@@ -281,8 +281,8 @@
         assert _codecs.escape_decode(test)[0] == b'a\n\\b\x00c\td\u2045'
         assert _codecs.escape_decode(b'\\077')[0] == b'?'
         assert _codecs.escape_decode(b'\\100')[0] == b'@'
-        assert _codecs.escape_decode(b'\\253')[0] == bytes([0253])
-        assert _codecs.escape_decode(b'\\312')[0] == bytes([0312])
+        assert _codecs.escape_decode(b'\\253')[0] == bytes([0o253])
+        assert _codecs.escape_decode(b'\\312')[0] == bytes([0o312])
 
     def test_escape_decode_wrap_around(self):
         import _codecs
@@ -301,7 +301,7 @@
         assert _codecs.escape_encode(b"'")[0] == b"\\'"
 
     def test_decode_utf8_different_case(self):
-        constant = u"a"
+        constant = "a"
         assert constant.encode("utf-8") == constant.encode("UTF-8")
 
     def test_codec_wrong_result(self):
@@ -315,13 +315,13 @@
             return None
         _codecs.register(search_function)
         raises(TypeError, b"hello".decode, "test.mytestenc")
-        raises(TypeError, u"hello".encode, "test.mytestenc")
+        raises(TypeError, "hello".encode, "test.mytestenc")
 
     def test_cpytest_decode(self):
         import codecs
-        assert codecs.decode(b'\xe4\xf6\xfc', 'latin-1') == u'\xe4\xf6\xfc'
+        assert codecs.decode(b'\xe4\xf6\xfc', 'latin-1') == '\xe4\xf6\xfc'
         raises(TypeError, codecs.decode)
-        assert codecs.decode(b'abc') == u'abc'
+        assert codecs.decode(b'abc') == 'abc'
         raises(UnicodeDecodeError, codecs.decode, b'\xff', 'ascii')
 
     def test_bad_errorhandler_return(self):
@@ -382,7 +382,7 @@
     def test_utf8sig(self):
         import codecs
         d = codecs.getincrementaldecoder("utf-8-sig")()
-        s = u"spam"
+        s = "spam"
         assert d.decode(s.encode("utf-8-sig")) == s
 
     def test_escape_decode_escaped_newline(self):
@@ -393,20 +393,20 @@
 
     def test_charmap_decode_1(self):
         import codecs
-        assert codecs.charmap_encode(u'xxx') == (b'xxx', 3)
-        assert codecs.charmap_encode(u'xxx', 'strict', {ord('x'): b'XX'}) == 
(b'XXXXXX', 3)
+        assert codecs.charmap_encode('xxx') == (b'xxx', 3)
+        assert codecs.charmap_encode('xxx', 'strict', {ord('x'): b'XX'}) == 
(b'XXXXXX', 3)
 
-        res = codecs.charmap_decode(b"\x00\x01\x02", "replace", u"ab")
-        assert res == (u"ab\ufffd", 3)
-        res = codecs.charmap_decode(b"\x00\x01\x02", "replace", u"ab\ufffe")
-        assert res == (u'ab\ufffd', 3)
+        res = codecs.charmap_decode(b"\x00\x01\x02", "replace", "ab")
+        assert res == ("ab\ufffd", 3)
+        res = codecs.charmap_decode(b"\x00\x01\x02", "replace", "ab\ufffe")
+        assert res == ('ab\ufffd', 3)
 
     def test_decode_errors(self):
         import sys
         if sys.maxunicode > 0xffff:
             try:
                 b"\x00\x00\x00\x00\x00\x11\x11\x00".decode("unicode_internal")
-            except UnicodeDecodeError, ex:
+            except UnicodeDecodeError as ex:
                 assert "unicode_internal" == ex.encoding
                 assert b"\x00\x00\x00\x00\x00\x11\x11\x00" == ex.object
                 assert ex.start == 4
@@ -417,28 +417,28 @@
     def test_errors(self):
         import codecs
         assert codecs.replace_errors(UnicodeEncodeError(
-            "ascii", u"\u3042", 0, 1, "ouch")) == (u"?", 1)
+            "ascii", "\u3042", 0, 1, "ouch")) == ("?", 1)
         assert codecs.replace_errors(UnicodeDecodeError(
-            "ascii", b"\xff", 0, 1, "ouch")) == (u"\ufffd", 1)
+            "ascii", b"\xff", 0, 1, "ouch")) == ("\ufffd", 1)
         assert codecs.replace_errors(UnicodeTranslateError(
-            u"\u3042", 0, 1, "ouch")) == (u"\ufffd", 1)
+            "\u3042", 0, 1, "ouch")) == ("\ufffd", 1)
 
         assert codecs.replace_errors(UnicodeEncodeError(
-            "ascii", u"\u3042\u3042", 0, 2, "ouch")) == (u"??", 2)
+            "ascii", "\u3042\u3042", 0, 2, "ouch")) == ("??", 2)
         assert codecs.replace_errors(UnicodeDecodeError(
-            "ascii", b"\xff\xff", 0, 2, "ouch")) == (u"\ufffd", 2)
+            "ascii", b"\xff\xff", 0, 2, "ouch")) == ("\ufffd", 2)
         assert codecs.replace_errors(UnicodeTranslateError(
-            u"\u3042\u3042", 0, 2, "ouch")) == (u"\ufffd\ufffd", 2)
+            "\u3042\u3042", 0, 2, "ouch")) == ("\ufffd\ufffd", 2)
 
         class BadStartUnicodeEncodeError(UnicodeEncodeError):
             def __init__(self):
-                UnicodeEncodeError.__init__(self, "ascii", u"", 0, 1, "bad")
+                UnicodeEncodeError.__init__(self, "ascii", "", 0, 1, "bad")
                 self.start = []
 
         # A UnicodeEncodeError object with a bad object attribute
         class BadObjectUnicodeEncodeError(UnicodeEncodeError):
             def __init__(self):
-                UnicodeEncodeError.__init__(self, "ascii", u"", 0, 1, "bad")
+                UnicodeEncodeError.__init__(self, "ascii", "", 0, 1, "bad")
                 self.object = []
 
         # A UnicodeDecodeError object without an end attribute
@@ -456,19 +456,19 @@
         # A UnicodeTranslateError object without a start attribute
         class NoStartUnicodeTranslateError(UnicodeTranslateError):
             def __init__(self):
-                UnicodeTranslateError.__init__(self, u"", 0, 1, "bad")
+                UnicodeTranslateError.__init__(self, "", 0, 1, "bad")
                 del self.start
 
         # A UnicodeTranslateError object without an end attribute
         class NoEndUnicodeTranslateError(UnicodeTranslateError):
             def __init__(self):
-                UnicodeTranslateError.__init__(self,  u"", 0, 1, "bad")
+                UnicodeTranslateError.__init__(self,  "", 0, 1, "bad")
                 del self.end
 
         # A UnicodeTranslateError object without an object attribute
         class NoObjectUnicodeTranslateError(UnicodeTranslateError):
             def __init__(self):
-                UnicodeTranslateError.__init__(self, u"", 0, 1, "bad")
+                UnicodeTranslateError.__init__(self, "", 0, 1, "bad")
                 del self.object
 
         import codecs
@@ -479,14 +479,14 @@
         raises(TypeError, codecs.replace_errors, BadObjectUnicodeEncodeError())
         raises(TypeError, codecs.replace_errors, BadObjectUnicodeDecodeError()
         )
-        # With the correct exception, "replace" returns an "?" or u"\ufffd" 
replacement
+        # With the correct exception, "replace" returns an "?" or "\ufffd" 
replacement
 
     def test_decode_ignore(self):
         assert b'\xff'.decode('utf-7', 'ignore') == ''
         assert b'\x00'.decode('unicode-internal', 'ignore') == ''
 
     def test_backslahreplace(self):
-        assert u'a\xac\u1234\u20ac\u8000'.encode('ascii', 'backslashreplace') 
== b'a\\xac\u1234\u20ac\u8000'
+        assert 'a\xac\u1234\u20ac\u8000'.encode('ascii', 'backslashreplace') 
== b'a\\xac\u1234\u20ac\u8000'
 
     def test_surrogateescape(self):
         assert b'a\x80b'.decode('utf-8', 'surrogateescape') == 'a\udc80b'
@@ -494,7 +494,7 @@
 
     def test_badhandler(self):
         import codecs
-        results = ( 42, u"foo", (1,2,3), (u"foo", 1, 3), (u"foo", None), 
(u"foo",), ("foo", 1, 3), ("foo", None), ("foo",) )
+        results = ( 42, "foo", (1,2,3), ("foo", 1, 3), ("foo", None), 
("foo",), ("foo", 1, 3), ("foo", None), ("foo",) )
         encs = ("ascii", "latin-1", "iso-8859-1", "iso-8859-15")
 
         for res in results:
@@ -502,7 +502,7 @@
             for enc in encs:
                 raises(
                     TypeError,
-                    u"\u3042".encode,
+                    "\u3042".encode,
                     enc,
                     "test.badhandler"
                 )
@@ -531,50 +531,50 @@
 
         res = b"\x00\x00\x00\x00\x00".decode("unicode-internal", "replace")
         if sys.maxunicode > 65535:
-            assert res == u"\u0000\ufffd"    # UCS4 build
+            assert res == "\u0000\ufffd"    # UCS4 build
         else:
-            assert res == u"\x00\x00\ufffd"  # UCS2 build
+            assert res == "\x00\x00\ufffd"  # UCS2 build
 
         res = b"\x00\x00\x00\x00\x00".decode("unicode-internal", "ignore")
         if sys.maxunicode > 65535:
-            assert res == u"\u0000"   # UCS4 build
+            assert res == "\u0000"   # UCS4 build
         else:
-            assert res == u"\x00\x00" # UCS2 build
+            assert res == "\x00\x00" # UCS2 build
 
         def handler_unicodeinternal(exc):
             if not isinstance(exc, UnicodeDecodeError):
                 raise TypeError("don't know how to handle %r" % exc)
-            return (u"\x01", 1)
+            return ("\x01", 1)
         codecs.register_error("test.hui", handler_unicodeinternal)
         res = b"\x00\x00\x00\x00\x00".decode("unicode-internal", "test.hui")
         if sys.maxunicode > 65535:
-            assert res == u"\u0000\u0001\u0000"   # UCS4 build
+            assert res == "\u0000\u0001\u0000"   # UCS4 build
         else:
-            assert res == u"\x00\x00\x01\x00\x00" # UCS2 build
+            assert res == "\x00\x00\x01\x00\x00" # UCS2 build
 
     def test_encode_error_bad_handler(self):
         import codecs
         codecs.register_error("test.bad_handler", lambda e: (repl, 1))
-        assert u"xyz".encode("latin-1", "test.bad_handler") == b"xyz"
-        repl = u"\u1234"
-        raises(UnicodeEncodeError, u"\u5678".encode, "latin-1",
+        assert "xyz".encode("latin-1", "test.bad_handler") == b"xyz"
+        repl = "\u1234"
+        raises(UnicodeEncodeError, "\u5678".encode, "latin-1",
                "test.bad_handler")
-        repl = u"\u00E9"
-        s = u"\u5678".encode("latin-1", "test.bad_handler")
+        repl = "\u00E9"
+        s = "\u5678".encode("latin-1", "test.bad_handler")
         assert s == b'\xe9'
 
     def test_charmap_encode(self):
         assert 'xxx'.encode('charmap') == b'xxx'
 
         import codecs
-        raises(TypeError, codecs.charmap_encode, u'\xff', "replace",  {0xff: 
300})
-        raises(UnicodeError, codecs.charmap_encode, u"\xff", "replace", {0xff: 
None})
+        raises(TypeError, codecs.charmap_encode, '\xff', "replace",  {0xff: 
300})
+        raises(UnicodeError, codecs.charmap_encode, "\xff", "replace", {0xff: 
None})
 
     def test_charmap_encode_replace(self):
         charmap = dict([(c, bytes([c, c]).upper()) for c in b"abcdefgh"])
         charmap[ord("?")] = b"XYZ"
         import codecs
-        sin = u"abcDEF"
+        sin = "abcDEF"
         sout = codecs.charmap_encode(sin, "replace", charmap)[0]
         assert sout == b"AABBCCXYZXYZXYZ"
 
@@ -583,13 +583,13 @@
 
     def test_charmap_build(self):
         import codecs
-        assert codecs.charmap_build(u'123456') == {49: 0, 50: 1, 51: 2,
+        assert codecs.charmap_build('123456') == {49: 0, 50: 1, 51: 2,
                                                    52: 3, 53: 4, 54: 5}
 
     def test_utf7_start_end_in_exception(self):
         try:
             b'+IC'.decode('utf-7')
-        except UnicodeDecodeError, exc:
+        except UnicodeDecodeError as exc:
             assert exc.start == 0
             assert exc.end == 3
 
@@ -598,7 +598,7 @@
 
     def test_utf_16_encode_decode(self):
         import codecs, sys
-        x = u'123abc'
+        x = '123abc'
         if sys.byteorder == 'big':
             assert codecs.getencoder('utf-16')(x) == (
                     b'\xfe\xff\x001\x002\x003\x00a\x00b\x00c', 6)
@@ -611,16 +611,16 @@
                     b'\xff\xfe1\x002\x003\x00a\x00b\x00c\x00') == (x, 14)
 
     def test_unicode_escape(self):        
-        assert u'\\'.encode('unicode-escape') == b'\\\\'
-        assert b'\\\\'.decode('unicode-escape') == u'\\'
-        assert u'\ud801'.encode('unicode-escape') == b'\\ud801'
-        assert u'\u0013'.encode('unicode-escape') == b'\\x13'
+        assert '\\'.encode('unicode-escape') == b'\\\\'
+        assert b'\\\\'.decode('unicode-escape') == '\\'
+        assert '\ud801'.encode('unicode-escape') == b'\\ud801'
+        assert '\u0013'.encode('unicode-escape') == b'\\x13'
 
     def test_mbcs(self):
         import sys
         if sys.platform != 'win32':
             return
-        assert u'test'.encode('mbcs') == 'test'
-        assert u'caf\xe9'.encode('mbcs') == 'caf\xe9'
-        assert u'\u040a'.encode('mbcs') == '?' # some cyrillic letter
-        assert 'cafx\e9'.decode('mbcs') == u'cafx\e9'
+        assert 'test'.encode('mbcs') == 'test'
+        assert 'caf\xe9'.encode('mbcs') == 'caf\xe9'
+        assert '\u040a'.encode('mbcs') == '?' # some cyrillic letter
+        assert 'cafx\e9'.decode('mbcs') == 'cafx\e9'
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to