diff options
author | Daniel Veillard <veillard@redhat.com> | 2010-01-13 15:41:06 +0100 |
---|---|---|
committer | Daniel Veillard <veillard@redhat.com> | 2010-01-13 15:41:06 +0100 |
commit | afa29e64cc836e90957174968a97b0c2b9d2a70f (patch) | |
tree | c4fc21c75e97a32e092e12c25abd234ba8cbc89c /python | |
parent | a1981a0da0201b8da3713aafc1c0656be26e21f0 (diff) | |
download | libxslt-afa29e64cc836e90957174968a97b0c2b9d2a70f.tar.gz libxslt-afa29e64cc836e90957174968a97b0c2b9d2a70f.tar.bz2 libxslt-afa29e64cc836e90957174968a97b0c2b9d2a70f.zip |
Fix python generator to not use deprecated xmllib
* python/generator.py: use xml.sax instead, patch based on similar
fix for libvirt by Cole Robinson <crobinso@redhat.com>
Diffstat (limited to 'python')
-rwxr-xr-x | python/generator.py | 76 |
1 files changed, 13 insertions, 63 deletions
diff --git a/python/generator.py b/python/generator.py index 22691066..797528fe 100755 --- a/python/generator.py +++ b/python/generator.py @@ -15,77 +15,27 @@ import string # ####################################################################### import os -import xmllib -try: - import sgmlop -except ImportError: - sgmlop = None # accelerator not available +import xml.sax debug = 0 -if sgmlop: - class FastParser: - """sgmlop based XML parser. this is typically 15x faster - than SlowParser...""" - - def __init__(self, target): - - # setup callbacks - self.finish_starttag = target.start - self.finish_endtag = target.end - self.handle_data = target.data - - # activate parser - self.parser = sgmlop.XMLParser() - self.parser.register(self) - self.feed = self.parser.feed - self.entity = { - "amp": "&", "gt": ">", "lt": "<", - "apos": "'", "quot": '"' - } - - def close(self): - try: - self.parser.close() - finally: - self.parser = self.feed = None # nuke circular reference - - def handle_entityref(self, entity): - # <string> entity - try: - self.handle_data(self.entity[entity]) - except KeyError: - self.handle_data("&%s;" % entity) - -else: - FastParser = None - - -class SlowParser(xmllib.XMLParser): - """slow but safe standard parser, based on the XML parser in - Python's standard library.""" - - def __init__(self, target): - self.unknown_starttag = target.start - self.handle_data = target.data - self.unknown_endtag = target.end - xmllib.XMLParser.__init__(self) - -def getparser(target = None): - # get the fastest available parser, and attach it to an - # unmarshalling object. return both objects. - if target == None: - target = docParser() - if FastParser: - return FastParser(target), target - return SlowParser(target), target - -class docParser: +def getparser(): + # Attach parser to an unmarshalling object. return both objects. + target = docParser() + parser = xml.sax.make_parser() + parser.setContentHandler(target) + return parser, target + +class docParser(xml.sax.handler.ContentHandler): def __init__(self): self._methodname = None self._data = [] self.in_function = 0 + self.startElement = self.start + self.endElement = self.end + self.characters = self.data + def close(self): if debug: print "close" |