]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Convert all unicode literals to tornado.util.u.
authorBen Darnell <ben@bendarnell.com>
Mon, 14 Jan 2013 00:11:03 +0000 (19:11 -0500)
committerBen Darnell <ben@bendarnell.com>
Mon, 14 Jan 2013 00:11:03 +0000 (19:11 -0500)
Mostly done by the fixer script with manual import updates,
although the raw literal in escape.py needed special handling.

12 files changed:
tornado/auth.py
tornado/escape.py
tornado/locale.py
tornado/test/auth_test.py
tornado/test/escape_test.py
tornado/test/httpclient_test.py
tornado/test/httpserver_test.py
tornado/test/locale_test.py
tornado/test/log_test.py
tornado/test/template_test.py
tornado/test/web_test.py
tornado/test/wsgi_test.py

index 964534fa8b535f745444719e421af5e86f132c88..c472f9339a760ee8fb488d502968e374dfd62812 100644 (file)
@@ -59,7 +59,7 @@ from tornado import httpclient
 from tornado import escape
 from tornado.httputil import url_concat
 from tornado.log import gen_log
-from tornado.util import bytes_type, b
+from tornado.util import bytes_type, b, u
 
 
 class OpenIdMixin(object):
@@ -92,7 +92,7 @@ class OpenIdMixin(object):
         """
         # Verify the OpenID response via direct request to the OP
         args = dict((k, v[-1]) for k, v in self.request.arguments.iteritems())
-        args["openid.mode"] = u"check_authentication"
+        args["openid.mode"] = u("check_authentication")
         url = self._OPENID_ENDPOINT
         if http_client is None:
             http_client = self.get_auth_http_client()
@@ -159,13 +159,13 @@ class OpenIdMixin(object):
         ax_ns = None
         for name in self.request.arguments.iterkeys():
             if name.startswith("openid.ns.") and \
-               self.get_argument(name) == u"http://openid.net/srv/ax/1.0":
+               self.get_argument(name) == u("http://openid.net/srv/ax/1.0"):
                 ax_ns = name[10:]
                 break
 
         def get_ax_arg(uri):
             if not ax_ns:
-                return u""
+                return u("")
             prefix = "openid." + ax_ns + ".type."
             ax_name = None
             for name in self.request.arguments.iterkeys():
@@ -174,8 +174,8 @@ class OpenIdMixin(object):
                     ax_name = "openid." + ax_ns + ".value." + part
                     break
             if not ax_name:
-                return u""
-            return self.get_argument(ax_name, u"")
+                return u("")
+            return self.get_argument(ax_name, u(""))
 
         email = get_ax_arg("http://axschema.org/contact/email")
         name = get_ax_arg("http://axschema.org/namePerson")
@@ -194,7 +194,7 @@ class OpenIdMixin(object):
         if name:
             user["name"] = name
         elif name_parts:
-            user["name"] = u" ".join(name_parts)
+            user["name"] = u(" ").join(name_parts)
         elif email:
             user["name"] = email.split("@")[0]
         if email:
@@ -763,7 +763,7 @@ class GoogleMixin(OpenIdMixin, OAuthMixin):
         oauth_ns = ""
         for name, values in self.request.arguments.iteritems():
             if name.startswith("openid.ns.") and \
-               values[-1] == u"http://specs.openid.net/extensions/oauth/1.0":
+               values[-1] == u("http://specs.openid.net/extensions/oauth/1.0"):
                 oauth_ns = name[10:]
                 break
         token = self.get_argument("openid." + oauth_ns + ".request_token", "")
index ed07c53d186c715c257559b35a7e01b22f1f3742..6833f9f169293d5000ad01d3c92c19204f96f465 100644 (file)
@@ -27,6 +27,8 @@ import re
 import sys
 import urllib
 
+from tornado.util import u
+
 # Python3 compatibility:  On python2.5, introduce the bytes alias from 2.6
 try:
     bytes
@@ -232,7 +234,9 @@ def recursive_unicode(obj):
 # but it gets all exponential on certain patterns (such as too many trailing
 # dots), causing the regex matcher to never return.
 # This regex should avoid those problems.
-_URL_RE = re.compile(ur"""\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&amp;|&quot;)*(?:[^!"#$%&'()*+,.:;<=>?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&amp;|&quot;)*\)))+)""")
+# Use to_unicode instead of tornado.util.u - we don't want backslashes getting
+# processed as escapes.
+_URL_RE = re.compile(to_unicode(r"""\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&amp;|&quot;)*(?:[^!"#$%&'()*+,.:;<=>?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&amp;|&quot;)*\)))+)"""))
 
 
 def linkify(text, shorten=False, extra_params="",
@@ -321,7 +325,7 @@ def linkify(text, shorten=False, extra_params="",
                     # have a status bar, such as Safari by default)
                     params += ' title="%s"' % href
 
-        return u'<a href="%s"%s>%s</a>' % (href, params, url)
+        return u('<a href="%s"%s>%s</a>') % (href, params, url)
 
     # First HTML-escape so that our strings are all safe.
     # The regex is modified to avoid character entites other than &amp; so
index 918f0c415f7aa8a5454d3cc1ea19a62e04410bed..c5d49db653633913b9f4351198c83626969b5f22 100644 (file)
@@ -48,6 +48,7 @@ import re
 
 from tornado import escape
 from tornado.log import gen_log
+from tornado.util import u
 
 _default_locale = "en_US"
 _translations = {}
@@ -84,7 +85,7 @@ def set_default_locale(code):
 
 
 def load_translations(directory):
-    u"""Loads translations from CSV files in a directory.
+    u("""Loads translations from CSV files in a directory.
 
     Translations are strings with optional Python-style named placeholders
     (e.g., "My name is %(name)s") and their associated translations.
@@ -109,7 +110,7 @@ def load_translations(directory):
         "%(name)s liked this","A %(name)s les gust\u00f3 esto","plural"
         "%(name)s liked this","A %(name)s le gust\u00f3 esto","singular"
 
-    """
+    """)
     global _translations
     global _supported_locales
     _translations = {}
@@ -242,7 +243,7 @@ class Locale(object):
 
     def __init__(self, code, translations):
         self.code = code
-        self.name = LOCALE_NAMES.get(code, {}).get("name", u"Unknown")
+        self.name = LOCALE_NAMES.get(code, {}).get("name", u("Unknown"))
         self.rtl = False
         for prefix in ["fa", "ar", "he"]:
             if self.code.startswith(prefix):
@@ -342,7 +343,7 @@ class Locale(object):
             str_time = "%d:%02d" % (local_date.hour, local_date.minute)
         elif self.code == "zh_CN":
             str_time = "%s%d:%02d" % (
-                (u'\u4e0a\u5348', u'\u4e0b\u5348')[local_date.hour >= 12],
+                (u('\u4e0a\u5348'), u('\u4e0b\u5348'))[local_date.hour >= 12],
                 local_date.hour % 12 or 12, local_date.minute)
         else:
             str_time = "%d:%02d %s" % (
@@ -388,7 +389,7 @@ class Locale(object):
             return ""
         if len(parts) == 1:
             return parts[0]
-        comma = u' \u0648 ' if self.code.startswith("fa") else u", "
+        comma = u(' \u0648 ') if self.code.startswith("fa") else u(", ")
         return _("%(commas)s and %(last)s") % {
             "commas": comma.join(parts[:-1]),
             "last": parts[len(parts) - 1],
@@ -444,66 +445,66 @@ class GettextLocale(Locale):
             return self.gettext(message)
 
 LOCALE_NAMES = {
-    "af_ZA": {"name_en": u"Afrikaans", "name": u"Afrikaans"},
-    "am_ET": {"name_en": u"Amharic", "name": u'\u12a0\u121b\u122d\u129b'},
-    "ar_AR": {"name_en": u"Arabic", "name": u"\u0627\u0644\u0639\u0631\u0628\u064a\u0629"},
-    "bg_BG": {"name_en": u"Bulgarian", "name": u"\u0411\u044a\u043b\u0433\u0430\u0440\u0441\u043a\u0438"},
-    "bn_IN": {"name_en": u"Bengali", "name": u"\u09ac\u09be\u0982\u09b2\u09be"},
-    "bs_BA": {"name_en": u"Bosnian", "name": u"Bosanski"},
-    "ca_ES": {"name_en": u"Catalan", "name": u"Catal\xe0"},
-    "cs_CZ": {"name_en": u"Czech", "name": u"\u010ce\u0161tina"},
-    "cy_GB": {"name_en": u"Welsh", "name": u"Cymraeg"},
-    "da_DK": {"name_en": u"Danish", "name": u"Dansk"},
-    "de_DE": {"name_en": u"German", "name": u"Deutsch"},
-    "el_GR": {"name_en": u"Greek", "name": u"\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac"},
-    "en_GB": {"name_en": u"English (UK)", "name": u"English (UK)"},
-    "en_US": {"name_en": u"English (US)", "name": u"English (US)"},
-    "es_ES": {"name_en": u"Spanish (Spain)", "name": u"Espa\xf1ol (Espa\xf1a)"},
-    "es_LA": {"name_en": u"Spanish", "name": u"Espa\xf1ol"},
-    "et_EE": {"name_en": u"Estonian", "name": u"Eesti"},
-    "eu_ES": {"name_en": u"Basque", "name": u"Euskara"},
-    "fa_IR": {"name_en": u"Persian", "name": u"\u0641\u0627\u0631\u0633\u06cc"},
-    "fi_FI": {"name_en": u"Finnish", "name": u"Suomi"},
-    "fr_CA": {"name_en": u"French (Canada)", "name": u"Fran\xe7ais (Canada)"},
-    "fr_FR": {"name_en": u"French", "name": u"Fran\xe7ais"},
-    "ga_IE": {"name_en": u"Irish", "name": u"Gaeilge"},
-    "gl_ES": {"name_en": u"Galician", "name": u"Galego"},
-    "he_IL": {"name_en": u"Hebrew", "name": u"\u05e2\u05d1\u05e8\u05d9\u05ea"},
-    "hi_IN": {"name_en": u"Hindi", "name": u"\u0939\u093f\u0928\u094d\u0926\u0940"},
-    "hr_HR": {"name_en": u"Croatian", "name": u"Hrvatski"},
-    "hu_HU": {"name_en": u"Hungarian", "name": u"Magyar"},
-    "id_ID": {"name_en": u"Indonesian", "name": u"Bahasa Indonesia"},
-    "is_IS": {"name_en": u"Icelandic", "name": u"\xcdslenska"},
-    "it_IT": {"name_en": u"Italian", "name": u"Italiano"},
-    "ja_JP": {"name_en": u"Japanese", "name": u"\u65e5\u672c\u8a9e"},
-    "ko_KR": {"name_en": u"Korean", "name": u"\ud55c\uad6d\uc5b4"},
-    "lt_LT": {"name_en": u"Lithuanian", "name": u"Lietuvi\u0173"},
-    "lv_LV": {"name_en": u"Latvian", "name": u"Latvie\u0161u"},
-    "mk_MK": {"name_en": u"Macedonian", "name": u"\u041c\u0430\u043a\u0435\u0434\u043e\u043d\u0441\u043a\u0438"},
-    "ml_IN": {"name_en": u"Malayalam", "name": u"\u0d2e\u0d32\u0d2f\u0d3e\u0d33\u0d02"},
-    "ms_MY": {"name_en": u"Malay", "name": u"Bahasa Melayu"},
-    "nb_NO": {"name_en": u"Norwegian (bokmal)", "name": u"Norsk (bokm\xe5l)"},
-    "nl_NL": {"name_en": u"Dutch", "name": u"Nederlands"},
-    "nn_NO": {"name_en": u"Norwegian (nynorsk)", "name": u"Norsk (nynorsk)"},
-    "pa_IN": {"name_en": u"Punjabi", "name": u"\u0a2a\u0a70\u0a1c\u0a3e\u0a2c\u0a40"},
-    "pl_PL": {"name_en": u"Polish", "name": u"Polski"},
-    "pt_BR": {"name_en": u"Portuguese (Brazil)", "name": u"Portugu\xeas (Brasil)"},
-    "pt_PT": {"name_en": u"Portuguese (Portugal)", "name": u"Portugu\xeas (Portugal)"},
-    "ro_RO": {"name_en": u"Romanian", "name": u"Rom\xe2n\u0103"},
-    "ru_RU": {"name_en": u"Russian", "name": u"\u0420\u0443\u0441\u0441\u043a\u0438\u0439"},
-    "sk_SK": {"name_en": u"Slovak", "name": u"Sloven\u010dina"},
-    "sl_SI": {"name_en": u"Slovenian", "name": u"Sloven\u0161\u010dina"},
-    "sq_AL": {"name_en": u"Albanian", "name": u"Shqip"},
-    "sr_RS": {"name_en": u"Serbian", "name": u"\u0421\u0440\u043f\u0441\u043a\u0438"},
-    "sv_SE": {"name_en": u"Swedish", "name": u"Svenska"},
-    "sw_KE": {"name_en": u"Swahili", "name": u"Kiswahili"},
-    "ta_IN": {"name_en": u"Tamil", "name": u"\u0ba4\u0bae\u0bbf\u0bb4\u0bcd"},
-    "te_IN": {"name_en": u"Telugu", "name": u"\u0c24\u0c46\u0c32\u0c41\u0c17\u0c41"},
-    "th_TH": {"name_en": u"Thai", "name": u"\u0e20\u0e32\u0e29\u0e32\u0e44\u0e17\u0e22"},
-    "tl_PH": {"name_en": u"Filipino", "name": u"Filipino"},
-    "tr_TR": {"name_en": u"Turkish", "name": u"T\xfcrk\xe7e"},
-    "uk_UA": {"name_en": u"Ukraini ", "name": u"\u0423\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0430"},
-    "vi_VN": {"name_en": u"Vietnamese", "name": u"Ti\u1ebfng Vi\u1ec7t"},
-    "zh_CN": {"name_en": u"Chinese (Simplified)", "name": u"\u4e2d\u6587(\u7b80\u4f53)"},
-    "zh_TW": {"name_en": u"Chinese (Traditional)", "name": u"\u4e2d\u6587(\u7e41\u9ad4)"},
+    "af_ZA": {"name_en": u("Afrikaans"), "name": u("Afrikaans")},
+    "am_ET": {"name_en": u("Amharic"), "name": u('\u12a0\u121b\u122d\u129b')},
+    "ar_AR": {"name_en": u("Arabic"), "name": u("\u0627\u0644\u0639\u0631\u0628\u064a\u0629")},
+    "bg_BG": {"name_en": u("Bulgarian"), "name": u("\u0411\u044a\u043b\u0433\u0430\u0440\u0441\u043a\u0438")},
+    "bn_IN": {"name_en": u("Bengali"), "name": u("\u09ac\u09be\u0982\u09b2\u09be")},
+    "bs_BA": {"name_en": u("Bosnian"), "name": u("Bosanski")},
+    "ca_ES": {"name_en": u("Catalan"), "name": u("Catal\xe0")},
+    "cs_CZ": {"name_en": u("Czech"), "name": u("\u010ce\u0161tina")},
+    "cy_GB": {"name_en": u("Welsh"), "name": u("Cymraeg")},
+    "da_DK": {"name_en": u("Danish"), "name": u("Dansk")},
+    "de_DE": {"name_en": u("German"), "name": u("Deutsch")},
+    "el_GR": {"name_en": u("Greek"), "name": u("\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac")},
+    "en_GB": {"name_en": u("English (UK)"), "name": u("English (UK)")},
+    "en_US": {"name_en": u("English (US)"), "name": u("English (US)")},
+    "es_ES": {"name_en": u("Spanish (Spain)"), "name": u("Espa\xf1ol (Espa\xf1a)")},
+    "es_LA": {"name_en": u("Spanish"), "name": u("Espa\xf1ol")},
+    "et_EE": {"name_en": u("Estonian"), "name": u("Eesti")},
+    "eu_ES": {"name_en": u("Basque"), "name": u("Euskara")},
+    "fa_IR": {"name_en": u("Persian"), "name": u("\u0641\u0627\u0631\u0633\u06cc")},
+    "fi_FI": {"name_en": u("Finnish"), "name": u("Suomi")},
+    "fr_CA": {"name_en": u("French (Canada)"), "name": u("Fran\xe7ais (Canada)")},
+    "fr_FR": {"name_en": u("French"), "name": u("Fran\xe7ais")},
+    "ga_IE": {"name_en": u("Irish"), "name": u("Gaeilge")},
+    "gl_ES": {"name_en": u("Galician"), "name": u("Galego")},
+    "he_IL": {"name_en": u("Hebrew"), "name": u("\u05e2\u05d1\u05e8\u05d9\u05ea")},
+    "hi_IN": {"name_en": u("Hindi"), "name": u("\u0939\u093f\u0928\u094d\u0926\u0940")},
+    "hr_HR": {"name_en": u("Croatian"), "name": u("Hrvatski")},
+    "hu_HU": {"name_en": u("Hungarian"), "name": u("Magyar")},
+    "id_ID": {"name_en": u("Indonesian"), "name": u("Bahasa Indonesia")},
+    "is_IS": {"name_en": u("Icelandic"), "name": u("\xcdslenska")},
+    "it_IT": {"name_en": u("Italian"), "name": u("Italiano")},
+    "ja_JP": {"name_en": u("Japanese"), "name": u("\u65e5\u672c\u8a9e")},
+    "ko_KR": {"name_en": u("Korean"), "name": u("\ud55c\uad6d\uc5b4")},
+    "lt_LT": {"name_en": u("Lithuanian"), "name": u("Lietuvi\u0173")},
+    "lv_LV": {"name_en": u("Latvian"), "name": u("Latvie\u0161u")},
+    "mk_MK": {"name_en": u("Macedonian"), "name": u("\u041c\u0430\u043a\u0435\u0434\u043e\u043d\u0441\u043a\u0438")},
+    "ml_IN": {"name_en": u("Malayalam"), "name": u("\u0d2e\u0d32\u0d2f\u0d3e\u0d33\u0d02")},
+    "ms_MY": {"name_en": u("Malay"), "name": u("Bahasa Melayu")},
+    "nb_NO": {"name_en": u("Norwegian (bokmal)"), "name": u("Norsk (bokm\xe5l)")},
+    "nl_NL": {"name_en": u("Dutch"), "name": u("Nederlands")},
+    "nn_NO": {"name_en": u("Norwegian (nynorsk)"), "name": u("Norsk (nynorsk)")},
+    "pa_IN": {"name_en": u("Punjabi"), "name": u("\u0a2a\u0a70\u0a1c\u0a3e\u0a2c\u0a40")},
+    "pl_PL": {"name_en": u("Polish"), "name": u("Polski")},
+    "pt_BR": {"name_en": u("Portuguese (Brazil)"), "name": u("Portugu\xeas (Brasil)")},
+    "pt_PT": {"name_en": u("Portuguese (Portugal)"), "name": u("Portugu\xeas (Portugal)")},
+    "ro_RO": {"name_en": u("Romanian"), "name": u("Rom\xe2n\u0103")},
+    "ru_RU": {"name_en": u("Russian"), "name": u("\u0420\u0443\u0441\u0441\u043a\u0438\u0439")},
+    "sk_SK": {"name_en": u("Slovak"), "name": u("Sloven\u010dina")},
+    "sl_SI": {"name_en": u("Slovenian"), "name": u("Sloven\u0161\u010dina")},
+    "sq_AL": {"name_en": u("Albanian"), "name": u("Shqip")},
+    "sr_RS": {"name_en": u("Serbian"), "name": u("\u0421\u0440\u043f\u0441\u043a\u0438")},
+    "sv_SE": {"name_en": u("Swedish"), "name": u("Svenska")},
+    "sw_KE": {"name_en": u("Swahili"), "name": u("Kiswahili")},
+    "ta_IN": {"name_en": u("Tamil"), "name": u("\u0ba4\u0bae\u0bbf\u0bb4\u0bcd")},
+    "te_IN": {"name_en": u("Telugu"), "name": u("\u0c24\u0c46\u0c32\u0c41\u0c17\u0c41")},
+    "th_TH": {"name_en": u("Thai"), "name": u("\u0e20\u0e32\u0e29\u0e32\u0e44\u0e17\u0e22")},
+    "tl_PH": {"name_en": u("Filipino"), "name": u("Filipino")},
+    "tr_TR": {"name_en": u("Turkish"), "name": u("T\xfcrk\xe7e")},
+    "uk_UA": {"name_en": u("Ukraini "), "name": u("\u0423\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0430")},
+    "vi_VN": {"name_en": u("Vietnamese"), "name": u("Ti\u1ebfng Vi\u1ec7t")},
+    "zh_CN": {"name_en": u("Chinese (Simplified)"), "name": u("\u4e2d\u6587(\u7b80\u4f53)")},
+    "zh_TW": {"name_en": u("Chinese (Traditional)"), "name": u("\u4e2d\u6587(\u7e41\u9ad4)")},
 }
index 54213986ed0bcf534d02e624d4a9ed58384998bc..d486b4ed1070108be7e49558032d73df22ef032e 100644 (file)
@@ -8,7 +8,7 @@ from __future__ import absolute_import, division, with_statement
 from tornado.auth import OpenIdMixin, OAuthMixin, OAuth2Mixin, TwitterMixin
 from tornado.escape import json_decode
 from tornado.testing import AsyncHTTPTestCase
-from tornado.util import b
+from tornado.util import b, u
 from tornado.web import RequestHandler, Application, asynchronous
 
 
@@ -255,9 +255,9 @@ class AuthTest(AsyncHTTPTestCase):
         response.rethrow()
         parsed = json_decode(response.body)
         self.assertEqual(parsed,
-                         {u'access_token': {u'key': u'hjkl',
-                                            u'screen_name': u'foo',
-                                            u'secret': u'vbnm'},
-                          u'name': u'Foo',
-                          u'screen_name': u'foo',
-                          u'username': u'foo'})
+                         {u('access_token'): {u('key'): u('hjkl'),
+                                            u('screen_name'): u('foo'),
+                                            u('secret'): u('vbnm')},
+                          u('name'): u('Foo'),
+                          u('screen_name'): u('foo'),
+                          u('username'): u('foo')})
index 793e3c8ebe6c0e41c731ecb4a3dd33124a0c39cf..38a8eacc9fcc9dd3770f64fc0327ee08502b1d6a 100644 (file)
@@ -5,130 +5,130 @@ from __future__ import absolute_import, division, with_statement
 import tornado.escape
 
 from tornado.escape import utf8, xhtml_escape, xhtml_unescape, url_escape, url_unescape, to_unicode, json_decode, json_encode
-from tornado.util import b
+from tornado.util import b, u
 from tornado.test.util import unittest
 
 linkify_tests = [
     # (input, linkify_kwargs, expected_output)
 
     ("hello http://world.com/!", {},
-     u'hello <a href="http://world.com/">http://world.com/</a>!'),
+     u('hello <a href="http://world.com/">http://world.com/</a>!')),
 
     ("hello http://world.com/with?param=true&stuff=yes", {},
-     u'hello <a href="http://world.com/with?param=true&amp;stuff=yes">http://world.com/with?param=true&amp;stuff=yes</a>'),
+     u('hello <a href="http://world.com/with?param=true&amp;stuff=yes">http://world.com/with?param=true&amp;stuff=yes</a>')),
 
     # an opened paren followed by many chars killed Gruber's regex
     ("http://url.com/w(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", {},
-     u'<a href="http://url.com/w">http://url.com/w</a>(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
+     u('<a href="http://url.com/w">http://url.com/w</a>(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')),
 
     # as did too many dots at the end
     ("http://url.com/withmany.......................................", {},
-     u'<a href="http://url.com/withmany">http://url.com/withmany</a>.......................................'),
+     u('<a href="http://url.com/withmany">http://url.com/withmany</a>.......................................')),
 
     ("http://url.com/withmany((((((((((((((((((((((((((((((((((a)", {},
-     u'<a href="http://url.com/withmany">http://url.com/withmany</a>((((((((((((((((((((((((((((((((((a)'),
+     u('<a href="http://url.com/withmany">http://url.com/withmany</a>((((((((((((((((((((((((((((((((((a)')),
 
     # some examples from http://daringfireball.net/2009/11/liberal_regex_for_matching_urls
     # plus a fex extras (such as multiple parentheses).
     ("http://foo.com/blah_blah", {},
-     u'<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>'),
+     u('<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>')),
 
     ("http://foo.com/blah_blah/", {},
-     u'<a href="http://foo.com/blah_blah/">http://foo.com/blah_blah/</a>'),
+     u('<a href="http://foo.com/blah_blah/">http://foo.com/blah_blah/</a>')),
 
     ("(Something like http://foo.com/blah_blah)", {},
-     u'(Something like <a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>)'),
+     u('(Something like <a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>)')),
 
     ("http://foo.com/blah_blah_(wikipedia)", {},
-     u'<a href="http://foo.com/blah_blah_(wikipedia)">http://foo.com/blah_blah_(wikipedia)</a>'),
+     u('<a href="http://foo.com/blah_blah_(wikipedia)">http://foo.com/blah_blah_(wikipedia)</a>')),
 
     ("http://foo.com/blah_(blah)_(wikipedia)_blah", {},
-     u'<a href="http://foo.com/blah_(blah)_(wikipedia)_blah">http://foo.com/blah_(blah)_(wikipedia)_blah</a>'),
+     u('<a href="http://foo.com/blah_(blah)_(wikipedia)_blah">http://foo.com/blah_(blah)_(wikipedia)_blah</a>')),
 
     ("(Something like http://foo.com/blah_blah_(wikipedia))", {},
-     u'(Something like <a href="http://foo.com/blah_blah_(wikipedia)">http://foo.com/blah_blah_(wikipedia)</a>)'),
+     u('(Something like <a href="http://foo.com/blah_blah_(wikipedia)">http://foo.com/blah_blah_(wikipedia)</a>)')),
 
     ("http://foo.com/blah_blah.", {},
-     u'<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>.'),
+     u('<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>.')),
 
     ("http://foo.com/blah_blah/.", {},
-     u'<a href="http://foo.com/blah_blah/">http://foo.com/blah_blah/</a>.'),
+     u('<a href="http://foo.com/blah_blah/">http://foo.com/blah_blah/</a>.')),
 
     ("<http://foo.com/blah_blah>", {},
-     u'&lt;<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>&gt;'),
+     u('&lt;<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>&gt;')),
 
     ("<http://foo.com/blah_blah/>", {},
-     u'&lt;<a href="http://foo.com/blah_blah/">http://foo.com/blah_blah/</a>&gt;'),
+     u('&lt;<a href="http://foo.com/blah_blah/">http://foo.com/blah_blah/</a>&gt;')),
 
     ("http://foo.com/blah_blah,", {},
-     u'<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>,'),
+     u('<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>,')),
 
     ("http://www.example.com/wpstyle/?p=364.", {},
-     u'<a href="http://www.example.com/wpstyle/?p=364">http://www.example.com/wpstyle/?p=364</a>.'),
+     u('<a href="http://www.example.com/wpstyle/?p=364">http://www.example.com/wpstyle/?p=364</a>.')),
 
     ("rdar://1234",
      {"permitted_protocols": ["http", "rdar"]},
-     u'<a href="rdar://1234">rdar://1234</a>'),
+     u('<a href="rdar://1234">rdar://1234</a>')),
 
     ("rdar:/1234",
      {"permitted_protocols": ["rdar"]},
-     u'<a href="rdar:/1234">rdar:/1234</a>'),
+     u('<a href="rdar:/1234">rdar:/1234</a>')),
 
     ("http://userid:password@example.com:8080", {},
-     u'<a href="http://userid:password@example.com:8080">http://userid:password@example.com:8080</a>'),
+     u('<a href="http://userid:password@example.com:8080">http://userid:password@example.com:8080</a>')),
 
     ("http://userid@example.com", {},
-     u'<a href="http://userid@example.com">http://userid@example.com</a>'),
+     u('<a href="http://userid@example.com">http://userid@example.com</a>')),
 
     ("http://userid@example.com:8080", {},
-     u'<a href="http://userid@example.com:8080">http://userid@example.com:8080</a>'),
+     u('<a href="http://userid@example.com:8080">http://userid@example.com:8080</a>')),
 
     ("http://userid:password@example.com", {},
-     u'<a href="http://userid:password@example.com">http://userid:password@example.com</a>'),
+     u('<a href="http://userid:password@example.com">http://userid:password@example.com</a>')),
 
     ("message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e",
      {"permitted_protocols": ["http", "message"]},
-     u'<a href="message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e">message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e</a>'),
+     u('<a href="message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e">message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e</a>')),
 
