Skip to content

Commit

Permalink
Keep track of tags as (uri, ncname) tuples internally
Browse files Browse the repository at this point in the history
  • Loading branch information
filipsalo committed Jun 26, 2020
1 parent c7c1d19 commit c56fdee
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions streamxmlwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ def sorter_factory(attrib_order):
class.
"""
attrib_order = attrib_order.copy()
for tag, names in attrib_order.iteritems():
items = attrib_order.items()
attrib_order = {}
for tag, names in items:
tag = _nssplitname(tag)
attrib_order[tag] = dict([(_nssplitname(name), n)
for (n, name) in enumerate(names)])
for tag, order in attrib_order.iteritems():
Expand Down Expand Up @@ -218,8 +220,8 @@ def start(self, tag, attributes=None, nsmap=None, **kwargs):
cnames = {}

# Write tag name (cname)
tag = _cname(tag, namespaces, cnames)
self.write("<" + tag)
tag = _nssplitname(tag)
self.write("<" + _cname(tag, namespaces, cnames))

# Make cnames for the attributes
if attributes:
Expand Down Expand Up @@ -260,20 +262,20 @@ def end(self, tag=None):
"""
open_tag, namespaces, cnames = self._tags.pop()
if tag is not None:
tag = _cname(tag, namespaces, cnames)
tag = _nssplitname(tag)
if open_tag != tag:
raise XMLSyntaxError("Start and end tag mismatch: %s and /%s."
% (open_tag, tag))
if self._start_tag_open:
if self._abbrev_empty:
self.write(" />")
else:
self.write("></" + open_tag + ">")
self.write("></" + _cname(open_tag, namespaces, cnames) + ">")
self._start_tag_open = False
else:
if self._pretty_print and not self._wrote_data:
self.write("\n" + INDENT * len(self._tags))
self.write("</" + open_tag + ">")
self.write("</" + _cname(open_tag, namespaces, cnames) + ">")
self._wrote_data = False

def start_ns(self, prefix, uri):
Expand Down

0 comments on commit c56fdee

Please sign in to comment.