# Path: tornado/util.py
# def b(s):
#     return s.encode('latin1')
# 
# Path: tornado/test/util.py



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.test.util import unittest
     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'),

    ("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>'),

    ("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'),

    ("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>'),
]


class EscapeTestCase(unittest.TestCase):
    def test_linkify(self):
        for text, kwargs, html in linkify_tests:
            linked = tornado.escape.linkify(text, **kwargs)
            self.assertEqual(linked, html)

    def test_xhtml_escape(self):
        tests = [
            ("<foo>", "&lt;foo&gt;"),
            (u"<foo>", u"&lt;foo&gt;"),

# Path: tornado/util.py
# def b(s):
#     return s.encode('latin1')
# 
# Path: tornado/test/util.py



# Path: tornado/test/escape_test.py
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.test.util import unittest

     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'),

    ("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>'),

    ("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'),

    ("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>'),
]


class EscapeTestCase(unittest.TestCase):
    def test_linkify(self):
        for text, kwargs, html in linkify_tests:
            linked = tornado.escape.linkify(text, **kwargs)
            self.assertEqual(linked, html)

    def test_xhtml_escape(self):
        tests = [
            ("<foo>", "&lt;foo&gt;"),
            (u"<foo>", u"&lt;foo&gt;"),

            (b("<foo>"), b("&lt;foo&gt;")),