-    (u"http://\u27a1.ws/\u4a39", {},
-     u'<a href="http://\u27a1.ws/\u4a39">http://\u27a1.ws/\u4a39</a>'),
+    (u("http://\u27a1.ws/\u4a39"), {},
+     u('<a href="http://\u27a1.ws/\u4a39">http://\u27a1.ws/\u4a39</a>')),
 
     ("<tag>http://example.com</tag>", {},
-     u'&lt;tag&gt;<a href="http://example.com">http://example.com</a>&lt;/tag&gt;'),
+     u('&lt;tag&gt;<a href="http://example.com">http://example.com</a>&lt;/tag&gt;')),
 
     ("Just a www.example.com link.", {},
-     u'Just a <a href="http://www.example.com">www.example.com</a> link.'),
+     u('Just a <a href="http://www.example.com">www.example.com</a> link.')),
 
     ("Just a www.example.com link.",
      {"require_protocol": True},
-     u'Just a www.example.com link.'),
+     u('Just a www.example.com link.')),
 
     ("A http://reallylong.com/link/that/exceedsthelenglimit.html",
      {"require_protocol": True, "shorten": True},
-     u'A <a href="http://reallylong.com/link/that/exceedsthelenglimit.html" title="http://reallylong.com/link/that/exceedsthelenglimit.html">http://reallylong.com/link...</a>'),
+     u('A <a href="http://reallylong.com/link/that/exceedsthelenglimit.html" title="http://reallylong.com/link/that/exceedsthelenglimit.html">http://reallylong.com/link...</a>')),
 
     ("A http://reallylongdomainnamethatwillbetoolong.com/hi!",
      {"shorten": True},
-     u'A <a href="http://reallylongdomainnamethatwillbetoolong.com/hi" title="http://reallylongdomainnamethatwillbetoolong.com/hi">http://reallylongdomainnametha...</a>!'),
+     u('A <a href="http://reallylongdomainnamethatwillbetoolong.com/hi" title="http://reallylongdomainnamethatwillbetoolong.com/hi">http://reallylongdomainnametha...</a>!')),
 
     ("A file:///passwords.txt and http://web.com link", {},
-     u'A file:///passwords.txt and <a href="http://web.com">http://web.com</a> link'),
+     u('A file:///passwords.txt and <a href="http://web.com">http://web.com</a> link')),
 
     ("A file:///passwords.txt and http://web.com link",
      {"permitted_protocols": ["file"]},
-     u'A <a href="file:///passwords.txt">file:///passwords.txt</a> and http://web.com link'),
+     u('A <a href="file:///passwords.txt">file:///passwords.txt</a> and http://web.com link')),
 
     ("www.external-link.com",
      {"extra_params": 'rel="nofollow" class="external"'},
-     u'<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a>'),
+     u('<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a>')),
 
     ("www.external-link.com and www.internal-link.com/blogs extra",
      {"extra_params": lambda(href):'class="internal"' if href.startswith("http://www.internal-link.com") else 'rel="nofollow" class="external"'},
-     u'<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a> and <a href="http://www.internal-link.com/blogs" class="internal">www.internal-link.com/blogs</a> extra'),
+     u('<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a> and <a href="http://www.internal-link.com/blogs" class="internal">www.internal-link.com/blogs</a> extra')),
 
     ("www.external-link.com",
      {"extra_params": lambda(href):'    rel="nofollow" class="external"  '},
-     u'<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a>'),
+     u('<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a>')),
 ]
 
 
