]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Replace tornado.web._unicode with tornado.escape._unicode.
authorBen Darnell <ben@bendarnell.com>
Sat, 11 Jun 2011 18:51:19 +0000 (11:51 -0700)
committerBen Darnell <ben@bendarnell.com>
Sat, 11 Jun 2011 18:51:19 +0000 (11:51 -0700)
Add a test case where this matters (when the argument is None)

tornado/test/web_test.py
tornado/web.py

index 39f5acb9a6d9f22ceae42e496d9f55dcf40beae1..f02d31f2c2db9a3cef6eac1c4754754b51309ee4 100644 (file)
@@ -244,6 +244,10 @@ class UIModuleResourceHandler(RequestHandler):
     def get(self):
         self.render("page.html", entries=[1,2])
 
+class OptionalPathHandler(RequestHandler):
+    def get(self, path):
+        self.write({"path": path})
+
 class WebTest(AsyncHTTPTestCase, LogTrapTestCase):
     def get_app(self):
         loader = DictLoader({
@@ -264,11 +268,17 @@ class WebTest(AsyncHTTPTestCase, LogTrapTestCase):
             url("/decode_arg_kw/(?P<arg>.*)", DecodeArgHandler),
             url("/linkify", LinkifyHandler),
             url("/uimodule_resources", UIModuleResourceHandler),
+            url("/optional_path/(.+)?", OptionalPathHandler),
             ]
         return Application(urls,
                            template_loader=loader,
                            autoescape="xhtml_escape")
 
+    def fetch_json(self, *args, **kwargs):
+        response = self.fetch(*args, **kwargs)
+        response.rethrow()
+        return json_decode(response.body)
+
     def test_types(self):
         response = self.fetch("/typecheck/asdf?foo=bar",
                               headers={"Cookie": "cook=ie"})
@@ -329,3 +339,9 @@ js_embed()
 </script>
 <script src="/analytics.js"/>
 </body></html>"""))
+
+    def test_optional_path(self):
+        self.assertEqual(self.fetch_json("/optional_path/foo"),
+                         {u"path": u"foo"})
+        self.assertEqual(self.fetch_json("/optional_path/"),
+                         {u"path": None})
index 6e0d6df5993696553e4f93031836016940a16500..9a46d65b6cc73131cfb08b9d96cb188adbae9860 100644 (file)
@@ -79,7 +79,7 @@ from tornado import escape
 from tornado import locale
 from tornado import stack_context
 from tornado import template
-from tornado.escape import utf8
+from tornado.escape import utf8, _unicode
 from tornado.util import b, bytes_type
 
 try:
@@ -1751,16 +1751,6 @@ class URLSpec(object):
 url = URLSpec
 
 
-def _unicode(s):
-    if isinstance(s, bytes_type):
-        try:
-            return s.decode("utf-8")
-        except UnicodeDecodeError:
-            raise HTTPError(400, "Non-utf8 argument")
-    assert isinstance(s, unicode)
-    return s
-
-
 def _time_independent_equals(a, b):
     if len(a) != len(b):
         return False