Skip to content

Commit

Permalink
Replace tornado.web._unicode with tornado.escape._unicode.
Browse files Browse the repository at this point in the history
Add a test case where this matters (when the argument is None)
  • Loading branch information
bdarnell committed Jun 11, 2011
1 parent 02ce53b commit ca14860
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
16 changes: 16 additions & 0 deletions tornado/test/web_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -264,11 +268,17 @@ def get_app(self):
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"})
Expand Down Expand Up @@ -329,3 +339,9 @@ def test_uimodule_resources(self):
</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})
12 changes: 1 addition & 11 deletions tornado/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get(self):
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:
Expand Down Expand Up @@ -1751,16 +1751,6 @@ def reverse(self, *args):
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
Expand Down

0 comments on commit ca14860

Please sign in to comment.