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({
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"})
</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})
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:
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