@@ -141,7 +141,7 @@ class EscapeTestCase(unittest.TestCase):
     def test_xhtml_escape(self):
         tests = [
             ("<foo>", "&lt;foo&gt;"),
-            (u"<foo>", u"&lt;foo&gt;"),
+            (u("<foo>"), u("&lt;foo&gt;")),
             (b("<foo>"), b("&lt;foo&gt;")),
 
             ("<>&\"", "&lt;&gt;&amp;&quot;"),
@@ -154,20 +154,20 @@ class EscapeTestCase(unittest.TestCase):
     def test_url_escape(self):
         tests = [
             # byte strings are passed through as-is
-            (u'\u00e9'.encode('utf8'), '%C3%A9'),
-            (u'\u00e9'.encode('latin1'), '%E9'),
+            (u('\u00e9').encode('utf8'), '%C3%A9'),
+            (u('\u00e9').encode('latin1'), '%E9'),
 
             # unicode strings become utf8
-            (u'\u00e9', '%C3%A9'),
+            (u('\u00e9'), '%C3%A9'),
             ]
         for unescaped, escaped in tests:
             self.assertEqual(url_escape(unescaped), escaped)
 
     def test_url_unescape(self):
         tests = [
-            ('%C3%A9', u'\u00e9', 'utf8'),
-            ('%C3%A9', u'\u00c3\u00a9', 'latin1'),
-            ('%C3%A9', utf8(u'\u00e9'), None),
+            ('%C3%A9', u('\u00e9'), 'utf8'),
+            ('%C3%A9', u('\u00c3\u00a9'), 'latin1'),
+            ('%C3%A9', utf8(u('\u00e9')), None),
             ]
         for escaped, unescaped, encoding in tests:
             # input strings to url_unescape should only contain ascii
@@ -180,20 +180,20 @@ class EscapeTestCase(unittest.TestCase):
         # On python2 the escape methods should generally return the same
         # type as their argument
         self.assertEqual(type(xhtml_escape("foo")), str)
-        self.assertEqual(type(xhtml_escape(u"foo")), unicode)
+        self.assertEqual(type(xhtml_escape(u("foo"))), unicode)
 
     def test_json_decode(self):
         # json_decode accepts both bytes and unicode, but strings it returns
         # are always unicode.
-        self.assertEqual(json_decode(b('"foo"')), u"foo")
-        self.assertEqual(json_decode(u'"foo"'), u"foo")
+        self.assertEqual(json_decode(b('"foo"')), u("foo"))
+        self.assertEqual(json_decode(u('"foo"')), u("foo"))
 
         # Non-ascii bytes are interpreted as utf8
-        self.assertEqual(json_decode(utf8(u'"\u00e9"')), u"\u00e9")
+        self.assertEqual(json_decode(utf8(u('"\u00e9"'))), u("\u00e9"))
 
     def test_json_encode(self):
         # json deals with strings, not bytes, but our encoding function should
         # accept bytes as well as long as they are utf8.
-        self.assertEqual(json_decode(json_encode(u"\u00e9")), u"\u00e9")
-        self.assertEqual(json_decode(json_encode(utf8(u"\u00e9"))), u"\u00e9")
+        self.assertEqual(json_decode(json_encode(u("\u00e9"))), u("\u00e9"))
+        self.assertEqual(json_decode(json_encode(utf8(u("\u00e9")))), u("\u00e9"))
         self.assertRaises(UnicodeDecodeError, json_encode, b("\xe9"))
index 4513666c8659e55c6d4a50db7affa61467a3c8f4..22af0b2990a4ef661e5d71553cfa8052d9e19022 100644 (file)
@@ -16,7 +16,7 @@ from tornado import netutil
 from tornado.stack_context import ExceptionStackContext, NullContext
 from tornado.testing import AsyncHTTPTestCase, bind_unused_port
 from tornado.test.util import unittest
-from tornado.util import b, bytes_type
+from tornado.util import b, u, bytes_type
 from tornado.web import Application, RequestHandler, url
 
 
@@ -201,7 +201,7 @@ Transfer-Encoding: chunked
                          response.body)
 
     def test_body_encoding(self):
-        unicode_body = u"\xe9"
+        unicode_body = u("\xe9")
         byte_body = binascii.a2b_hex(b("e9"))
 
         # unicode string in body gets converted to utf8
@@ -221,7 +221,7 @@ Transfer-Encoding: chunked
         # break anything
         response = self.fetch("/echopost", method="POST", body=byte_body,
                               headers={"Content-Type": "application/blah"},
-                              user_agent=u"foo")
+                              user_agent=u("foo"))
         self.assertEqual(response.headers["Content-Length"], "1")
         self.assertEqual(response.body, byte_body)
 
index 9c701a464111333566494b7f906c7fd7307a1bf9..0b1d3dc3a50067a68fd573e0572c3a1d34e99f87 100644 (file)
@@ -11,7 +11,7 @@ from tornado.log import gen_log
 from tornado.simple_httpclient import SimpleAsyncHTTPClient
 from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, ExpectLog
 from tornado.test.util import unittest
-from tornado.util import b, bytes_type
+from tornado.util import b, u, bytes_type
 from tornado.web import Application, RequestHandler, asynchronous
 import datetime
 import os
@@ -206,19 +206,19 @@ class HTTPConnectionTest(AsyncHTTPTestCase):
                                   b("\r\n").join([
                     b("Content-Disposition: form-data; name=argument"),
                     b(""),
-                    u"\u00e1".encode("utf-8"),
+                    u("\u00e1").encode("utf-8"),
                     b("--1234567890"),
-                    u'Content-Disposition: form-data; name="files"; filename="\u00f3"'.encode("utf8"),
+                    u('Content-Disposition: form-data; name="files"; filename="\u00f3"').encode("utf8"),
                     b(""),
-                    u"\u00fa".encode("utf-8"),
+                    u("\u00fa").encode("utf-8"),
                     b("--1234567890--"),
                     b(""),
                     ]))
         data = json_decode(response.body)
