#5767: remove sgmlop support from xmlrpclib; the sgmlop parser does not do much validation and is no longer much faster than e.g. the cElementTree XMLParser.
This commit is contained in:
parent
e616c53aec
commit
e6632b47bb
|
@ -526,56 +526,6 @@ try:
|
||||||
except (AttributeError, ImportError):
|
except (AttributeError, ImportError):
|
||||||
FastMarshaller = None
|
FastMarshaller = None
|
||||||
|
|
||||||
#
|
|
||||||
# the SGMLOP parser is about 15x faster than Python's builtin
|
|
||||||
# XML parser. SGMLOP sources can be downloaded from:
|
|
||||||
#
|
|
||||||
# http://www.pythonware.com/products/xml/sgmlop.htm
|
|
||||||
#
|
|
||||||
|
|
||||||
try:
|
|
||||||
import sgmlop
|
|
||||||
if not hasattr(sgmlop, "XMLParser"):
|
|
||||||
raise ImportError
|
|
||||||
except ImportError:
|
|
||||||
SgmlopParser = None # sgmlop accelerator not available
|
|
||||||
else:
|
|
||||||
class SgmlopParser:
|
|
||||||
def __init__(self, target):
|
|
||||||
|
|
||||||
# setup callbacks
|
|
||||||
self.finish_starttag = target.start
|
|
||||||
self.finish_endtag = target.end
|
|
||||||
self.handle_data = target.data
|
|
||||||
self.handle_xml = target.xml
|
|
||||||
|
|
||||||
# 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_proc(self, tag, attr):
|
|
||||||
m = re.search("encoding\s*=\s*['\"]([^\"']+)[\"']", attr)
|
|
||||||
if m:
|
|
||||||
self.handle_xml(m.group(1), 1)
|
|
||||||
|
|
||||||
def handle_entityref(self, entity):
|
|
||||||
# <string> entity
|
|
||||||
try:
|
|
||||||
self.handle_data(self.entity[entity])
|
|
||||||
except KeyError:
|
|
||||||
self.handle_data("&%s;" % entity)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from xml.parsers import expat
|
from xml.parsers import expat
|
||||||
if not hasattr(expat, "ParserCreate"):
|
if not hasattr(expat, "ParserCreate"):
|
||||||
|
@ -584,8 +534,7 @@ except ImportError:
|
||||||
ExpatParser = None # expat not available
|
ExpatParser = None # expat not available
|
||||||
else:
|
else:
|
||||||
class ExpatParser:
|
class ExpatParser:
|
||||||
# fast expat parser for Python 2.0 and later. this is about
|
# fast expat parser for Python 2.0 and later.
|
||||||
# 50% slower than sgmlop, on roundtrip testing
|
|
||||||
def __init__(self, target):
|
def __init__(self, target):
|
||||||
self._parser = parser = expat.ParserCreate(None, None)
|
self._parser = parser = expat.ParserCreate(None, None)
|
||||||
self._target = target
|
self._target = target
|
||||||
|
@ -606,8 +555,7 @@ else:
|
||||||
|
|
||||||
class SlowParser:
|
class SlowParser:
|
||||||
"""Default XML parser (based on xmllib.XMLParser)."""
|
"""Default XML parser (based on xmllib.XMLParser)."""
|
||||||
# this is about 10 times slower than sgmlop, on roundtrip
|
# this is the slowest parser.
|
||||||
# testing.
|
|
||||||
def __init__(self, target):
|
def __init__(self, target):
|
||||||
import xmllib # lazy subclassing (!)
|
import xmllib # lazy subclassing (!)
|
||||||
if xmllib.XMLParser not in SlowParser.__bases__:
|
if xmllib.XMLParser not in SlowParser.__bases__:
|
||||||
|
@ -1069,8 +1017,6 @@ def getparser(use_datetime=0):
|
||||||
target = Unmarshaller(use_datetime=use_datetime)
|
target = Unmarshaller(use_datetime=use_datetime)
|
||||||
if FastParser:
|
if FastParser:
|
||||||
parser = FastParser(target)
|
parser = FastParser(target)
|
||||||
elif SgmlopParser:
|
|
||||||
parser = SgmlopParser(target)
|
|
||||||
elif ExpatParser:
|
elif ExpatParser:
|
||||||
parser = ExpatParser(target)
|
parser = ExpatParser(target)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -317,6 +317,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #5767: Removed sgmlop support from xmlrpclib.
|
||||||
|
|
||||||
- Issue #6131: test_modulefinder leaked when run after test_distutils.
|
- Issue #6131: test_modulefinder leaked when run after test_distutils.
|
||||||
Patch by Hirokazu Yamamoto.
|
Patch by Hirokazu Yamamoto.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue