Commit ef87d6ed authored by Guido van Rossum's avatar Guido van Rossum

Rip out all the u"..." literals and calls to unicode().

parent 572dbf8f
...@@ -376,7 +376,7 @@ class HTMLParser(markupbase.ParserBase): ...@@ -376,7 +376,7 @@ class HTMLParser(markupbase.ParserBase):
# which is not part of HTML 4 # which is not part of HTML 4
import htmlentitydefs import htmlentitydefs
if HTMLParser.entitydefs is None: if HTMLParser.entitydefs is None:
entitydefs = HTMLParser.entitydefs = {'apos':u"'"} entitydefs = HTMLParser.entitydefs = {'apos':"'"}
for k, v in htmlentitydefs.name2codepoint.items(): for k, v in htmlentitydefs.name2codepoint.items():
entitydefs[k] = unichr(v) entitydefs[k] = unichr(v)
try: try:
......
...@@ -589,7 +589,7 @@ class StreamReader(Codec): ...@@ -589,7 +589,7 @@ class StreamReader(Codec):
""" """
self.bytebuffer = "" self.bytebuffer = ""
self.charbuffer = u"" self.charbuffer = ""
self.linebuffer = None self.linebuffer = None
def seek(self, offset, whence=0): def seek(self, offset, whence=0):
......
...@@ -740,7 +740,7 @@ class Transformer: ...@@ -740,7 +740,7 @@ class Transformer:
# hack... changes in compile.c:parsestr and # hack... changes in compile.c:parsestr and
# tokenizer.c must be reflected here. # tokenizer.c must be reflected here.
if self.encoding not in ['utf-8', 'iso-8859-1']: if self.encoding not in ['utf-8', 'iso-8859-1']:
lit = unicode(lit, 'utf-8').encode(self.encoding) lit = str(lit, 'utf-8').encode(self.encoding)
return eval("# coding: %s\n%s" % (self.encoding, lit)) return eval("# coding: %s\n%s" % (self.encoding, lit))
else: else:
return eval(lit) return eval(lit)
...@@ -750,7 +750,7 @@ class Transformer: ...@@ -750,7 +750,7 @@ class Transformer:
for node in nodelist[1:]: for node in nodelist[1:]:
k += self.decode_literal(node[1]) k += self.decode_literal(node[1])
if isinstance(k, bytes): if isinstance(k, bytes):
return Bytes(str(k), lineno=nodelist[0][2]) return Bytes(str(k), lineno=nodelist[0][2])
return Const(k, lineno=nodelist[0][2]) return Const(k, lineno=nodelist[0][2])
def atom_ellipsis(self, nodelist): def atom_ellipsis(self, nodelist):
...@@ -825,7 +825,7 @@ class Transformer: ...@@ -825,7 +825,7 @@ class Transformer:
else: else:
annotation = None annotation = None
return SimpleArg(name, annotation, lineno) return SimpleArg(name, annotation, lineno)
def com_arglist(self, nodelist): def com_arglist(self, nodelist):
# varargslist: # varargslist:
# (fpdef ['=' test] ',')* # (fpdef ['=' test] ',')*
......
...@@ -644,7 +644,7 @@ def escape_path(path): ...@@ -644,7 +644,7 @@ def escape_path(path):
# And here, kind of: draft-fielding-uri-rfc2396bis-03 # And here, kind of: draft-fielding-uri-rfc2396bis-03
# (And in draft IRI specification: draft-duerst-iri-05) # (And in draft IRI specification: draft-duerst-iri-05)
# (And here, for new URI schemes: RFC 2718) # (And here, for new URI schemes: RFC 2718)
if isinstance(path, unicode): if isinstance(path, str):
path = path.encode("utf-8") path = path.encode("utf-8")
path = urllib.quote(path, HTTP_PATH_SAFE) path = urllib.quote(path, HTTP_PATH_SAFE)
path = ESCAPED_CHAR_RE.sub(uppercase_escaped_char, path) path = ESCAPED_CHAR_RE.sub(uppercase_escaped_char, path)
......
...@@ -186,7 +186,7 @@ except NameError: ...@@ -186,7 +186,7 @@ except NameError:
pass pass
d[str] = _deepcopy_atomic d[str] = _deepcopy_atomic
try: try:
d[unicode] = _deepcopy_atomic d[str] = _deepcopy_atomic
except NameError: except NameError:
pass pass
try: try:
......
...@@ -59,7 +59,7 @@ def create_string_buffer(init, size=None): ...@@ -59,7 +59,7 @@ def create_string_buffer(init, size=None):
create_string_buffer(anInteger) -> character array create_string_buffer(anInteger) -> character array
create_string_buffer(aString, anInteger) -> character array create_string_buffer(aString, anInteger) -> character array
""" """
if isinstance(init, (str, unicode)): if isinstance(init, (str, str)):
if size is None: if size is None:
size = len(init)+1 size = len(init)+1
buftype = c_char * size buftype = c_char * size
...@@ -281,7 +281,7 @@ else: ...@@ -281,7 +281,7 @@ else:
create_unicode_buffer(anInteger) -> character array create_unicode_buffer(anInteger) -> character array
create_unicode_buffer(aString, anInteger) -> character array create_unicode_buffer(aString, anInteger) -> character array
""" """
if isinstance(init, (str, unicode)): if isinstance(init, (str, str)):
if size is None: if size is None:
size = len(init)+1 size = len(init)+1
buftype = c_wchar * size buftype = c_wchar * size
......
...@@ -33,7 +33,7 @@ DEFAULT_LIBRARY_FALLBACK = [ ...@@ -33,7 +33,7 @@ DEFAULT_LIBRARY_FALLBACK = [
def ensure_utf8(s): def ensure_utf8(s):
"""Not all of PyObjC and Python understand unicode paths very well yet""" """Not all of PyObjC and Python understand unicode paths very well yet"""
if isinstance(s, unicode): if isinstance(s, str):
return s.encode('utf8') return s.encode('utf8')
return s return s
......
...@@ -24,7 +24,7 @@ class BasicWrapTestCase(unittest.TestCase): ...@@ -24,7 +24,7 @@ class BasicWrapTestCase(unittest.TestCase):
return return
f = dll._testfunc_i_bhilfd f = dll._testfunc_i_bhilfd
f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double] f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double]
result = f(self.wrap(1), self.wrap(u"x"), self.wrap(3), self.wrap(4), self.wrap(5.0), self.wrap(6.0)) result = f(self.wrap(1), self.wrap("x"), self.wrap(3), self.wrap(4), self.wrap(5.0), self.wrap(6.0))
self.failUnlessEqual(result, 139) self.failUnlessEqual(result, 139)
self.failUnless(type(result), int) self.failUnless(type(result), int)
......
...@@ -17,7 +17,7 @@ class StringBufferTestCase(unittest.TestCase): ...@@ -17,7 +17,7 @@ class StringBufferTestCase(unittest.TestCase):
self.failUnlessEqual(b[:], "abc\0") self.failUnlessEqual(b[:], "abc\0")
def test_string_conversion(self): def test_string_conversion(self):
b = create_string_buffer(u"abc") b = create_string_buffer("abc")
self.failUnlessEqual(len(b), 4) # trailing nul char self.failUnlessEqual(len(b), 4) # trailing nul char
self.failUnlessEqual(sizeof(b), 4 * sizeof(c_char)) self.failUnlessEqual(sizeof(b), 4 * sizeof(c_char))
self.failUnless(type(b[0]) is str) self.failUnless(type(b[0]) is str)
...@@ -33,21 +33,21 @@ class StringBufferTestCase(unittest.TestCase): ...@@ -33,21 +33,21 @@ class StringBufferTestCase(unittest.TestCase):
b = create_unicode_buffer(32) b = create_unicode_buffer(32)
self.failUnlessEqual(len(b), 32) self.failUnlessEqual(len(b), 32)
self.failUnlessEqual(sizeof(b), 32 * sizeof(c_wchar)) self.failUnlessEqual(sizeof(b), 32 * sizeof(c_wchar))
self.failUnless(type(b[0]) is unicode) self.failUnless(type(b[0]) is str)
b = create_unicode_buffer(u"abc") b = create_unicode_buffer("abc")
self.failUnlessEqual(len(b), 4) # trailing nul char self.failUnlessEqual(len(b), 4) # trailing nul char
self.failUnlessEqual(sizeof(b), 4 * sizeof(c_wchar)) self.failUnlessEqual(sizeof(b), 4 * sizeof(c_wchar))
self.failUnless(type(b[0]) is unicode) self.failUnless(type(b[0]) is str)
self.failUnlessEqual(b[0], u"a") self.failUnlessEqual(b[0], "a")
self.failUnlessEqual(b[:], "abc\0") self.failUnlessEqual(b[:], "abc\0")
def test_unicode_conversion(self): def test_unicode_conversion(self):
b = create_unicode_buffer("abc") b = create_unicode_buffer("abc")
self.failUnlessEqual(len(b), 4) # trailing nul char self.failUnlessEqual(len(b), 4) # trailing nul char
self.failUnlessEqual(sizeof(b), 4 * sizeof(c_wchar)) self.failUnlessEqual(sizeof(b), 4 * sizeof(c_wchar))
self.failUnless(type(b[0]) is unicode) self.failUnless(type(b[0]) is str)
self.failUnlessEqual(b[0], u"a") self.failUnlessEqual(b[0], "a")
self.failUnlessEqual(b[:], "abc\0") self.failUnlessEqual(b[:], "abc\0")
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -70,7 +70,7 @@ class FunctionTestCase(unittest.TestCase): ...@@ -70,7 +70,7 @@ class FunctionTestCase(unittest.TestCase):
return return
f = dll._testfunc_i_bhilfd f = dll._testfunc_i_bhilfd
f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double] f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double]
result = f(1, u"x", 3, 4, 5.0, 6.0) result = f(1, "x", 3, 4, 5.0, 6.0)
self.failUnlessEqual(result, 139) self.failUnlessEqual(result, 139)
self.failUnlessEqual(type(result), int) self.failUnlessEqual(type(result), int)
...@@ -83,7 +83,7 @@ class FunctionTestCase(unittest.TestCase): ...@@ -83,7 +83,7 @@ class FunctionTestCase(unittest.TestCase):
f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double]
f.restype = c_wchar f.restype = c_wchar
result = f(0, 0, 0, 0, 0, 0) result = f(0, 0, 0, 0, 0, 0)
self.failUnlessEqual(result, u'\x00') self.failUnlessEqual(result, '\x00')
def test_voidresult(self): def test_voidresult(self):
f = dll._testfunc_v f = dll._testfunc_v
......
...@@ -58,8 +58,8 @@ class SimpleTypesTestCase(unittest.TestCase): ...@@ -58,8 +58,8 @@ class SimpleTypesTestCase(unittest.TestCase):
self.failUnless(c_char_p.from_param(s)._obj is s) self.failUnless(c_char_p.from_param(s)._obj is s)
# new in 0.9.1: convert (encode) unicode to ascii # new in 0.9.1: convert (encode) unicode to ascii
self.failUnlessEqual(c_char_p.from_param(u"123")._obj, "123") self.failUnlessEqual(c_char_p.from_param("123")._obj, "123")
self.assertRaises(UnicodeEncodeError, c_char_p.from_param, u"123\377") self.assertRaises(UnicodeEncodeError, c_char_p.from_param, "123\377")
self.assertRaises(TypeError, c_char_p.from_param, 42) self.assertRaises(TypeError, c_char_p.from_param, 42)
...@@ -75,16 +75,16 @@ class SimpleTypesTestCase(unittest.TestCase): ...@@ -75,16 +75,16 @@ class SimpleTypesTestCase(unittest.TestCase):
except ImportError: except ImportError:
## print "(No c_wchar_p)" ## print "(No c_wchar_p)"
return return
s = u"123" s = "123"
if sys.platform == "win32": if sys.platform == "win32":
self.failUnless(c_wchar_p.from_param(s)._obj is s) self.failUnless(c_wchar_p.from_param(s)._obj is s)
self.assertRaises(TypeError, c_wchar_p.from_param, 42) self.assertRaises(TypeError, c_wchar_p.from_param, 42)
# new in 0.9.1: convert (decode) ascii to unicode # new in 0.9.1: convert (decode) ascii to unicode
self.failUnlessEqual(c_wchar_p.from_param("123")._obj, u"123") self.failUnlessEqual(c_wchar_p.from_param("123")._obj, "123")
self.assertRaises(UnicodeDecodeError, c_wchar_p.from_param, "123\377") self.assertRaises(UnicodeDecodeError, c_wchar_p.from_param, "123\377")
pa = c_wchar_p.from_param(c_wchar_p(u"123")) pa = c_wchar_p.from_param(c_wchar_p("123"))
self.failUnlessEqual(type(pa), c_wchar_p) self.failUnlessEqual(type(pa), c_wchar_p)
def test_int_pointers(self): def test_int_pointers(self):
......
...@@ -123,7 +123,7 @@ class CharPointersTestCase(unittest.TestCase): ...@@ -123,7 +123,7 @@ class CharPointersTestCase(unittest.TestCase):
pass pass
else: else:
self.failUnlessEqual(None, func(c_wchar_p(None))) self.failUnlessEqual(None, func(c_wchar_p(None)))
self.failUnlessEqual(u"123", func(c_wchar_p(u"123"))) self.failUnlessEqual("123", func(c_wchar_p("123")))
def test_instance(self): def test_instance(self):
func = testdll._testfunc_p_p func = testdll._testfunc_p_p
...@@ -157,24 +157,24 @@ else: ...@@ -157,24 +157,24 @@ else:
func.argtypes = POINTER(c_wchar), func.argtypes = POINTER(c_wchar),
self.failUnlessEqual(None, func(None)) self.failUnlessEqual(None, func(None))
self.failUnlessEqual(u"123", func(u"123")) self.failUnlessEqual("123", func("123"))
self.failUnlessEqual(None, func(c_wchar_p(None))) self.failUnlessEqual(None, func(c_wchar_p(None)))
self.failUnlessEqual(u"123", func(c_wchar_p(u"123"))) self.failUnlessEqual("123", func(c_wchar_p("123")))
self.failUnlessEqual(u"123", func(c_wbuffer(u"123"))) self.failUnlessEqual("123", func(c_wbuffer("123")))
ca = c_wchar("a") ca = c_wchar("a")
self.failUnlessEqual(u"a", func(pointer(ca))[0]) self.failUnlessEqual("a", func(pointer(ca))[0])
self.failUnlessEqual(u"a", func(byref(ca))[0]) self.failUnlessEqual("a", func(byref(ca))[0])
def test_c_wchar_p_arg(self): def test_c_wchar_p_arg(self):
func = testdll._testfunc_p_p func = testdll._testfunc_p_p
func.restype = c_wchar_p func.restype = c_wchar_p
func.argtypes = c_wchar_p, func.argtypes = c_wchar_p,
c_wchar_p.from_param(u"123") c_wchar_p.from_param("123")
self.failUnlessEqual(None, func(None)) self.failUnlessEqual(None, func(None))
self.failUnlessEqual("123", func(u"123")) self.failUnlessEqual("123", func("123"))
self.failUnlessEqual(None, func(c_wchar_p(None))) self.failUnlessEqual(None, func(c_wchar_p(None)))
self.failUnlessEqual("123", func(c_wchar_p("123"))) self.failUnlessEqual("123", func(c_wchar_p("123")))
......
...@@ -45,7 +45,7 @@ class SlicesTestCase(unittest.TestCase): ...@@ -45,7 +45,7 @@ class SlicesTestCase(unittest.TestCase):
import operator import operator
self.assertRaises(TypeError, operator.setslice, self.assertRaises(TypeError, operator.setslice,
res, 0, 5, u"abcde") res, 0, 5, "abcde")
dll.my_free(res) dll.my_free(res)
dll.my_strdup.restype = POINTER(c_byte) dll.my_strdup.restype = POINTER(c_byte)
...@@ -88,7 +88,7 @@ class SlicesTestCase(unittest.TestCase): ...@@ -88,7 +88,7 @@ class SlicesTestCase(unittest.TestCase):
pass pass
else: else:
def test_wchar_ptr(self): def test_wchar_ptr(self):
s = u"abcdefghijklmnopqrstuvwxyz\0" s = "abcdefghijklmnopqrstuvwxyz\0"
dll = CDLL(_ctypes_test.__file__) dll = CDLL(_ctypes_test.__file__)
dll.my_wcsdup.restype = POINTER(c_wchar) dll.my_wcsdup.restype = POINTER(c_wchar)
...@@ -99,7 +99,7 @@ class SlicesTestCase(unittest.TestCase): ...@@ -99,7 +99,7 @@ class SlicesTestCase(unittest.TestCase):
import operator import operator
self.assertRaises(TypeError, operator.setslice, self.assertRaises(TypeError, operator.setslice,
res, 0, 5, u"abcde") res, 0, 5, "abcde")
dll.my_free(res) dll.my_free(res)
if sizeof(c_wchar) == sizeof(c_short): if sizeof(c_wchar) == sizeof(c_short):
......
...@@ -62,17 +62,17 @@ else: ...@@ -62,17 +62,17 @@ else:
def test(self): def test(self):
BUF = c_wchar * 4 BUF = c_wchar * 4
buf = BUF(u"a", u"b", u"c") buf = BUF("a", "b", "c")
self.failUnlessEqual(buf.value, u"abc") self.failUnlessEqual(buf.value, "abc")
buf.value = u"ABCD" buf.value = "ABCD"
self.failUnlessEqual(buf.value, u"ABCD") self.failUnlessEqual(buf.value, "ABCD")
buf.value = u"x" buf.value = "x"
self.failUnlessEqual(buf.value, u"x") self.failUnlessEqual(buf.value, "x")
buf[1] = u"Z" buf[1] = "Z"
self.failUnlessEqual(buf.value, u"xZCD") self.failUnlessEqual(buf.value, "xZCD")
class StringTestCase(unittest.TestCase): class StringTestCase(unittest.TestCase):
def XX_test_basic_strings(self): def XX_test_basic_strings(self):
...@@ -99,7 +99,7 @@ class StringTestCase(unittest.TestCase): ...@@ -99,7 +99,7 @@ class StringTestCase(unittest.TestCase):
self.failUnlessEqual(cs.value, "XY") self.failUnlessEqual(cs.value, "XY")
self.failUnlessEqual(cs.raw, "XY\000\000\000\000\000") self.failUnlessEqual(cs.raw, "XY\000\000\000\000\000")
self.assertRaises(TypeError, c_string, u"123") self.assertRaises(TypeError, c_string, "123")
def XX_test_sized_strings(self): def XX_test_sized_strings(self):
...@@ -142,13 +142,13 @@ except NameError: ...@@ -142,13 +142,13 @@ except NameError:
else: else:
class WStringTestCase(unittest.TestCase): class WStringTestCase(unittest.TestCase):
def test_wchar(self): def test_wchar(self):
c_wchar(u"x") c_wchar("x")
repr(byref(c_wchar(u"x"))) repr(byref(c_wchar("x")))
c_wchar("x") c_wchar("x")
def X_test_basic_wstrings(self): def X_test_basic_wstrings(self):
cs = c_wstring(u"abcdef") cs = c_wstring("abcdef")
# XXX This behaviour is about to change: # XXX This behaviour is about to change:
# len returns the size of the internal buffer in bytes. # len returns the size of the internal buffer in bytes.
...@@ -156,30 +156,30 @@ else: ...@@ -156,30 +156,30 @@ else:
self.failUnless(sizeof(cs) == 14) self.failUnless(sizeof(cs) == 14)
# The value property is the string up to the first terminating NUL. # The value property is the string up to the first terminating NUL.
self.failUnless(cs.value == u"abcdef") self.failUnless(cs.value == "abcdef")
self.failUnless(c_wstring(u"abc\000def").value == u"abc") self.failUnless(c_wstring("abc\000def").value == "abc")
self.failUnless(c_wstring(u"abc\000def").value == u"abc") self.failUnless(c_wstring("abc\000def").value == "abc")
# The raw property is the total buffer contents: # The raw property is the total buffer contents:
self.failUnless(cs.raw == u"abcdef\000") self.failUnless(cs.raw == "abcdef\000")
self.failUnless(c_wstring(u"abc\000def").raw == u"abc\000def\000") self.failUnless(c_wstring("abc\000def").raw == "abc\000def\000")
# We can change the value: # We can change the value:
cs.value = u"ab" cs.value = "ab"
self.failUnless(cs.value == u"ab") self.failUnless(cs.value == "ab")
self.failUnless(cs.raw == u"ab\000\000\000\000\000") self.failUnless(cs.raw == "ab\000\000\000\000\000")
self.assertRaises(TypeError, c_wstring, "123") self.assertRaises(TypeError, c_wstring, "123")
self.assertRaises(ValueError, c_wstring, 0) self.assertRaises(ValueError, c_wstring, 0)
def X_test_toolong(self): def X_test_toolong(self):
cs = c_wstring(u"abcdef") cs = c_wstring("abcdef")
# Much too long string: # Much too long string:
self.assertRaises(ValueError, setattr, cs, "value", u"123456789012345") self.assertRaises(ValueError, setattr, cs, "value", "123456789012345")
# One char too long values: # One char too long values:
self.assertRaises(ValueError, setattr, cs, "value", u"1234567") self.assertRaises(ValueError, setattr, cs, "value", "1234567")
def run_test(rep, msg, func, arg): def run_test(rep, msg, func, arg):
......
...@@ -269,15 +269,15 @@ class StructureTestCase(unittest.TestCase): ...@@ -269,15 +269,15 @@ class StructureTestCase(unittest.TestCase):
_fields_ = [("name", c_wchar * 12), _fields_ = [("name", c_wchar * 12),
("age", c_int)] ("age", c_int)]
p = PersonW(u"Someone") p = PersonW("Someone")
self.failUnlessEqual(p.name, "Someone") self.failUnlessEqual(p.name, "Someone")
self.failUnlessEqual(PersonW(u"1234567890").name, u"1234567890") self.failUnlessEqual(PersonW("1234567890").name, "1234567890")
self.failUnlessEqual(PersonW(u"12345678901").name, u"12345678901") self.failUnlessEqual(PersonW("12345678901").name, "12345678901")
# exact fit # exact fit
self.failUnlessEqual(PersonW(u"123456789012").name, u"123456789012") self.failUnlessEqual(PersonW("123456789012").name, "123456789012")
#too long #too long
self.assertRaises(ValueError, PersonW, u"1234567890123") self.assertRaises(ValueError, PersonW, "1234567890123")
def test_init_errors(self): def test_init_errors(self):
class Phone(Structure): class Phone(Structure):
......
...@@ -23,31 +23,31 @@ else: ...@@ -23,31 +23,31 @@ else:
def test_ascii_strict(self): def test_ascii_strict(self):
ctypes.set_conversion_mode("ascii", "strict") ctypes.set_conversion_mode("ascii", "strict")
# no conversions take place with unicode arguments # no conversions take place with unicode arguments
self.failUnlessEqual(wcslen(u"abc"), 3) self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessEqual(wcslen(u"ab\u2070"), 3) self.failUnlessEqual(wcslen("ab\u2070"), 3)
# string args are converted # string args are converted
self.failUnlessEqual(wcslen("abc"), 3) self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessRaises(ctypes.ArgumentError, wcslen, "ab") self.failUnlessRaises(ctypes.ArgumentError, wcslen, "ab")
def test_ascii_replace(self): def test_ascii_replace(self):
ctypes.set_conversion_mode("ascii", "replace") ctypes.set_conversion_mode("ascii", "replace")
self.failUnlessEqual(wcslen(u"abc"), 3) self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessEqual(wcslen(u"ab\u2070"), 3) self.failUnlessEqual(wcslen("ab\u2070"), 3)
self.failUnlessEqual(wcslen("abc"), 3) self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessEqual(wcslen("ab"), 3) self.failUnlessEqual(wcslen("ab"), 3)
def test_ascii_ignore(self): def test_ascii_ignore(self):
ctypes.set_conversion_mode("ascii", "ignore") ctypes.set_conversion_mode("ascii", "ignore")
self.failUnlessEqual(wcslen(u"abc"), 3) self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessEqual(wcslen(u"ab\u2070"), 3) self.failUnlessEqual(wcslen("ab\u2070"), 3)
# ignore error mode skips non-ascii characters # ignore error mode skips non-ascii characters
self.failUnlessEqual(wcslen("abc"), 3) self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessEqual(wcslen(""), 0) self.failUnlessEqual(wcslen(""), 0)
def test_latin1_strict(self): def test_latin1_strict(self):
ctypes.set_conversion_mode("latin-1", "strict") ctypes.set_conversion_mode("latin-1", "strict")
self.failUnlessEqual(wcslen(u"abc"), 3) self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessEqual(wcslen(u"ab\u2070"), 3) self.failUnlessEqual(wcslen("ab\u2070"), 3)
self.failUnlessEqual(wcslen("abc"), 3) self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessEqual(wcslen(""), 4) self.failUnlessEqual(wcslen(""), 4)
...@@ -58,12 +58,12 @@ else: ...@@ -58,12 +58,12 @@ else:
ctypes.set_conversion_mode("ascii", "replace") ctypes.set_conversion_mode("ascii", "replace")
buf = ctypes.create_unicode_buffer("ab") buf = ctypes.create_unicode_buffer("ab")
self.failUnlessEqual(buf[:], u"ab\uFFFD\uFFFD\uFFFD\0") self.failUnlessEqual(buf[:], "ab\uFFFD\uFFFD\uFFFD\0")
ctypes.set_conversion_mode("ascii", "ignore") ctypes.set_conversion_mode("ascii", "ignore")
buf = ctypes.create_unicode_buffer("ab") buf = ctypes.create_unicode_buffer("ab")
# is that correct? not sure. But with 'ignore', you get what you pay for.. # is that correct? not sure. But with 'ignore', you get what you pay for..
self.failUnlessEqual(buf[:], u"ab\0\0\0\0") self.failUnlessEqual(buf[:], "ab\0\0\0\0")
import _ctypes_test import _ctypes_test
func = ctypes.CDLL(_ctypes_test.__file__)._testfunc_p_p func = ctypes.CDLL(_ctypes_test.__file__)._testfunc_p_p
...@@ -82,32 +82,32 @@ else: ...@@ -82,32 +82,32 @@ else:
def test_ascii_replace(self): def test_ascii_replace(self):
ctypes.set_conversion_mode("ascii", "strict") ctypes.set_conversion_mode("ascii", "strict")
self.failUnlessEqual(func("abc"), "abc") self.failUnlessEqual(func("abc"), "abc")
self.failUnlessEqual(func(u"abc"), "abc") self.failUnlessEqual(func("abc"), "abc")
self.assertRaises(ctypes.ArgumentError, func, u"ab") self.assertRaises(ctypes.ArgumentError, func, "ab")
def test_ascii_ignore(self): def test_ascii_ignore(self):
ctypes.set_conversion_mode("ascii", "ignore") ctypes.set_conversion_mode("ascii", "ignore")
self.failUnlessEqual(func("abc"), "abc") self.failUnlessEqual(func("abc"), "abc")
self.failUnlessEqual(func(u"abc"), "abc") self.failUnlessEqual(func("abc"), "abc")
self.failUnlessEqual(func(u""), "") self.failUnlessEqual(func(""), "")
def test_ascii_replace(self): def test_ascii_replace(self):
ctypes.set_conversion_mode("ascii", "replace") ctypes.set_conversion_mode("ascii", "replace")
self.failUnlessEqual(func("abc"), "abc") self.failUnlessEqual(func("abc"), "abc")
self.failUnlessEqual(func(u"abc"), "abc") self.failUnlessEqual(func("abc"), "abc")
self.failUnlessEqual(func(u""), "????") self.failUnlessEqual(func(""), "????")
def test_buffers(self): def test_buffers(self):
ctypes.set_conversion_mode("ascii", "strict") ctypes.set_conversion_mode("ascii", "strict")
buf = ctypes.create_string_buffer(u"abc") buf = ctypes.create_string_buffer("abc")
self.failUnlessEqual(len(buf), 3+1) self.failUnlessEqual(len(buf), 3+1)
ctypes.set_conversion_mode("ascii", "replace") ctypes.set_conversion_mode("ascii", "replace")
buf = ctypes.create_string_buffer(u"ab") buf = ctypes.create_string_buffer("ab")
self.failUnlessEqual(buf[:], "ab???\0") self.failUnlessEqual(buf[:], "ab???\0")
ctypes.set_conversion_mode("ascii", "ignore") ctypes.set_conversion_mode("ascii", "ignore")
buf = ctypes.create_string_buffer(u"ab") buf = ctypes.create_string_buffer("ab")
# is that correct? not sure. But with 'ignore', you get what you pay for.. # is that correct? not sure. But with 'ignore', you get what you pay for..
self.failUnlessEqual(buf[:], "ab\0\0\0\0") self.failUnlessEqual(buf[:], "ab\0\0\0\0")
......
...@@ -247,11 +247,11 @@ class bdist_wininst (Command): ...@@ -247,11 +247,11 @@ class bdist_wininst (Command):
# Convert cfgdata from unicode to ascii, mbcs encoded # Convert cfgdata from unicode to ascii, mbcs encoded
try: try:
unicode str
except NameError: except NameError:
pass pass
else: else:
if isinstance(cfgdata, unicode): if isinstance(cfgdata, str):
cfgdata = cfgdata.encode("mbcs") cfgdata = cfgdata.encode("mbcs")
# Append the pre-install script # Append the pre-install script
......
...@@ -147,7 +147,7 @@ class build_clib (Command): ...@@ -147,7 +147,7 @@ class build_clib (Command):
raise DistutilsSetupError, \ raise DistutilsSetupError, \
"each element of 'libraries' must a 2-tuple" "each element of 'libraries' must a 2-tuple"
if isinstance(lib[0], basestring) StringType: if isinstance(lib[0], basestring):
raise DistutilsSetupError, \ raise DistutilsSetupError, \
"first element of each tuple in 'libraries' " + \ "first element of each tuple in 'libraries' " + \
"must be a string (the library name)" "must be a string (the library name)"
......
...@@ -259,7 +259,7 @@ Your selection [default 1]: ''', end=' ') ...@@ -259,7 +259,7 @@ Your selection [default 1]: ''', end=' ')
if type(value) not in (type([]), type( () )): if type(value) not in (type([]), type( () )):
value = [value] value = [value]
for value in value: for value in value:
value = unicode(value).encode("utf-8") value = str(value).encode("utf-8")
body.write(sep_boundary) body.write(sep_boundary)
body.write('\nContent-Disposition: form-data; name="%s"'%key) body.write('\nContent-Disposition: form-data; name="%s"'%key)
body.write("\n\n") body.write("\n\n")
......
...@@ -196,7 +196,7 @@ def _normalize_module(module, depth=2): ...@@ -196,7 +196,7 @@ def _normalize_module(module, depth=2):
""" """
if inspect.ismodule(module): if inspect.ismodule(module):
return module return module
elif isinstance(module, (str, unicode)): elif isinstance(module, (str, str)):
return __import__(module, globals(), locals(), ["*"]) return __import__(module, globals(), locals(), ["*"])
elif module is None: elif module is None:
return sys.modules[sys._getframe(depth).f_globals['__name__']] return sys.modules[sys._getframe(depth).f_globals['__name__']]
......
...@@ -202,10 +202,10 @@ class Charset: ...@@ -202,10 +202,10 @@ class Charset:
# is already a unicode, we leave it at that, but ensure that the # is already a unicode, we leave it at that, but ensure that the
# charset is ASCII, as the standard (RFC XXX) requires. # charset is ASCII, as the standard (RFC XXX) requires.
try: try:
if isinstance(input_charset, unicode): if isinstance(input_charset, str):
input_charset.encode('ascii') input_charset.encode('ascii')
else: else:
input_charset = unicode(input_charset, 'ascii') input_charset = str(input_charset, 'ascii')
except UnicodeError: except UnicodeError:
raise errors.CharsetError(input_charset) raise errors.CharsetError(input_charset)
input_charset = input_charset.lower() input_charset = input_charset.lower()
...@@ -264,7 +264,7 @@ class Charset: ...@@ -264,7 +264,7 @@ class Charset:
def convert(self, s): def convert(self, s):
"""Convert a string from the input_codec to the output_codec.""" """Convert a string from the input_codec to the output_codec."""
if self.input_codec != self.output_codec: if self.input_codec != self.output_codec:
return unicode(s, self.input_codec).encode(self.output_codec) return str(s, self.input_codec).encode(self.output_codec)
else: else:
return s return s
...@@ -281,10 +281,10 @@ class Charset: ...@@ -281,10 +281,10 @@ class Charset:
Characters that could not be converted to Unicode will be replaced Characters that could not be converted to Unicode will be replaced
with the Unicode replacement character U+FFFD. with the Unicode replacement character U+FFFD.
""" """
if isinstance(s, unicode) or self.input_codec is None: if isinstance(s, str) or self.input_codec is None:
return s return s
try: try:
return unicode(s, self.input_codec, 'replace') return str(s, self.input_codec, 'replace')
except LookupError: except LookupError:
# Input codec not installed on system, so return the original # Input codec not installed on system, so return the original
# string unchanged. # string unchanged.
...@@ -307,7 +307,7 @@ class Charset: ...@@ -307,7 +307,7 @@ class Charset:
codec = self.output_codec codec = self.output_codec
else: else:
codec = self.input_codec codec = self.input_codec
if not isinstance(ustr, unicode) or codec is None: if not isinstance(ustr, str) or codec is None:
return ustr return ustr
try: try:
return ustr.encode(codec, 'replace') return ustr.encode(codec, 'replace')
......
...@@ -23,7 +23,7 @@ fcre = re.compile(r'^From ', re.MULTILINE) ...@@ -23,7 +23,7 @@ fcre = re.compile(r'^From ', re.MULTILINE)
def _is8bitstring(s): def _is8bitstring(s):
if isinstance(s, str): if isinstance(s, str):
try: try:
unicode(s, 'us-ascii') str(s, 'us-ascii')
except UnicodeError: except UnicodeError:
return True return True
return False return False
......
...@@ -21,9 +21,9 @@ from email.charset import Charset ...@@ -21,9 +21,9 @@ from email.charset import Charset
NL = '\n' NL = '\n'
SPACE = ' ' SPACE = ' '
USPACE = u' ' USPACE = ' '
SPACE8 = ' ' * 8 SPACE8 = ' ' * 8
UEMPTYSTRING = u'' UEMPTYSTRING = ''
MAXLINELEN = 76 MAXLINELEN = 76
...@@ -210,7 +210,7 @@ class Header: ...@@ -210,7 +210,7 @@ class Header:
elif nextcs not in (None, 'us-ascii'): elif nextcs not in (None, 'us-ascii'):
uchunks.append(USPACE) uchunks.append(USPACE)
lastcs = nextcs lastcs = nextcs
uchunks.append(unicode(s, str(charset))) uchunks.append(str(s, str(charset)))
return UEMPTYSTRING.join(uchunks) return UEMPTYSTRING.join(uchunks)
# Rich comparison operators for equality only. BAW: does it make sense to # Rich comparison operators for equality only. BAW: does it make sense to
...@@ -257,13 +257,13 @@ class Header: ...@@ -257,13 +257,13 @@ class Header:
# Possibly raise UnicodeError if the byte string can't be # Possibly raise UnicodeError if the byte string can't be
# converted to a unicode with the input codec of the charset. # converted to a unicode with the input codec of the charset.
incodec = charset.input_codec or 'us-ascii' incodec = charset.input_codec or 'us-ascii'
ustr = unicode(s, incodec, errors) ustr = str(s, incodec, errors)
# Now make sure that the unicode could be converted back to a # Now make sure that the unicode could be converted back to a
# byte string with the output codec, which may be different # byte string with the output codec, which may be different
# than the iput coded. Still, use the original byte string. # than the iput coded. Still, use the original byte string.
outcodec = charset.output_codec or 'us-ascii' outcodec = charset.output_codec or 'us-ascii'
ustr.encode(outcodec, errors) ustr.encode(outcodec, errors)
elif isinstance(s, unicode): elif isinstance(s, str):
# Now we have to be sure the unicode string can be converted # Now we have to be sure the unicode string can be converted
# to a byte string with a reasonable output codec. We want to # to a byte string with a reasonable output codec. We want to
# use the byte string in the chunk. # use the byte string in the chunk.
......
...@@ -751,13 +751,13 @@ class Message: ...@@ -751,13 +751,13 @@ class Message:
# LookupError will be raised if the charset isn't known to # LookupError will be raised if the charset isn't known to
# Python. UnicodeError will be raised if the encoded text # Python. UnicodeError will be raised if the encoded text
# contains a character not in the charset. # contains a character not in the charset.
charset = unicode(charset[2], pcharset).encode('us-ascii') charset = str(charset[2], pcharset).encode('us-ascii')
except (LookupError, UnicodeError): except (LookupError, UnicodeError):
charset = charset[2] charset = charset[2]
# charset character must be in us-ascii range # charset character must be in us-ascii range
try: try:
if isinstance(charset, str): if isinstance(charset, str):
charset = unicode(charset, 'us-ascii') charset = str(charset, 'us-ascii')
charset = charset.encode('us-ascii') charset = charset.encode('us-ascii')
except UnicodeError: except UnicodeError:
return failobj return failobj
......
...@@ -505,7 +505,7 @@ class TestMessageAPI(TestEmailBase): ...@@ -505,7 +505,7 @@ class TestMessageAPI(TestEmailBase):
msg = Message() msg = Message()
msg.set_charset('us-ascii') msg.set_charset('us-ascii')
self.assertEqual('us-ascii', msg.get_content_charset()) self.assertEqual('us-ascii', msg.get_content_charset())
msg.set_charset(u'us-ascii') msg.set_charset('us-ascii')
self.assertEqual('us-ascii', msg.get_content_charset()) self.assertEqual('us-ascii', msg.get_content_charset())
...@@ -583,7 +583,7 @@ bug demonstration ...@@ -583,7 +583,7 @@ bug demonstration
utf8 = Charset("utf-8") utf8 = Charset("utf-8")
g_head = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. " g_head = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. "
cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. " cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. "
utf8_head = u"\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8") utf8_head = "\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8")
h = Header(g_head, g, header_name='Subject') h = Header(g_head, g, header_name='Subject')
h.append(cz_head, cz) h.append(cz_head, cz)
h.append(utf8_head, utf8) h.append(utf8_head, utf8)
...@@ -1514,7 +1514,7 @@ class TestRFC2047(unittest.TestCase): ...@@ -1514,7 +1514,7 @@ class TestRFC2047(unittest.TestCase):
s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>' s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>'
dh = decode_header(s) dh = decode_header(s)
eq(dh, [('Andr\xe9', 'iso-8859-1'), ('Pirard <pirard@dom.ain>', None)]) eq(dh, [('Andr\xe9', 'iso-8859-1'), ('Pirard <pirard@dom.ain>', None)])
hu = unicode(make_header(dh)).encode('latin-1') hu = str(make_header(dh)).encode('latin-1')
eq(hu, 'Andr\xe9 Pirard <pirard@dom.ain>') eq(hu, 'Andr\xe9 Pirard <pirard@dom.ain>')
def test_whitespace_eater_unicode_2(self): def test_whitespace_eater_unicode_2(self):
...@@ -1524,7 +1524,7 @@ class TestRFC2047(unittest.TestCase): ...@@ -1524,7 +1524,7 @@ class TestRFC2047(unittest.TestCase):
eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'), eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'),
('jumped over the', None), ('lazy dog', 'iso-8859-1')]) ('jumped over the', None), ('lazy dog', 'iso-8859-1')])
hu = make_header(dh).__unicode__() hu = make_header(dh).__unicode__()
eq(hu, u'The quick brown fox jumped over the lazy dog') eq(hu, 'The quick brown fox jumped over the lazy dog')
def test_rfc2047_without_whitespace(self): def test_rfc2047_without_whitespace(self):
s = 'Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord' s = 'Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord'
...@@ -2770,7 +2770,7 @@ class TestCharset(unittest.TestCase): ...@@ -2770,7 +2770,7 @@ class TestCharset(unittest.TestCase):
eq('hello w\xf6rld', c.body_encode('hello w\xf6rld')) eq('hello w\xf6rld', c.body_encode('hello w\xf6rld'))
def test_unicode_charset_name(self): def test_unicode_charset_name(self):
charset = Charset(u'us-ascii') charset = Charset('us-ascii')
self.assertEqual(str(charset), 'us-ascii') self.assertEqual(str(charset), 'us-ascii')
self.assertRaises(Errors.CharsetError, Charset, 'asc\xffii') self.assertRaises(Errors.CharsetError, Charset, 'asc\xffii')
...@@ -2809,7 +2809,7 @@ class TestHeader(TestEmailBase): ...@@ -2809,7 +2809,7 @@ class TestHeader(TestEmailBase):
utf8 = Charset("utf-8") utf8 = Charset("utf-8")
g_head = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. " g_head = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. "
cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. " cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. "
utf8_head = u"\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8") utf8_head = "\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8")
h = Header(g_head, g) h = Header(g_head, g)
h.append(cz_head, cz) h.append(cz_head, cz)
h.append(utf8_head, utf8) h.append(utf8_head, utf8)
...@@ -2829,7 +2829,7 @@ class TestHeader(TestEmailBase): ...@@ -2829,7 +2829,7 @@ class TestHeader(TestEmailBase):
eq(decode_header(enc), eq(decode_header(enc),
[(g_head, "iso-8859-1"), (cz_head, "iso-8859-2"), [(g_head, "iso-8859-1"), (cz_head, "iso-8859-2"),
(utf8_head, "utf-8")]) (utf8_head, "utf-8")])
ustr = unicode(h) ustr = str(h)
eq(ustr.encode('utf-8'), eq(ustr.encode('utf-8'),
'Die Mieter treten hier ein werden mit einem Foerderband ' 'Die Mieter treten hier ein werden mit einem Foerderband '
'komfortabel den Korridor entlang, an s\xc3\xbcdl\xc3\xbcndischen ' 'komfortabel den Korridor entlang, an s\xc3\xbcdl\xc3\xbcndischen '
...@@ -2897,9 +2897,9 @@ A very long line that must get split to something other than at the ...@@ -2897,9 +2897,9 @@ A very long line that must get split to something other than at the
def test_utf8_shortest(self): def test_utf8_shortest(self):
eq = self.assertEqual eq = self.assertEqual
h = Header(u'p\xf6stal', 'utf-8') h = Header('p\xf6stal', 'utf-8')
eq(h.encode(), '=?utf-8?q?p=C3=B6stal?=') eq(h.encode(), '=?utf-8?q?p=C3=B6stal?=')
h = Header(u'\u83ca\u5730\u6642\u592b', 'utf-8') h = Header('\u83ca\u5730\u6642\u592b', 'utf-8')
eq(h.encode(), '=?utf-8?b?6I+K5Zyw5pmC5aSr?=') eq(h.encode(), '=?utf-8?b?6I+K5Zyw5pmC5aSr?=')
def test_bad_8bit_header(self): def test_bad_8bit_header(self):
...@@ -3152,7 +3152,7 @@ Content-Disposition: inline; ...@@ -3152,7 +3152,7 @@ Content-Disposition: inline;
''' '''
msg = email.message_from_string(m) msg = email.message_from_string(m)
self.assertEqual(msg.get_filename(), self.assertEqual(msg.get_filename(),
u'This is even more ***fun*** is it not.pdf\ufffd') 'This is even more ***fun*** is it not.pdf\ufffd')
def test_rfc2231_unknown_encoding(self): def test_rfc2231_unknown_encoding(self):
m = """\ m = """\
......
...@@ -13,7 +13,7 @@ from email.Message import Message ...@@ -13,7 +13,7 @@ from email.Message import Message
# We're compatible with Python 2.3, but it doesn't have the built-in Asian # We're compatible with Python 2.3, but it doesn't have the built-in Asian
# codecs, so we have to skip all these tests. # codecs, so we have to skip all these tests.
try: try:
unicode('foo', 'euc-jp') str('foo', 'euc-jp')
except LookupError: except LookupError:
raise TestSkipped raise TestSkipped
...@@ -57,7 +57,7 @@ Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?= ...@@ -57,7 +57,7 @@ Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?=
jcode = 'euc-jp' jcode = 'euc-jp'
msg = Message() msg = Message()
msg.set_payload(jhello, jcode) msg.set_payload(jhello, jcode)
ustr = unicode(msg.get_payload(), msg.get_content_charset()) ustr = str(msg.get_payload(), msg.get_content_charset())
self.assertEqual(jhello, ustr.encode(jcode)) self.assertEqual(jhello, ustr.encode(jcode))
......
...@@ -13,7 +13,7 @@ from email.message import Message ...@@ -13,7 +13,7 @@ from email.message import Message
# We're compatible with Python 2.3, but it doesn't have the built-in Asian # We're compatible with Python 2.3, but it doesn't have the built-in Asian
# codecs, so we have to skip all these tests. # codecs, so we have to skip all these tests.
try: try:
unicode('foo', 'euc-jp') str('foo', 'euc-jp')
except LookupError: except LookupError:
raise TestSkipped raise TestSkipped
...@@ -57,7 +57,7 @@ Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?= ...@@ -57,7 +57,7 @@ Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?=
jcode = 'euc-jp' jcode = 'euc-jp'
msg = Message() msg = Message()
msg.set_payload(jhello, jcode) msg.set_payload(jhello, jcode)
ustr = unicode(msg.get_payload(), msg.get_content_charset()) ustr = str(msg.get_payload(), msg.get_content_charset())
self.assertEqual(jhello, ustr.encode(jcode)) self.assertEqual(jhello, ustr.encode(jcode))
......
...@@ -564,7 +564,7 @@ bug demonstration ...@@ -564,7 +564,7 @@ bug demonstration
utf8 = Charset("utf-8") utf8 = Charset("utf-8")
g_head = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. " g_head = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. "
cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. " cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. "
utf8_head = u"\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8") utf8_head = "\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8")
h = Header(g_head, g, header_name='Subject') h = Header(g_head, g, header_name='Subject')
h.append(cz_head, cz) h.append(cz_head, cz)
h.append(utf8_head, utf8) h.append(utf8_head, utf8)
...@@ -1512,7 +1512,7 @@ class TestRFC2047(unittest.TestCase): ...@@ -1512,7 +1512,7 @@ class TestRFC2047(unittest.TestCase):
s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>' s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>'
dh = decode_header(s) dh = decode_header(s)
eq(dh, [('Andr\xe9', 'iso-8859-1'), ('Pirard <pirard@dom.ain>', None)]) eq(dh, [('Andr\xe9', 'iso-8859-1'), ('Pirard <pirard@dom.ain>', None)])
hu = unicode(make_header(dh)).encode('latin-1') hu = str(make_header(dh)).encode('latin-1')
eq(hu, 'Andr\xe9 Pirard <pirard@dom.ain>') eq(hu, 'Andr\xe9 Pirard <pirard@dom.ain>')
def test_whitespace_eater_unicode_2(self): def test_whitespace_eater_unicode_2(self):
...@@ -1522,7 +1522,7 @@ class TestRFC2047(unittest.TestCase): ...@@ -1522,7 +1522,7 @@ class TestRFC2047(unittest.TestCase):
eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'), eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'),
('jumped over the', None), ('lazy dog', 'iso-8859-1')]) ('jumped over the', None), ('lazy dog', 'iso-8859-1')])
hu = make_header(dh).__unicode__() hu = make_header(dh).__unicode__()
eq(hu, u'The quick brown fox jumped over the lazy dog') eq(hu, 'The quick brown fox jumped over the lazy dog')
def test_rfc2047_missing_whitespace(self): def test_rfc2047_missing_whitespace(self):
s = 'Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord' s = 'Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord'
...@@ -2769,7 +2769,7 @@ class TestCharset(unittest.TestCase): ...@@ -2769,7 +2769,7 @@ class TestCharset(unittest.TestCase):
eq('hello w\xf6rld', c.body_encode('hello w\xf6rld')) eq('hello w\xf6rld', c.body_encode('hello w\xf6rld'))
def test_unicode_charset_name(self): def test_unicode_charset_name(self):
charset = Charset(u'us-ascii') charset = Charset('us-ascii')
self.assertEqual(str(charset), 'us-ascii') self.assertEqual(str(charset), 'us-ascii')
self.assertRaises(errors.CharsetError, Charset, 'asc\xffii') self.assertRaises(errors.CharsetError, Charset, 'asc\xffii')
...@@ -2808,7 +2808,7 @@ class TestHeader(TestEmailBase): ...@@ -2808,7 +2808,7 @@ class TestHeader(TestEmailBase):
utf8 = Charset("utf-8") utf8 = Charset("utf-8")
g_head = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. " g_head = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. "
cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. " cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. "
utf8_head = u"\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8") utf8_head = "\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8")
h = Header(g_head, g) h = Header(g_head, g)
h.append(cz_head, cz) h.append(cz_head, cz)
h.append(utf8_head, utf8) h.append(utf8_head, utf8)
...@@ -2828,7 +2828,7 @@ class TestHeader(TestEmailBase): ...@@ -2828,7 +2828,7 @@ class TestHeader(TestEmailBase):
eq(decode_header(enc), eq(decode_header(enc),
[(g_head, "iso-8859-1"), (cz_head, "iso-8859-2"), [(g_head, "iso-8859-1"), (cz_head, "iso-8859-2"),
(utf8_head, "utf-8")]) (utf8_head, "utf-8")])
ustr = unicode(h) ustr = str(h)
eq(ustr.encode('utf-8'), eq(ustr.encode('utf-8'),
'Die Mieter treten hier ein werden mit einem Foerderband ' 'Die Mieter treten hier ein werden mit einem Foerderband '
'komfortabel den Korridor entlang, an s\xc3\xbcdl\xc3\xbcndischen ' 'komfortabel den Korridor entlang, an s\xc3\xbcdl\xc3\xbcndischen '
...@@ -2896,9 +2896,9 @@ A very long line that must get split to something other than at the ...@@ -2896,9 +2896,9 @@ A very long line that must get split to something other than at the
def test_utf8_shortest(self): def test_utf8_shortest(self):
eq = self.assertEqual eq = self.assertEqual
h = Header(u'p\xf6stal', 'utf-8') h = Header('p\xf6stal', 'utf-8')
eq(h.encode(), '=?utf-8?q?p=C3=B6stal?=') eq(h.encode(), '=?utf-8?q?p=C3=B6stal?=')
h = Header(u'\u83ca\u5730\u6642\u592b', 'utf-8') h = Header('\u83ca\u5730\u6642\u592b', 'utf-8')
eq(h.encode(), '=?utf-8?b?6I+K5Zyw5pmC5aSr?=') eq(h.encode(), '=?utf-8?b?6I+K5Zyw5pmC5aSr?=')
def test_bad_8bit_header(self): def test_bad_8bit_header(self):
...@@ -3151,7 +3151,7 @@ Content-Disposition: inline; ...@@ -3151,7 +3151,7 @@ Content-Disposition: inline;
''' '''
msg = email.message_from_string(m) msg = email.message_from_string(m)
self.assertEqual(msg.get_filename(), self.assertEqual(msg.get_filename(),
u'This is even more ***fun*** is it not.pdf\ufffd') 'This is even more ***fun*** is it not.pdf\ufffd')
def test_rfc2231_unknown_encoding(self): def test_rfc2231_unknown_encoding(self):
m = """\ m = """\
......
...@@ -44,7 +44,7 @@ from email.encoders import _bencode, _qencode ...@@ -44,7 +44,7 @@ from email.encoders import _bencode, _qencode
COMMASPACE = ', ' COMMASPACE = ', '
EMPTYSTRING = '' EMPTYSTRING = ''
UEMPTYSTRING = u'' UEMPTYSTRING = ''
CRLF = '\r\n' CRLF = '\r\n'
TICK = "'" TICK = "'"
...@@ -315,9 +315,9 @@ def collapse_rfc2231_value(value, errors='replace', ...@@ -315,9 +315,9 @@ def collapse_rfc2231_value(value, errors='replace',
rawval = unquote(value[2]) rawval = unquote(value[2])
charset = value[0] or 'us-ascii' charset = value[0] or 'us-ascii'
try: try:
return unicode(rawval, charset, errors) return str(rawval, charset, errors)
except LookupError: except LookupError:
# XXX charset is unknown to Python. # XXX charset is unknown to Python.
return unicode(rawval, fallback_charset, errors) return str(rawval, fallback_charset, errors)
else: else:
return unquote(value) return unquote(value)
...@@ -60,7 +60,7 @@ def normalize_encoding(encoding): ...@@ -60,7 +60,7 @@ def normalize_encoding(encoding):
""" """
# Make sure we have an 8-bit string, because .translate() works # Make sure we have an 8-bit string, because .translate() works
# differently for Unicode strings. # differently for Unicode strings.
if isinstance(encoding, unicode): if isinstance(encoding, str):
# Note that .encode('latin-1') does *not* use the codec # Note that .encode('latin-1') does *not* use the codec
# registry, so this call doesn't recurse. (See unicodeobject.c # registry, so this call doesn't recurse. (See unicodeobject.c
# PyUnicode_AsEncodedString() for details) # PyUnicode_AsEncodedString() for details)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -189,7 +189,7 @@ def punycode_decode(text, errors): ...@@ -189,7 +189,7 @@ def punycode_decode(text, errors):
else: else:
base = text[:pos] base = text[:pos]
extended = text[pos+1:] extended = text[pos+1:]
base = unicode(base, "ascii", errors) base = str(base, "ascii", errors)
extended = extended.upper() extended = extended.upper()
return insertion_sort(base, extended, errors) return insertion_sort(base, extended, errors)
......
This diff is collapsed.
...@@ -57,7 +57,7 @@ class IncrementalDecoder(codecs.BufferedIncrementalDecoder): ...@@ -57,7 +57,7 @@ class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
if codecs.BOM_UTF8.startswith(input): if codecs.BOM_UTF8.startswith(input):
# not enough data to decide if this really is a BOM # not enough data to decide if this really is a BOM
# => try again on the next call # => try again on the next call
return (u"", 0) return ("", 0)
else: else:
self.first = 0 self.first = 0
else: else:
...@@ -106,7 +106,7 @@ class StreamReader(codecs.StreamReader): ...@@ -106,7 +106,7 @@ class StreamReader(codecs.StreamReader):
if len(input) < 3 and codecs.BOM_UTF8.startswith(input): if len(input) < 3 and codecs.BOM_UTF8.startswith(input):
# not enough data to decide if this is a BOM # not enough data to decide if this is a BOM
# => try again on the next call # => try again on the next call
return (u"", 0) return ("", 0)
self.decode = codecs.utf_8_decode self.decode = codecs.utf_8_decode
return decode(input, errors) return decode(input, errors)
......
This diff is collapsed.
...@@ -49,8 +49,8 @@ def iglob(pathname): ...@@ -49,8 +49,8 @@ def iglob(pathname):
def glob1(dirname, pattern): def glob1(dirname, pattern):
if not dirname: if not dirname:
dirname = os.curdir dirname = os.curdir
if isinstance(pattern, unicode) and not isinstance(dirname, unicode): if isinstance(pattern, str) and not isinstance(dirname, str):
dirname = unicode(dirname, sys.getfilesystemencoding() or dirname = str(dirname, sys.getfilesystemencoding() or
sys.getdefaultencoding()) sys.getdefaultencoding())
try: try:
names = os.listdir(dirname) names = os.listdir(dirname)
......
...@@ -276,7 +276,7 @@ class EditorWindow(object): ...@@ -276,7 +276,7 @@ class EditorWindow(object):
def _filename_to_unicode(self, filename): def _filename_to_unicode(self, filename):
"""convert filename to unicode in order to display it in Tk""" """convert filename to unicode in order to display it in Tk"""
if isinstance(filename, unicode) or not filename: if isinstance(filename, str) or not filename:
return filename return filename
else: else:
try: try:
......
This diff is collapsed.
...@@ -39,7 +39,7 @@ class OutputWindow(EditorWindow): ...@@ -39,7 +39,7 @@ class OutputWindow(EditorWindow):
# we assume that they are in the locale's encoding # we assume that they are in the locale's encoding
if isinstance(s, str): if isinstance(s, str):
try: try:
s = unicode(s, IOBinding.encoding) s = str(s, IOBinding.encoding)
except UnicodeError: except UnicodeError:
# some other encoding; let Tcl deal with it # some other encoding; let Tcl deal with it
pass pass
......
...@@ -105,7 +105,7 @@ _tran = ''.join(_tran) ...@@ -105,7 +105,7 @@ _tran = ''.join(_tran)
del ch del ch
try: try:
UnicodeType = type(unicode("")) UnicodeType = type(str(""))
except NameError: except NameError:
UnicodeType = None UnicodeType = None
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment