changeset 109:230ee6a2c6b2 trunk

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 61f58e3a123d
children 64ff134868c4
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)
 
Copyright (C) 2012-2017 Edgewall Software