-        self.assertEqual(u"\u00e9", data["header"])
-        self.assertEqual(u"\u00e1", data["argument"])
-        self.assertEqual(u"\u00f3", data["filename"])
-        self.assertEqual(u"\u00fa", data["filebody"])
+        self.assertEqual(u("\u00e9"), data["header"])
+        self.assertEqual(u("\u00e1"), data["argument"])
+        self.assertEqual(u("\u00f3"), data["filename"])
+        self.assertEqual(u("\u00fa"), data["filebody"])
 
     def test_100_continue(self):
         # Run through a 100-continue interaction by hand:
@@ -304,12 +304,12 @@ class HTTPServerTest(AsyncHTTPTestCase):
     def test_query_string_encoding(self):
         response = self.fetch("/echo?foo=%C3%A9")
         data = json_decode(response.body)
-        self.assertEqual(data, {u"foo": [u"\u00e9"]})
+        self.assertEqual(data, {u("foo"): [u("\u00e9")]})
 
     def test_empty_query_string(self):
         response = self.fetch("/echo?foo=&foo=")
         data = json_decode(response.body)
-        self.assertEqual(data, {u"foo": [u"", u""]})
+        self.assertEqual(data, {u("foo"): [u(""), u("")]})
 
     def test_types(self):
         headers = {"Cookie": "foo=bar"}
