# Path: tornado/escape.py
#             def _json_decode(s):
# def xhtml_escape(value):
# def xhtml_unescape(value):
# def json_encode(value):
# def json_decode(value):
# def squeeze(value):
# def url_escape(value):
#     def url_unescape(value, encoding='utf-8'):
#     def url_unescape(value, encoding='utf-8'):
#     def parse_qs_bytes(qs, keep_blank_values=False, strict_parsing=False):
# def utf8(value):
# def to_unicode(value):
# def to_basestring(value):
# def recursive_unicode(obj):
# def linkify(text, shorten=False, extra_params="",
#             require_protocol=False, permitted_protocols=["http", "https"]):
#     def make_link(m):
# def _convert_entity(m):
# def _build_unicode_map():
# _XHTML_ESCAPE_RE = re.compile('[&<>"]')
# _XHTML_ESCAPE_DICT = {'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;'}
# _UTF8_TYPES = (bytes, type(None))
# _TO_UNICODE_TYPES = (unicode, type(None))
# _BASESTRING_TYPES = (basestring, type(None))
# _URL_RE = re.compile(ur"""\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&amp;|&quot;)*(?:[^!"#$%&'()*+,.:;<=>?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&amp;|&quot;)*\)))+)""")
# _HTML_UNICODE_MAP = _build_unicode_map()
# 
# Path: tornado/testing.py
# class LogTrapTestCase(unittest.TestCase):
#     """A test case that captures and discards all logging output
#     if the test passes.
# 
#     Some libraries can produce a lot of logging output even when
#     the test succeeds, so this class can be useful to minimize the noise.
#     Simply use it as a base class for your test case.  It is safe to combine
#     with AsyncTestCase via multiple inheritance
#     ("class MyTestCase(AsyncHTTPTestCase, LogTrapTestCase):")
# 
#     This class assumes that only one log handler is configured and that
#     it is a StreamHandler.  This is true for both logging.basicConfig
#     and the "pretty logging" configured by tornado.options.
#     """
#     def run(self, result=None):
#         logger = logging.getLogger()
#         if len(logger.handlers) > 1:
#             # Multiple handlers have been defined.  It gets messy to handle
#             # this, especially since the handlers may have different
#             # formatters.  Just leave the logging alone in this case.
#             super(LogTrapTestCase, self).run(result)
#             return
#         if not logger.handlers:
#             logging.basicConfig()
#         self.assertEqual(len(logger.handlers), 1)
#         handler = logger.handlers[0]
#         assert isinstance(handler, logging.StreamHandler)
#         old_stream = handler.stream
#         try:
#             handler.stream = StringIO()
#             logging.info("RUNNING TEST: " + str(self))
#             old_error_count = len(result.failures) + len(result.errors)
#             super(LogTrapTestCase, self).run(result)
#             new_error_count = len(result.failures) + len(result.errors)
#             if new_error_count != old_error_count:
#                 old_stream.write(handler.stream.getvalue())
#         finally:
#             handler.stream = old_stream
# 
# Path: tornado/util.py
# class ObjectDict(dict):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
# def import_object(name):
#     def b(s):
#     def b(s):
# def doctests():


from tornado.escape import utf8, native_str
from tornado.template import Template, DictLoader, ParseError
from tornado.testing import LogTrapTestCase
from tornado.util import b, bytes_type
        # test simulates unicode characters appearing directly in the
        # template file (with utf8 encoding), i.e. \u escapes would not
        # be used in the template file itself.
        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" }}'))
        else:
            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})
        self.assertEqual(loader.load("test.html").generate(), b("6"))

    def test_apply(self):
        def upper(s): return s.upper()
        template = Template(utf8("{% apply upper %}foo{% end %}"))
        self.assertEqual(template.generate(upper=upper), b("FOO"))

    def test_if(self):
        template = Template(utf8("{% if x > 4 %}yes{% else %}no{% end %}"))
        self.assertEqual(template.generate(x=5), b("yes"))
        self.assertEqual(template.generate(x=3), b("no"))

    def test_comment(self):
        template = Template(utf8("{% comment blah blah %}foo"))
        self.assertEqual(template.generate(), b("foo"))



