diff options
author | Guido van Rossum <guido@python.org> | 2007-05-02 19:09:54 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-05-02 19:09:54 (GMT) |
commit | ef87d6ed94780fe00250a551031023aeb2898365 (patch) | |
tree | 1f8989aaaec7ec5f8b2f26498317f2022bf85531 /Lib/email | |
parent | 572dbf8f1320c0b34b9c786e5c30ba4a4b61b292 (diff) | |
download | cpython-ef87d6ed94780fe00250a551031023aeb2898365.zip cpython-ef87d6ed94780fe00250a551031023aeb2898365.tar.gz cpython-ef87d6ed94780fe00250a551031023aeb2898365.tar.bz2 |
Rip out all the u"..." literals and calls to unicode().
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/charset.py | 12 | ||||
-rw-r--r-- | Lib/email/generator.py | 2 | ||||
-rw-r--r-- | Lib/email/header.py | 10 | ||||
-rw-r--r-- | Lib/email/message.py | 4 | ||||
-rw-r--r-- | Lib/email/test/test_email.py | 20 | ||||
-rw-r--r-- | Lib/email/test/test_email_codecs.py | 4 | ||||
-rw-r--r-- | Lib/email/test/test_email_codecs_renamed.py | 4 | ||||
-rw-r--r-- | Lib/email/test/test_email_renamed.py | 18 | ||||
-rw-r--r-- | Lib/email/utils.py | 6 |
9 files changed, 40 insertions, 40 deletions
diff --git a/Lib/email/charset.py b/Lib/email/charset.py index 9bebf6f..5b5e95d 100644 --- a/Lib/email/charset.py +++ b/Lib/email/charset.py @@ -202,10 +202,10 @@ class Charset: # is already a unicode, we leave it at that, but ensure that the # charset is ASCII, as the standard (RFC XXX) requires. try: - if isinstance(input_charset, unicode): + if isinstance(input_charset, str): input_charset.encode('ascii') else: - input_charset = unicode(input_charset, 'ascii') + input_charset = str(input_charset, 'ascii') except UnicodeError: raise errors.CharsetError(input_charset) input_charset = input_charset.lower() @@ -264,7 +264,7 @@ class Charset: def convert(self, s): """Convert a string from the input_codec to the 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: return s @@ -281,10 +281,10 @@ class Charset: Characters that could not be converted to Unicode will be replaced 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 try: - return unicode(s, self.input_codec, 'replace') + return str(s, self.input_codec, 'replace') except LookupError: # Input codec not installed on system, so return the original # string unchanged. @@ -307,7 +307,7 @@ class Charset: codec = self.output_codec else: codec = self.input_codec - if not isinstance(ustr, unicode) or codec is None: + if not isinstance(ustr, str) or codec is None: return ustr try: return ustr.encode(codec, 'replace') diff --git a/Lib/email/generator.py b/Lib/email/generator.py index 4f3fea4..02b4495 100644 --- a/Lib/email/generator.py +++ b/Lib/email/generator.py @@ -23,7 +23,7 @@ fcre = re.compile(r'^From ', re.MULTILINE) def _is8bitstring(s): if isinstance(s, str): try: - unicode(s, 'us-ascii') + str(s, 'us-ascii') except UnicodeError: return True return False diff --git a/Lib/email/header.py b/Lib/email/header.py index ab0d3fc..675b68d 100644 --- a/Lib/email/header.py +++ b/Lib/email/header.py @@ -21,9 +21,9 @@ from email.charset import Charset NL = '\n' SPACE = ' ' -USPACE = u' ' +USPACE = ' ' SPACE8 = ' ' * 8 -UEMPTYSTRING = u'' +UEMPTYSTRING = '' MAXLINELEN = 76 @@ -210,7 +210,7 @@ class Header: elif nextcs not in (None, 'us-ascii'): uchunks.append(USPACE) lastcs = nextcs - uchunks.append(unicode(s, str(charset))) + uchunks.append(str(s, str(charset))) return UEMPTYSTRING.join(uchunks) # Rich comparison operators for equality only. BAW: does it make sense to @@ -257,13 +257,13 @@ class Header: # Possibly raise UnicodeError if the byte string can't be # converted to a unicode with the input codec of the charset. 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 # byte string with the output codec, which may be different # than the iput coded. Still, use the original byte string. outcodec = charset.output_codec or 'us-ascii' ustr.encode(outcodec, errors) - elif isinstance(s, unicode): + elif isinstance(s, str): # Now we have to be sure the unicode string can be converted # to a byte string with a reasonable output codec. We want to # use the byte string in the chunk. diff --git a/Lib/email/message.py b/Lib/email/message.py index 6fc3af1..1767bfb 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -751,13 +751,13 @@ class Message: # LookupError will be raised if the charset isn't known to # Python. UnicodeError will be raised if the encoded text # 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): charset = charset[2] # charset character must be in us-ascii range try: if isinstance(charset, str): - charset = unicode(charset, 'us-ascii') + charset = str(charset, 'us-ascii') charset = charset.encode('us-ascii') except UnicodeError: return failobj diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index a2e09fa..e1d0eb7 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -505,7 +505,7 @@ class TestMessageAPI(TestEmailBase): msg = Message() msg.set_charset('us-ascii') 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()) @@ -583,7 +583,7 @@ bug demonstration 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. " 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.append(cz_head, cz) h.append(utf8_head, utf8) @@ -1514,7 +1514,7 @@ class TestRFC2047(unittest.TestCase): s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>' dh = decode_header(s) 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>') def test_whitespace_eater_unicode_2(self): @@ -1524,7 +1524,7 @@ class TestRFC2047(unittest.TestCase): eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'), ('jumped over the', None), ('lazy dog', 'iso-8859-1')]) 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): s = 'Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord' @@ -2770,7 +2770,7 @@ class TestCharset(unittest.TestCase): eq('hello w\xf6rld', c.body_encode('hello w\xf6rld')) def test_unicode_charset_name(self): - charset = Charset(u'us-ascii') + charset = Charset('us-ascii') self.assertEqual(str(charset), 'us-ascii') self.assertRaises(Errors.CharsetError, Charset, 'asc\xffii') @@ -2809,7 +2809,7 @@ class TestHeader(TestEmailBase): 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. " 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.append(cz_head, cz) h.append(utf8_head, utf8) @@ -2829,7 +2829,7 @@ class TestHeader(TestEmailBase): eq(decode_header(enc), [(g_head, "iso-8859-1"), (cz_head, "iso-8859-2"), (utf8_head, "utf-8")]) - ustr = unicode(h) + ustr = str(h) eq(ustr.encode('utf-8'), 'Die Mieter treten hier ein werden mit einem Foerderband ' '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 def test_utf8_shortest(self): 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?=') - 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?=') def test_bad_8bit_header(self): @@ -3152,7 +3152,7 @@ Content-Disposition: inline; ''' msg = email.message_from_string(m) 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): m = """\ diff --git a/Lib/email/test/test_email_codecs.py b/Lib/email/test/test_email_codecs.py index 8b97530..1c77347 100644 --- a/Lib/email/test/test_email_codecs.py +++ b/Lib/email/test/test_email_codecs.py @@ -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 # codecs, so we have to skip all these tests. try: - unicode('foo', 'euc-jp') + str('foo', 'euc-jp') except LookupError: raise TestSkipped @@ -57,7 +57,7 @@ Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?= jcode = 'euc-jp' msg = Message() 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)) diff --git a/Lib/email/test/test_email_codecs_renamed.py b/Lib/email/test/test_email_codecs_renamed.py index 10e2065..d190de3 100644 --- a/Lib/email/test/test_email_codecs_renamed.py +++ b/Lib/email/test/test_email_codecs_renamed.py @@ -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 # codecs, so we have to skip all these tests. try: - unicode('foo', 'euc-jp') + str('foo', 'euc-jp') except LookupError: raise TestSkipped @@ -57,7 +57,7 @@ Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?= jcode = 'euc-jp' msg = Message() 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)) diff --git a/Lib/email/test/test_email_renamed.py b/Lib/email/test/test_email_renamed.py index 7f72270..4ce2184 100644 --- a/Lib/email/test/test_email_renamed.py +++ b/Lib/email/test/test_email_renamed.py @@ -564,7 +564,7 @@ bug demonstration 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. " 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.append(cz_head, cz) h.append(utf8_head, utf8) @@ -1512,7 +1512,7 @@ class TestRFC2047(unittest.TestCase): s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>' dh = decode_header(s) 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>') def test_whitespace_eater_unicode_2(self): @@ -1522,7 +1522,7 @@ class TestRFC2047(unittest.TestCase): eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'), ('jumped over the', None), ('lazy dog', 'iso-8859-1')]) 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): s = 'Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord' @@ -2769,7 +2769,7 @@ class TestCharset(unittest.TestCase): eq('hello w\xf6rld', c.body_encode('hello w\xf6rld')) def test_unicode_charset_name(self): - charset = Charset(u'us-ascii') + charset = Charset('us-ascii') self.assertEqual(str(charset), 'us-ascii') self.assertRaises(errors.CharsetError, Charset, 'asc\xffii') @@ -2808,7 +2808,7 @@ class TestHeader(TestEmailBase): 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. " 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.append(cz_head, cz) h.append(utf8_head, utf8) @@ -2828,7 +2828,7 @@ class TestHeader(TestEmailBase): eq(decode_header(enc), [(g_head, "iso-8859-1"), (cz_head, "iso-8859-2"), (utf8_head, "utf-8")]) - ustr = unicode(h) + ustr = str(h) eq(ustr.encode('utf-8'), 'Die Mieter treten hier ein werden mit einem Foerderband ' '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 def test_utf8_shortest(self): 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?=') - 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?=') def test_bad_8bit_header(self): @@ -3151,7 +3151,7 @@ Content-Disposition: inline; ''' msg = email.message_from_string(m) 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): m = """\ diff --git a/Lib/email/utils.py b/Lib/email/utils.py index ee952d3..de9fbf8 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -44,7 +44,7 @@ from email.encoders import _bencode, _qencode COMMASPACE = ', ' EMPTYSTRING = '' -UEMPTYSTRING = u'' +UEMPTYSTRING = '' CRLF = '\r\n' TICK = "'" @@ -315,9 +315,9 @@ def collapse_rfc2231_value(value, errors='replace', rawval = unquote(value[2]) charset = value[0] or 'us-ascii' try: - return unicode(rawval, charset, errors) + return str(rawval, charset, errors) except LookupError: # XXX charset is unknown to Python. - return unicode(rawval, fallback_charset, errors) + return str(rawval, fallback_charset, errors) else: return unquote(value) |