index accb72c95a10497f924e1db79310f90ebb0a3270..f23440c249ea8359855bf3f604c4ae21cd60b011 100644 (file)
@@ -4,7 +4,7 @@ import os
 import tornado.locale
 from tornado.escape import utf8
 from tornado.test.util import unittest
-from tornado.util import b
+from tornado.util import b, u
 
 
 class TranslationLoaderTest(unittest.TestCase):
@@ -31,7 +31,7 @@ class TranslationLoaderTest(unittest.TestCase):
             os.path.join(os.path.dirname(__file__), 'csv_translations'))
         locale = tornado.locale.get("fr_FR")
         self.assertTrue(isinstance(locale, tornado.locale.CSVLocale))
-        self.assertEqual(locale.translate("school"), u"\u00e9cole")
+        self.assertEqual(locale.translate("school"), u("\u00e9cole"))
 
     def test_gettext(self):
         tornado.locale.load_gettext_translations(
@@ -39,12 +39,12 @@ class TranslationLoaderTest(unittest.TestCase):
             "tornado_test")
         locale = tornado.locale.get("fr_FR")
         self.assertTrue(isinstance(locale, tornado.locale.GettextLocale))
-        self.assertEqual(locale.translate("school"), u"\u00e9cole")
+        self.assertEqual(locale.translate("school"), u("\u00e9cole"))
 
 
 class LocaleDataTest(unittest.TestCase):
     def test_non_ascii_name(self):
         name = tornado.locale.LOCALE_NAMES['es_LA']['name']
         self.assertTrue(isinstance(name, unicode))