# Path: tornado/escape.py
#             def _json_decode(s):
# def xhtml_escape(value):
# def xhtml_unescape(value):
# def json_encode(value):
# def json_decode(value):
# def squeeze(value):
# def url_escape(value):
#     def url_unescape(value, encoding='utf-8'):
#     def url_unescape(value, encoding='utf-8'):
#     def parse_qs_bytes(qs, keep_blank_values=False, strict_parsing=False):
# def utf8(value):
# def to_unicode(value):
# def to_basestring(value):
# def recursive_unicode(obj):
# def linkify(text, shorten=False, extra_params="",
#             require_protocol=False, permitted_protocols=["http", "https"]):
#     def make_link(m):
# def _convert_entity(m):
# def _build_unicode_map():
# _XHTML_ESCAPE_RE = re.compile('[&<>"]')
# _XHTML_ESCAPE_DICT = {'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;'}
# _UTF8_TYPES = (bytes, type(None))
# _TO_UNICODE_TYPES = (unicode, type(None))
# _BASESTRING_TYPES = (basestring, type(None))
# _URL_RE = re.compile(ur"""\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&amp;|&quot;)*(?:[^!"#$%&'()*+,.:;<=>?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&amp;|&quot;)*\)))+)""")
# _HTML_UNICODE_MAP = _build_unicode_map()
# 
# Path: tornado/testing.py
# class LogTrapTestCase(unittest.TestCase):
#     """A test case that captures and discards all logging output
#     if the test passes.
# 
#     Some libraries can produce a lot of logging output even when
#     the test succeeds, so this class can be useful to minimize the noise.
#     Simply use it as a base class for your test case.  It is safe to combine
#     with AsyncTestCase via multiple inheritance
#     ("class MyTestCase(AsyncHTTPTestCase, LogTrapTestCase):")
# 
#     This class assumes that only one log handler is configured and that
#     it is a StreamHandler.  This is true for both logging.basicConfig
#     and the "pretty logging" configured by tornado.options.
#     """
#     def run(self, result=None):
#         logger = logging.getLogger()
#         if len(logger.handlers) > 1:
#             # Multiple handlers have been defined.  It gets messy to handle
#             # this, especially since the handlers may have different
#             # formatters.  Just leave the logging alone in this case.
#             super(LogTrapTestCase, self).run(result)
#             return
#         if not logger.handlers:
#             logging.basicConfig()
#         self.assertEqual(len(logger.handlers), 1)
#         handler = logger.handlers[0]
#         assert isinstance(handler, logging.StreamHandler)
#         old_stream = handler.stream
#         try:
#             handler.stream = StringIO()
#             logging.info("RUNNING TEST: " + str(self))
#             old_error_count = len(result.failures) + len(result.errors)
#             super(LogTrapTestCase, self).run(result)
#             new_error_count = len(result.failures) + len(result.errors)
#             if new_error_count != old_error_count:
#                 old_stream.write(handler.stream.getvalue())
#         finally:
#             handler.stream = old_stream
# 
# Path: tornado/util.py
# class ObjectDict(dict):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
# def import_object(name):
#     def b(s):
#     def b(s):
# def doctests():


# Path: tornado/test/template_test.py
from tornado.escape import utf8, native_str
from tornado.template import Template, DictLoader, ParseError
from tornado.testing import LogTrapTestCase
from tornado.util import b, bytes_type

        # test simulates unicode characters appearing directly in the
        # template file (with utf8 encoding), i.e. \u escapes would not
        # be used in the template file itself.
        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" }}'))
        else:
            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})
        self.assertEqual(loader.load("test.html").generate(), b("6"))

    def test_apply(self):
        def upper(s): return s.upper()
        template = Template(utf8("{% apply upper %}foo{% end %}"))
        self.assertEqual(template.generate(upper=upper), b("FOO"))

    def test_if(self):
        template = Template(utf8("{% if x > 4 %}yes{% else %}no{% end %}"))
        self.assertEqual(template.generate(x=5), b("yes"))
        self.assertEqual(template.generate(x=3), b("no"))

    def test_comment(self):
        template = Template(utf8("{% comment blah blah %}foo"))
        self.assertEqual(template.generate(), b("foo"))



class AutoEscapeTest(LogTrapTestCase):