1 from htmllib
import HTMLParser
3 from urlparse
import urlparse
4 from formatter
import AbstractFormatter
5 from htmlentitydefs
import entitydefs
6 from xml.sax.saxutils
import quoteattr
9 """Gets rid of < and > and & and, for good measure, :""" 10 return escape(text, quote=
True).replace(
':',
':')
14 HTMLParser.__init__(self, fmt)
21 'li',
'ol',
'ul',
'p',
'cite']
31 {
'a':[
'href',
'title'],
33 'blockquote':[
'type']}
42 if len(ref) < 7
and ref.isdigit():
43 self.
result +=
'&#%s;' % ref
48 self.
result +=
'&%s;' % ref
64 and len(attrs[x]) > 0]
66 if attribute
in [
'href',
'src',
'background']:
68 bt +=
' %s="%s"' % (attribute, attrs[attribute])
71 (
xssescape(attribute), quoteattr(attrs[attribute]))
72 if bt ==
"<a" or bt ==
"<img":
78 self.open_tags.insert(0, tag)
81 bracketed =
"</%s>" % tag
86 self.open_tags.remove(tag)
94 parsed = urlparse(url)
97 """Returns the argument stripped of potentially harmful HTML or Javascript code""" 102 self.
result +=
"</%s>" % endtag
105 """Returns a printable string informing the user which tags are allowed""" 106 self.permitted_tags.sort()
def handle_endtag(self, tag, attrs)
def strip(self, rawstring)
def __init__(self, fmt=AbstractFormatter)
def handle_comment(self, comment)
def handle_entityref(self, ref)
def unknown_endtag(self, tag)
def handle_data(self, data)
def url_is_acceptable(self, url)
def unknown_starttag(self, tag, attributes)
def handle_starttag(self, tag, method, attrs)
def handle_charref(self, ref)