-        self.assertEqual(name, u'Espa\u00f1ol')
+        self.assertEqual(name, u('Espa\u00f1ol'))
         self.assertEqual(utf8(name), b('Espa\xc3\xb1ol'))
index 1ec354766c5cad6efa57fd3b6ba61bafec3ad9cd..ff75523c763ad0f443c479649b2645660202a485 100644 (file)
@@ -27,7 +27,7 @@ from tornado.escape import utf8
 from tornado.log import LogFormatter, define_logging_options, enable_pretty_logging
 from tornado.options import OptionParser
 from tornado.test.util import unittest
-from tornado.util import b, bytes_type
+from tornado.util import b, u, bytes_type
 
 @contextlib.contextmanager
 def ignore_bytes_warning():
@@ -51,9 +51,9 @@ class LogFormatterTest(unittest.TestCase):
         # for testing.  (testing with color off fails to expose some potential
         # encoding issues from the control characters)
         self.formatter._colors = {
-            logging.ERROR: u"\u0001",
+            logging.ERROR: u("\u0001"),
             }
-        self.formatter._normal = u"\u0002"
+        self.formatter._normal = u("\u0002")
         self.formatter._color = True
         # construct a Logger directly to bypass getLogger's caching
         self.logger = logging.Logger('LogFormatterTest')
@@ -96,16 +96,16 @@ class LogFormatterTest(unittest.TestCase):
             self.assertEqual(self.get_output(), utf8(repr(b("\xe9"))))
 
     def test_utf8_logging(self):
-        self.logger.error(u"\u00e9".encode("utf8"))
+        self.logger.error(u("\u00e9").encode("utf8"))
         if issubclass(bytes_type, basestring):
             # on python 2, utf8 byte strings (and by extension ascii byte
             # strings) are passed through as-is.
-            self.assertEqual(self.get_output(), utf8(u"\u00e9"))
+            self.assertEqual(self.get_output(), utf8(u("\u00e9")))
         else:
             # on python 3, byte strings always get repr'd even if
             # they're ascii-only, so this degenerates into another
             # copy of test_bytes_logging.
-            self.assertEqual(self.get_output(), utf8(repr(utf8(u"\u00e9"))))
+            self.assertEqual(self.get_output(), utf8(repr(utf8(u("\u00e9")))))
 
 
 class UnicodeLogFormatterTest(LogFormatterTest):
@@ -116,8 +116,8 @@ class UnicodeLogFormatterTest(LogFormatterTest):
         return logging.FileHandler(filename, encoding="utf8")
 
     def test_unicode_logging(self):
-        self.logger.error(u"\u00e9")
-        self.assertEqual(self.get_output(), utf8(u"\u00e9"))
+        self.logger.error(u("\u00e9"))
+        self.assertEqual(self.get_output(), utf8(u("\u00e9")))
 
 
 class EnablePrettyLoggingTest(unittest.TestCase):
index 04f5c64a79b0ebfa2021a7bcd0cb58d232d1b1b0..14047e2d7e16f76d2ce41e09175d295e86df744d 100644 (file)
@@ -7,7 +7,7 @@ from tornado.escape import utf8, native_str, to_unicode
 from tornado.template import Template, DictLoader, ParseError, Loader
 from tornado.testing import ExpectLog
 from tornado.test.util import unittest
-from tornado.util import b, bytes_type, ObjectDict
+from tornado.util import b, u, bytes_type, ObjectDict
 
 
 class TemplateTest(unittest.TestCase):
@@ -71,8 +71,8 @@ class TemplateTest(unittest.TestCase):
                          b("expr {{jquery expr}}"))
 
     def test_unicode_template(self):
-        template = Template(utf8(u"\u00e9"))
-        self.assertEqual(template.generate(), utf8(u"\u00e9"))
+        template = Template(utf8(u("\u00e9")))
+        self.assertEqual(template.generate(), utf8(u("\u00e9")))
 
     def test_unicode_literal_expression(self):
         # Unicode literals should be usable in templates.  Note that this
@@ -82,10 +82,10 @@ class TemplateTest(unittest.TestCase):
         if str is unicode:
             # python 3 needs a different version of this test since
             # 2to3 doesn't run on template internals
-            template = Template(utf8(u'{{ "\u00e9" }}'))
+            template = Template(utf8(u('{{ "\u00e9" }}')))
         else:
-            template = Template(utf8(u'{{ u"\u00e9" }}'))
-        self.assertEqual(template.generate(), utf8(u"\u00e9"))
+            template = Template(utf8(u('{{ u"\u00e9" }}')))
+        self.assertEqual(template.generate(), utf8(u("\u00e9")))
 
     def test_custom_namespace(self):
         loader = DictLoader({"test.html": "{{ inc(5) }}"}, namespace={"inc": lambda x: x + 1})
@@ -100,14 +100,14 @@ class TemplateTest(unittest.TestCase):
     def test_unicode_apply(self):
         def upper(s):
             return to_unicode(s).upper()
-        template = Template(utf8(u"{% apply upper %}foo \u00e9{% end %}"))
-        self.assertEqual(template.generate(upper=upper), utf8(u"FOO \u00c9"))
+        template = Template(utf8(u("{% apply upper %}foo \u00e9{% end %}")))
+        self.assertEqual(template.generate(upper=upper), utf8(u("FOO \u00c9")))
 
     def test_bytes_apply(self):
         def upper(s):
             return utf8(to_unicode(s).upper())
