/usr/share/pyshared/textile/tools/sanitizer.py is in python-textile 1:2.1.5-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | def sanitize(string, html_type):
"""
>>> sanitize("\\t<p>a paragraph</p>","html")
u'\\t<p>a paragraph</p>'
>>> sanitize("\\t<script>alert('evil script');</script>", "xhtml")
u"\\t<script>alert('evil script');</script>"
"""
try:
import html5lib
from html5lib import sanitizer, serializer, treewalkers, treebuilders
except ImportError:
raise Exception("html5lib not available")
p = html5lib.HTMLParser(tokenizer=sanitizer.HTMLSanitizer)
tree = p.parseFragment(string)
walker = treewalkers.getTreeWalker("simpletree")
stream = walker(tree)
if html_type == 'xhtml':
s = serializer.xhtmlserializer.XHTMLSerializer()
else:
s = serializer.htmlserializer.HTMLSerializer(omit_optional_tags=False,
quote_attr_values=True)
return s.render(stream)
def setup_module(module):
from nose.plugins.skip import SkipTest
try:
import html5lib
except ImportError:
raise SkipTest()
|