Mercurial > genshi > genshi-test
changeset 109:2de3f9d84a1c
Reorder the conditional branches in the serializers so that the more common event kinds are on top.
author | cmlenz |
---|---|
date | Fri, 28 Jul 2006 17:34:18 +0000 |
parents | 9cf42fb6b21e |
children | 44fbc30d78cd |
files | markup/output.py |
diffstat | 1 files changed, 64 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- 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 = ['<!DOCTYPE %s'] - if pubid: - buf.append(' PUBLIC "%s"') - elif sysid: - buf.append(' SYSTEM') - if sysid: - buf.append(' "%s"') - buf.append('>\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('<!--%s-->' % data) + elif kind is DOCTYPE: + if not have_doctype: + name, pubid, sysid = data + buf = ['<!DOCTYPE %s'] + if pubid: + buf.append(' PUBLIC "%s"') + elif sysid: + buf.append(' SYSTEM') + if sysid: + buf.append(' "%s"') + buf.append('>\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('<?%s %s?>' % 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 = ['<!DOCTYPE %s'] - if pubid: - buf.append(' PUBLIC "%s"') - elif sysid: - buf.append(' SYSTEM') - if sysid: - buf.append(' "%s"') - buf.append('>\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('<!--%s-->' % data) + elif kind is DOCTYPE: + if not have_doctype: + name, pubid, sysid = data + buf = ['<!DOCTYPE %s'] + if pubid: + buf.append(' PUBLIC "%s"') + elif sysid: + buf.append(' SYSTEM') + if sysid: + buf.append(' "%s"') + buf.append('>\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('<?%s %s?>' % 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 = ['<!DOCTYPE %s'] - if pubid: - buf.append(' PUBLIC "%s"') - elif sysid: - buf.append(' SYSTEM') - if sysid: - buf.append(' "%s"') - buf.append('>\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('<!--%s-->' % data) + elif kind is DOCTYPE: + if not have_doctype: + name, pubid, sysid = data + buf = ['<!DOCTYPE %s'] + if pubid: + buf.append(' PUBLIC "%s"') + elif sysid: + buf.append(' SYSTEM') + if sysid: + buf.append(' "%s"') + buf.append('>\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('<?%s %s?>' % data)