[XML-SIG] Preparing for PyXML 0.8
Fredrik Lundh
fredrik@pythonware.com
Mon, 5 Aug 2002 16:14:26 +0200
uche wrote:
> > The HTMLParser module from the standard library? Or is there another
> > I'm missing?
>
> The std library. 2.1 or later onnly, ya know.
that should be 2.2 and later, right?
note that if you don't use do/start/end handlers, you can support
earlier versions by falling back on SGMLParser:
try:
from HTMLParser import HTMLParser
except ImportError:
from sgmllib import SGMLParser
# hack to use sgmllib's SGMLParser to emulate 2.2's HTMLParser
class HTMLParser(SGMLParser):
# the following only works as long as this class doesn't
# provide any do, start, or end handlers
def unknown_starttag(self, tag, attrs):
self.handle_starttag(tag, attrs)
def unknown_endtag(self, tag):
self.handle_endtag(tag)
# (taken from xmltoys.HTMLTreeBuilder)
</F>