summaryrefslogtreecommitdiffstats
path: root/Lib/xml
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-08-26 01:58:18 (GMT)
committerEli Bendersky <eliben@gmail.com>2013-08-26 01:58:18 (GMT)
commit6206a7e4b0e0184aa3a7f38dd6635e904ebeea8b (patch)
tree8cb6978b5156d9354bffaaebc325c6316007a7cd /Lib/xml
parentd640fe2af5095c8104a7cf850c2a669c8e864215 (diff)
downloadcpython-6206a7e4b0e0184aa3a7f38dd6635e904ebeea8b.zip
cpython-6206a7e4b0e0184aa3a7f38dd6635e904ebeea8b.tar.gz
cpython-6206a7e4b0e0184aa3a7f38dd6635e904ebeea8b.tar.bz2
Remove the obsolete XMLParser._start/_start_list duality.
XMLParser configures expat to report attributes in a list (ordered_attributes), so only _start_list is needed. Rename it to _start and kill _start.
Diffstat (limited to 'Lib/xml')
-rw-r--r--Lib/xml/etree/ElementTree.py38
1 files changed, 12 insertions, 26 deletions
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index 291579b..3e3b09c 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1469,19 +1469,10 @@ class XMLParser:
parser.CommentHandler = target.comment
if hasattr(target, 'pi'):
parser.ProcessingInstructionHandler = target.pi
- # let expat do the buffering, if supported
- try:
- parser.buffer_text = 1
- except AttributeError:
- pass
- # use new-style attribute handling, if supported
- try:
- parser.ordered_attributes = 1
- parser.specified_attributes = 1
- if hasattr(target, 'start'):
- parser.StartElementHandler = self._start_list
- except AttributeError:
- pass
+ # Configure pyexpat: buffering, new-style attribute handling.
+ parser.buffer_text = 1
+ parser.ordered_attributes = 1
+ parser.specified_attributes = 1
self._doctype = None
self.entity = {}
try:
@@ -1503,7 +1494,7 @@ class XMLParser:
parser.ordered_attributes = 1
parser.specified_attributes = 1
def handler(tag, attrib_in, event=event_name, append=append,
- start=self._start_list):
+ start=self._start):
append((event, start(tag, attrib_in)))
parser.StartElementHandler = handler
elif event_name == "end":
@@ -1539,21 +1530,16 @@ class XMLParser:
self._names[key] = name
return name
- def _start(self, tag, attrib_in):
- fixname = self._fixname
- tag = fixname(tag)
- attrib = {}
- for key, value in attrib_in.items():
- attrib[fixname(key)] = value
- return self.target.start(tag, attrib)
-
- def _start_list(self, tag, attrib_in):
+ def _start(self, tag, attr_list):
+ # Handler for expat's StartElementHandler. Since ordered_attributes
+ # is set, the attributes are reported as a list of alternating
+ # attribute name,value.
fixname = self._fixname
tag = fixname(tag)
attrib = {}
- if attrib_in:
- for i in range(0, len(attrib_in), 2):
- attrib[fixname(attrib_in[i])] = attrib_in[i+1]
+ if attr_list:
+ for i in range(0, len(attr_list), 2):
+ attrib[fixname(attr_list[i])] = attr_list[i+1]
return self.target.start(tag, attrib)
def _end(self, tag):