Python tornado.escape.xhtml_unescape() Examples

The following are 11 code examples of tornado.escape.xhtml_unescape(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tornado.escape , or try the search function .
Example #1
Source File: escape_test.py    From tornado-zh with MIT License 5 votes vote down vote up
def test_xhtml_escape(self):
        tests = [
            ("<foo>", "&lt;foo&gt;"),
            (u("<foo>"), u("&lt;foo&gt;")),
            (b"<foo>", b"&lt;foo&gt;"),

            ("<>&\"'", "&lt;&gt;&amp;&quot;&#39;"),
            ("&amp;", "&amp;amp;"),

            (u("<\u00e9>"), u("&lt;\u00e9&gt;")),
            (b"<\xc3\xa9>", b"&lt;\xc3\xa9&gt;"),
        ]
        for unescaped, escaped in tests:
            self.assertEqual(utf8(xhtml_escape(unescaped)), utf8(escaped))
            self.assertEqual(utf8(unescaped), utf8(xhtml_unescape(escaped))) 
Example #2
Source File: escape_test.py    From tornado-zh with MIT License 5 votes vote down vote up
def test_xhtml_unescape_numeric(self):
        tests = [
            ('foo&#32;bar', 'foo bar'),
            ('foo&#x20;bar', 'foo bar'),
            ('foo&#X20;bar', 'foo bar'),
            ('foo&#xabc;bar', u('foo\u0abcbar')),
            ('foo&#xyz;bar', 'foo&#xyz;bar'),  # invalid encoding
            ('foo&#;bar', 'foo&#;bar'),        # invalid encoding
            ('foo&#x;bar', 'foo&#x;bar'),      # invalid encoding
        ]
        for escaped, unescaped in tests:
            self.assertEqual(unescaped, xhtml_unescape(escaped)) 
Example #3
Source File: escape_test.py    From tornado-zh with MIT License 5 votes vote down vote up
def test_xhtml_escape(self):
        tests = [
            ("<foo>", "&lt;foo&gt;"),
            (u("<foo>"), u("&lt;foo&gt;")),
            (b"<foo>", b"&lt;foo&gt;"),

            ("<>&\"'", "&lt;&gt;&amp;&quot;&#39;"),
            ("&amp;", "&amp;amp;"),

            (u("<\u00e9>"), u("&lt;\u00e9&gt;")),
            (b"<\xc3\xa9>", b"&lt;\xc3\xa9&gt;"),
        ]
        for unescaped, escaped in tests:
            self.assertEqual(utf8(xhtml_escape(unescaped)), utf8(escaped))
            self.assertEqual(utf8(unescaped), utf8(xhtml_unescape(escaped))) 
Example #4
Source File: escape_test.py    From tornado-zh with MIT License 5 votes vote down vote up
def test_xhtml_unescape_numeric(self):
        tests = [
            ('foo&#32;bar', 'foo bar'),
            ('foo&#x20;bar', 'foo bar'),
            ('foo&#X20;bar', 'foo bar'),
            ('foo&#xabc;bar', u('foo\u0abcbar')),
            ('foo&#xyz;bar', 'foo&#xyz;bar'),  # invalid encoding
            ('foo&#;bar', 'foo&#;bar'),        # invalid encoding
            ('foo&#x;bar', 'foo&#x;bar'),      # invalid encoding
        ]
        for escaped, unescaped in tests:
            self.assertEqual(unescaped, xhtml_unescape(escaped)) 
Example #5
Source File: parse_cases.py    From viewfinder with Apache License 2.0 5 votes vote down vote up
def parse_cases(filename):
  """Parses the fogbugz data in the file.

  Returns a list of (subject, assigned_to, body) tuples.
  """
  results = []

  tree = ElementTree.parse(filename)

  for case in tree.find('cases').findall('case'):
    subject = 'FB%s: %s' % (case.get('ixBug'), case.findtext('sTitle'))
    body = []
    assigned_to = case.findtext('sPersonAssignedTo')
    body.append('Assigned to: %s' % assigned_to)
    body.append('Project: %s' % case.findtext('sProject'))
    body.append('Area: %s' % case.findtext('sArea'))
    body.append('Priority: %s (%s)' % (case.findtext('ixPriority'), case.findtext('sPriority')))
    body.append('Category: %s' % case.findtext('sCategory'))
    body.append('')
    for event in case.find('events').findall('event'):
      body.append( '%s at %s' % (event.findtext('evtDescription'), event.findtext('dt')))
      if event.findtext('s'):
        body.append('')
        body.append(event.findtext('s'))
        body.append('')
      if event.find('rgAttachments') is not None:
        for attachment in event.find('rgAttachments').findall('attachment'):
          body.append('Attachment: %s' % escape.xhtml_unescape(attachment.findtext('sURL')))
    results.append((subject, USER_MAP[assigned_to], '\n'.join(body)))
  return results 
Example #6
Source File: escape_test.py    From viewfinder with Apache License 2.0 5 votes vote down vote up
def test_xhtml_escape(self):
        tests = [
            ("<foo>", "&lt;foo&gt;"),
            (u("<foo>"), u("&lt;foo&gt;")),
            (b"<foo>", b"&lt;foo&gt;"),

            ("<>&\"'", "&lt;&gt;&amp;&quot;&#39;"),
            ("&amp;", "&amp;amp;"),

            (u("<\u00e9>"), u("&lt;\u00e9&gt;")),
            (b"<\xc3\xa9>", b"&lt;\xc3\xa9&gt;"),
        ]
        for unescaped, escaped in tests:
            self.assertEqual(utf8(xhtml_escape(unescaped)), utf8(escaped))
            self.assertEqual(utf8(unescaped), utf8(xhtml_unescape(escaped))) 
Example #7
Source File: parse_cases.py    From viewfinder with Apache License 2.0 5 votes vote down vote up
def parse_cases(filename):
  """Parses the fogbugz data in the file.

  Returns a list of (subject, assigned_to, body) tuples.
  """
  results = []

  tree = ElementTree.parse(filename)

  for case in tree.find('cases').findall('case'):
    subject = 'FB%s: %s' % (case.get('ixBug'), case.findtext('sTitle'))
    body = []
    assigned_to = case.findtext('sPersonAssignedTo')
    body.append('Assigned to: %s' % assigned_to)
    body.append('Project: %s' % case.findtext('sProject'))
    body.append('Area: %s' % case.findtext('sArea'))
    body.append('Priority: %s (%s)' % (case.findtext('ixPriority'), case.findtext('sPriority')))
    body.append('Category: %s' % case.findtext('sCategory'))
    body.append('')
    for event in case.find('events').findall('event'):
      body.append( '%s at %s' % (event.findtext('evtDescription'), event.findtext('dt')))
      if event.findtext('s'):
        body.append('')
        body.append(event.findtext('s'))
        body.append('')
      if event.find('rgAttachments') is not None:
        for attachment in event.find('rgAttachments').findall('attachment'):
          body.append('Attachment: %s' % escape.xhtml_unescape(attachment.findtext('sURL')))
    results.append((subject, USER_MAP[assigned_to], '\n'.join(body)))
  return results 
Example #8
Source File: escape_test.py    From viewfinder with Apache License 2.0 5 votes vote down vote up
def test_xhtml_escape(self):
        tests = [
            ("<foo>", "&lt;foo&gt;"),
            (u("<foo>"), u("&lt;foo&gt;")),
            (b"<foo>", b"&lt;foo&gt;"),

            ("<>&\"'", "&lt;&gt;&amp;&quot;&#39;"),
            ("&amp;", "&amp;amp;"),

            (u("<\u00e9>"), u("&lt;\u00e9&gt;")),
            (b"<\xc3\xa9>", b"&lt;\xc3\xa9&gt;"),
        ]
        for unescaped, escaped in tests:
            self.assertEqual(utf8(xhtml_escape(unescaped)), utf8(escaped))
            self.assertEqual(utf8(unescaped), utf8(xhtml_unescape(escaped))) 
Example #9
Source File: escape_test.py    From honeything with GNU General Public License v3.0 5 votes vote down vote up
def test_xhtml_escape(self):
        tests = [
            ("<foo>", "&lt;foo&gt;"),
            (u"<foo>", u"&lt;foo&gt;"),
            (b("<foo>"), b("&lt;foo&gt;")),

            ("<>&\"", "&lt;&gt;&amp;&quot;"),
            ("&amp;", "&amp;amp;"),
            ]
        for unescaped, escaped in tests:
            self.assertEqual(utf8(xhtml_escape(unescaped)), utf8(escaped))
            self.assertEqual(utf8(unescaped), utf8(xhtml_unescape(escaped))) 
Example #10
Source File: escape_test.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def test_xhtml_escape(self):
        tests = [
            ("<foo>", "&lt;foo&gt;"),
            (u("<foo>"), u("&lt;foo&gt;")),
            (b"<foo>", b"&lt;foo&gt;"),

            ("<>&\"'", "&lt;&gt;&amp;&quot;&#39;"),
            ("&amp;", "&amp;amp;"),

            (u("<\u00e9>"), u("&lt;\u00e9&gt;")),
            (b"<\xc3\xa9>", b"&lt;\xc3\xa9&gt;"),
        ]
        for unescaped, escaped in tests:
            self.assertEqual(utf8(xhtml_escape(unescaped)), utf8(escaped))
            self.assertEqual(utf8(unescaped), utf8(xhtml_unescape(escaped))) 
Example #11
Source File: escape_test.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def test_xhtml_unescape_numeric(self):
        tests = [
            ('foo&#32;bar', 'foo bar'),
            ('foo&#x20;bar', 'foo bar'),
            ('foo&#X20;bar', 'foo bar'),
            ('foo&#xabc;bar', u('foo\u0abcbar')),
            ('foo&#xyz;bar', 'foo&#xyz;bar'),  # invalid encoding
            ('foo&#;bar', 'foo&#;bar'),        # invalid encoding
            ('foo&#x;bar', 'foo&#x;bar'),      # invalid encoding
        ]
        for escaped, unescaped in tests:
            self.assertEqual(unescaped, xhtml_unescape(escaped))