1
#Stolen from _Python Standard Library_, by Fredrik Lundh, chapter 5.
4
import cgi, string, sys
6
class SGMLFilter(sgmllib.SGMLParser):
7
# sgml filter. override start/end to manipulate
10
def __init__(self, outfile=None, infile=None):
11
sgmllib.SGMLParser.__init__(self)
14
self.write = outfile.write
26
def handle_entityref(self, name):
27
self.write("&%s;" % name)
29
def handle_data(self, data):
30
self.write(cgi.escape(data))
32
def unknown_starttag(self, tag, attrs):
33
tag, attrs = self.start(tag, attrs)
36
self.write("<%s>" % tag)
38
self.write("<%s" % tag)
40
self.write(" %s=%s" % (k, repr(v)))
43
def unknown_endtag(self, tag):
46
self.write("</%s>" % tag)
48
def start(self, tag, attrs):
49
return tag, attrs # override