# HG changeset patch # User cmlenz # Date 1156172435 0 # Node ID dbae9efe57045200371d069be61f72cce185daed # Parent 7efcbf6b1cf243c5aa1876c35834fd4ba6754790 * Minor fix for the XHTML serializer (the local namespace var got clobbered) * Additional unit tests for empty element serialization, and using XHTML as non-default namespace (with a prefix) diff --git a/markup/output.py b/markup/output.py --- a/markup/output.py +++ b/markup/output.py @@ -208,14 +208,14 @@ tag, attrib = data tagname = tag.localname - namespace = tag.namespace - if namespace: - if namespace in ns_mapping: - prefix = ns_mapping[namespace] + tagns = tag.namespace + if tagns: + if tagns in ns_mapping: + prefix = ns_mapping[tagns] if prefix: tagname = '%s:%s' % (prefix, tagname) else: - ns_attrib.append((QName('xmlns'), namespace)) + ns_attrib.append((QName('xmlns'), tagns)) buf = ['<', tagname] for attr, value in attrib + ns_attrib: @@ -231,8 +231,7 @@ buf += [' ', attrname, '="', escape(value), '"'] ns_attrib = [] - if (tag.namespace and tag not in namespace) or \ - tagname in empty_elems: + if (tagns and tagns != namespace) or tagname in empty_elems: kind, data, pos = stream.next() if kind is END: buf += [' />'] @@ -250,7 +249,7 @@ if tag.namespace: prefix = ns_mapping.get(tag.namespace) if prefix: - tagname = '%s:%s' % (prefix, tag.localname) + tagname = '%s:%s' % (prefix, tagname) yield Markup('' % tagname) elif kind is TEXT: diff --git a/markup/tests/output.py b/markup/tests/output.py --- a/markup/tests/output.py +++ b/markup/tests/output.py @@ -94,6 +94,11 @@ output = XML(text).render(XHTMLSerializer) self.assertEqual(text, output) + def test_empty_script(self): + text = '', output) + def test_script_escaping(self): text = """', output) + def test_script_escaping(self): text = '' output = XML(text).render(HTMLSerializer)