# HG changeset patch # User cmlenz # Date 1154108058 0 # Node ID 230ee6a2c6b2b0fbe926cc2db73e522f089d2864 # Parent 61f58e3a123d851addf7503e143858bdeda5db58 Reorder the conditional branches in the serializers so that the more common event kinds are on top. diff --git a/markup/output.py b/markup/output.py --- a/markup/output.py +++ b/markup/output.py @@ -83,30 +83,7 @@ stream = _PushbackIterator(chain(self.preamble, stream)) for kind, data, pos in stream: - if kind is DOCTYPE: - if not have_doctype: - name, pubid, sysid = data - buf = ['\n') - yield Markup(''.join(buf), *filter(None, data)) - have_doctype = True - - elif kind is START_NS: - prefix, uri = data - if uri not in ns_mapping: - ns_mapping[uri] = prefix - if not prefix: - ns_attrib.append((QName('xmlns'), uri)) - else: - ns_attrib.append((QName('xmlns:%s' % prefix), uri)) - - elif kind is START: + if kind is START: tag, attrib = data tagname = tag.localname @@ -154,6 +131,29 @@ elif kind is COMMENT: yield Markup('' % data) + elif kind is DOCTYPE: + if not have_doctype: + name, pubid, sysid = data + buf = ['\n') + yield Markup(''.join(buf), *filter(None, data)) + have_doctype = True + + elif kind is START_NS: + prefix, uri = data + if uri not in ns_mapping: + ns_mapping[uri] = prefix + if not prefix: + ns_attrib.append((QName('xmlns'), uri)) + else: + ns_attrib.append((QName('xmlns:%s' % prefix), uri)) + elif kind is PI: yield Markup('' % data) @@ -183,26 +183,7 @@ stream = _PushbackIterator(chain(self.preamble, stream)) for kind, data, pos in stream: - if kind is DOCTYPE: - if not have_doctype: - name, pubid, sysid = data - buf = ['\n') - yield Markup(''.join(buf), *filter(None, data)) - have_doctype = True - - elif kind is START_NS: - prefix, uri = data - if uri not in ns_mapping: - ns_mapping[uri] = prefix - - elif kind is START: + if kind is START: tag, attrib = data if tag.namespace and tag not in self.NAMESPACE: continue # not in the HTML namespace, so don't emit @@ -241,6 +222,25 @@ elif kind is COMMENT: yield Markup('' % data) + elif kind is DOCTYPE: + if not have_doctype: + name, pubid, sysid = data + buf = ['\n') + yield Markup(''.join(buf), *filter(None, data)) + have_doctype = True + + elif kind is START_NS: + prefix, uri = data + if uri not in ns_mapping: + ns_mapping[uri] = prefix + elif kind is PI: yield Markup('' % data) @@ -261,26 +261,7 @@ stream = _PushbackIterator(chain(self.preamble, stream)) for kind, data, pos in stream: - if kind is DOCTYPE: - if not have_doctype: - name, pubid, sysid = data - buf = ['\n') - yield Markup(''.join(buf), *filter(None, data)) - have_doctype = True - - elif kind is START_NS: - prefix, uri = data - if uri not in ns_mapping: - ns_mapping[uri] = prefix - - elif kind is START: + if kind is START: tag, attrib = data if tag.namespace and tag not in self.NAMESPACE: continue # not in the HTML namespace, so don't emit @@ -314,6 +295,25 @@ elif kind is COMMENT: yield Markup('' % data) + elif kind is DOCTYPE: + if not have_doctype: + name, pubid, sysid = data + buf = ['\n') + yield Markup(''.join(buf), *filter(None, data)) + have_doctype = True + + elif kind is START_NS: + prefix, uri = data + if uri not in ns_mapping: + ns_mapping[uri] = prefix + elif kind is PI: yield Markup('' % data)