Mercurial > genshi > genshi-test
diff markup/output.py @ 69:e9a3930f8823
A couple of minor performance improvements.
author | cmlenz |
---|---|
date | Mon, 10 Jul 2006 17:37:01 +0000 |
parents | 822089ae65ce |
children | b0fd16111f2e |
line wrap: on
line diff
--- a/markup/output.py +++ b/markup/output.py @@ -20,7 +20,8 @@ except NameError: from sets import ImmutableSet as frozenset -from markup.core import Markup, Namespace, QName, Stream +from markup.core import Markup, Namespace, QName +from markup.core import DOCTYPE, START, END, START_NS, END_NS, TEXT __all__ = ['Serializer', 'XMLSerializer', 'HTMLSerializer'] @@ -54,11 +55,11 @@ stream = _PushbackIterator(stream) for kind, data, pos in stream: - if kind is Stream.DOCTYPE: + if kind is DOCTYPE: # FIXME: what if there's no system or public ID in the input? yield Markup('<!DOCTYPE %s "%s" "%s">\n' % data) - elif kind is Stream.START_NS: + elif kind is START_NS: prefix, uri = data if uri not in ns_mapping: ns_mapping[uri] = prefix @@ -67,7 +68,7 @@ else: ns_attrib.append((QName('xmlns:%s' % prefix), uri)) - elif kind is Stream.START: + elif kind is START: tag, attrib = data tagname = tag.localname @@ -75,10 +76,10 @@ try: prefix = ns_mapping[tag.namespace] if prefix: - tagname = prefix + ':' + tag.localname + tagname = '%s:%s' % (prefix, tag.localname) except KeyError: ns_attrib.append((QName('xmlns'), tag.namespace)) - buf = ['<', tagname] + buf = ['<%s' % tagname] if ns_attrib: attrib.extend(ns_attrib) @@ -88,11 +89,11 @@ if attr.namespace: prefix = ns_mapping.get(attr.namespace) if prefix: - attrname = prefix + ':' + attrname + attrname = '%s:%s' % (prefix, attrname) buf.append(' %s="%s"' % (attrname, Markup.escape(value))) kind, data, pos = stream.next() - if kind is Stream.END: + if kind is END: buf.append('/>') else: buf.append('>') @@ -100,16 +101,16 @@ yield Markup(''.join(buf)) - elif kind is Stream.END: + elif kind is END: tag = data tagname = tag.localname if tag.namespace: prefix = ns_mapping.get(tag.namespace) if prefix: - tagname = prefix + ':' + tag.localname + tagname = '%s:%s' % (prefix, tag.localname) yield Markup('</%s>' % tagname) - elif kind is Stream.TEXT: + elif kind is TEXT: yield Markup.escape(data, quotes=False) @@ -137,15 +138,15 @@ stream = _PushbackIterator(stream) for kind, data, pos in stream: - if kind is Stream.DOCTYPE: + if kind is DOCTYPE: yield Markup('<!DOCTYPE %s "%s" "%s">\n' % data) - elif kind is Stream.START_NS: + elif kind is START_NS: prefix, uri = data if uri not in ns_mapping: ns_mapping[uri] = prefix - elif kind is Stream.START: + elif 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 @@ -162,18 +163,18 @@ if tag.localname in self._EMPTY_ELEMS: kind, data, pos = stream.next() - if kind is not Stream.END: + if kind is not END: stream.pushback((kind, data, pos)) yield Markup(''.join(buf + ['>'])) - elif kind is Stream.END: + elif kind is END: tag = data if tag.namespace and tag not in self.NAMESPACE: continue # not in the HTML namespace, so don't emit yield Markup('</%s>' % tag.localname) - elif kind is Stream.TEXT: + elif kind is TEXT: yield Markup.escape(data, quotes=False)