-        template = Template(utf8(u"{% apply upper %}foo \u00e9{% end %}"))
-        self.assertEqual(template.generate(upper=upper), utf8(u"FOO \u00c9"))
+        template = Template(utf8(u("{% apply upper %}foo \u00e9{% end %}")))
+        self.assertEqual(template.generate(upper=upper), utf8(u("FOO \u00c9")))
 
     def test_if(self):
         template = Template(utf8("{% if x > 4 %}yes{% else %}no{% end %}"))
@@ -379,4 +379,4 @@ class TemplateLoaderTest(unittest.TestCase):
     def test_utf8_in_file(self):
         tmpl = self.loader.load("utf8.html")
         result = tmpl.generate()
-        self.assertEqual(to_unicode(result).strip(), u"H\u00e9llo")
+        self.assertEqual(to_unicode(result).strip(), u("H\u00e9llo"))
index bf1eb31fff3764fd1644f54659a4ef872738bdc7..cb370296cc0a68ddba74d82d81cc4d3b1ae0b338 100644 (file)
@@ -7,7 +7,7 @@ from tornado.simple_httpclient import SimpleAsyncHTTPClient
 from tornado.template import DictLoader
 from tornado.testing import AsyncHTTPTestCase, ExpectLog
 from tornado.test.util import unittest
-from tornado.util import b, bytes_type, ObjectDict
+from tornado.util import b, u, bytes_type, ObjectDict
 from tornado.web import RequestHandler, authenticated, Application, asynchronous, url, HTTPError, StaticFileHandler, _create_signature, create_signed_value, ErrorHandler
 
 import binascii
@@ -107,7 +107,7 @@ class CookieTest(WebTestCase):
                 # Try setting cookies with different argument types
                 # to ensure that everything gets encoded correctly
                 self.set_cookie("str", "asdf")
-                self.set_cookie("unicode", u"qwer")
+                self.set_cookie("unicode", u("qwer"))
                 self.set_cookie("bytes", b("zxcv"))
 
         class GetCookieHandler(RequestHandler):
@@ -118,8 +118,8 @@ class CookieTest(WebTestCase):
             def get(self):
                 # unicode domain and path arguments shouldn't break things
                 # either (see bug #285)
-                self.set_cookie("unicode_args", "blah", domain=u"foo.com",
-                                path=u"/foo")
+                self.set_cookie("unicode_args", "blah", domain=u("foo.com"),
+                                path=u("/foo"))
 
         class SetCookieSpecialCharHandler(RequestHandler):
             def get(self):
@@ -308,9 +308,9 @@ class RequestEncodingTest(WebTestCase):
     def test_group_encoding(self):
         # Path components and query arguments should be decoded the same way
         self.assertEqual(self.fetch_json('/group/%C3%A9?arg=%C3%A9'),
-                         {u"path": u"/group/%C3%A9",
-                          u"path_args": [u"\u00e9"],
-                          u"args": {u"arg": [u"\u00e9"]}})
+                         {u("path"): u("/group/%C3%A9"),
+                          u("path_args"): [u("\u00e9")],
+                          u("args"): {u("arg"): [u("\u00e9")]}})
 
     def test_slashes(self):
         # Slashes may be escaped to appear as a single "directory" in the path,
@@ -535,15 +535,15 @@ class WSGISafeWebTest(WebTestCase):
             response = self.fetch(url)
             response.rethrow()
             data = json_decode(response.body)
-            self.assertEqual(data, {u'path': [u'unicode', u'\u00e9'],
-                                    u'query': [u'unicode', u'\u00e9'],
+            self.assertEqual(data, {u('path'): [u('unicode'), u('\u00e9')],
+                                    u('query'): [u('unicode'), u('\u00e9')],
                                     })
 
         response = self.fetch("/decode_arg/%C3%A9?foo=%C3%A9")
         response.rethrow()
         data = json_decode(response.body)
-        self.assertEqual(data, {u'path': [u'bytes', u'c3a9'],
-                                u'query': [u'bytes', u'c3a9'],
+        self.assertEqual(data, {u('path'): [u('bytes'), u('c3a9')],
+                                u('query'): [u('bytes'), u('c3a9')],
                                 })
 
     def test_reverse_url(self):
@@ -553,7 +553,7 @@ class WSGISafeWebTest(WebTestCase):
                          '/decode_arg/42')
         self.assertEqual(self.app.reverse_url('decode_arg', b('\xe9')),
                          '/decode_arg/%E9')
-        self.assertEqual(self.app.reverse_url('decode_arg', u'\u00e9'),
+        self.assertEqual(self.app.reverse_url('decode_arg', u('\u00e9')),
                          '/decode_arg/%C3%A9')
 
     def test_uimodule_unescaped(self):
@@ -588,9 +588,9 @@ js_embed()
 
     def test_optional_path(self):
         self.assertEqual(self.fetch_json("/optional_path/foo"),
-                         {u"path": u"foo"})
+                         {u("path"): u("foo")})
         self.assertEqual(self.fetch_json("/optional_path/"),
-                         {u"path": None})
+                         {u("path"): None})
 
     def test_multi_header(self):
         response = self.fetch("/multi_header")
@@ -894,7 +894,7 @@ class NamedURLSpecGroupsTest(WebTestCase):
                 self.write(path)
 
         return [("/str/(?P<path>.*)", EchoHandler),
-                (u"/unicode/(?P<path>.*)", EchoHandler)]
+                (u("/unicode/(?P<path>.*)"), EchoHandler)]
 
     def test_named_urlspec_groups(self):
         response = self.fetch("/str/foo")
index c327ba4d1858112bd4b1f90df9b80b1f4e56563f..1d832adf5acd8f096efdce26fa52e005b25a00e7 100644 (file)
@@ -4,7 +4,7 @@ from wsgiref.validate import validator
 from tornado.escape import json_decode
 from tornado.test.httpserver_test import TypeCheckHandler
 from tornado.testing import AsyncHTTPTestCase
-from tornado.util import b
+from tornado.util import b, u
 from tornado.web import RequestHandler
 from tornado.wsgi import WSGIApplication, WSGIContainer
 
@@ -50,7 +50,7 @@ class WSGIApplicationTest(AsyncHTTPTestCase):
 
     def test_path_quoting(self):
         response = self.fetch("/path/foo%20bar%C3%A9")
-        self.assertEqual(response.body, u"foo bar\u00e9".encode("utf-8"))
+        self.assertEqual(response.body, u("foo bar\u00e9").encode("utf-8"))
 
     def test_types(self):
         headers = {"Cookie": "foo=bar"}