mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-11-08 00:24:52 +03:00
python: Remove FastParser from generator.
FastParser uses sgmlop, a non-standard python module meant as a replacement for xmllib (which is deprecated since python 2.0). Fedora doesn't even carry this module, and the generator doesn't have high performance requirements, so just rip the code out. Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
@@ -26,52 +26,9 @@ else:
|
|||||||
#######################################################################
|
#######################################################################
|
||||||
import os
|
import os
|
||||||
import xmllib
|
import xmllib
|
||||||
try:
|
|
||||||
import sgmlop
|
|
||||||
except ImportError:
|
|
||||||
sgmlop = None # accelerator not available
|
|
||||||
|
|
||||||
debug = 0
|
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
|
|
||||||
self.handle_cdata = target.cdata
|
|
||||||
|
|
||||||
# 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):
|
class SlowParser(xmllib.XMLParser):
|
||||||
"""slow but safe standard parser, based on the XML parser in
|
"""slow but safe standard parser, based on the XML parser in
|
||||||
Python's standard library."""
|
Python's standard library."""
|
||||||
@@ -83,13 +40,9 @@ class SlowParser(xmllib.XMLParser):
|
|||||||
self.unknown_endtag = target.end
|
self.unknown_endtag = target.end
|
||||||
xmllib.XMLParser.__init__(self)
|
xmllib.XMLParser.__init__(self)
|
||||||
|
|
||||||
def getparser(target = None):
|
def getparser():
|
||||||
# get the fastest available parser, and attach it to an
|
# Attach parser to an unmarshalling object. return both objects.
|
||||||
# unmarshalling object. return both objects.
|
target = docParser()
|
||||||
if target is None:
|
|
||||||
target = docParser()
|
|
||||||
if FastParser:
|
|
||||||
return FastParser(target), target
|
|
||||||
return SlowParser(target), target
|
return SlowParser(target), target
|
||||||
|
|
||||||
class docParser:
|
class docParser:
|
||||||
|
|||||||
Reference in New Issue
Block a user