Mercurial > genshi > genshi-test
changeset 160:faea6db52ef1
Attribute order in parsed XML is now preserved.
author | cmlenz |
---|---|
date | Wed, 16 Aug 2006 21:54:49 +0000 |
parents | 03a0cca25cf6 |
children | a25f9fc5787d |
files | ChangeLog markup/input.py markup/tests/input.py markup/tests/output.py |
diffstat | 4 files changed, 16 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -15,7 +15,7 @@ * The XHTML serializer now correctly handles elements in foreign namespaces (such as SVG or MathML). * Fixed relative includes in templates on Windows (ticket #27). - * Output can be encoded using legacy codecs such as ISO-8859-1, any character + * Output can be encoded using legacy codecs such as ISO-8859-1. Any character not representable in the chosen encoding gets replaced by the corresponding XML character reference. * String literals in XPath expressions that contain spaces are now parsed
--- a/markup/input.py +++ b/markup/input.py @@ -68,6 +68,8 @@ parser = expat.ParserCreate('utf-8', '}') parser.buffer_text = True parser.returns_unicode = True + parser.ordered_attributes = True + parser.StartElementHandler = self._handle_start parser.EndElementHandler = self._handle_end parser.CharacterDataHandler = self._handle_data @@ -144,7 +146,7 @@ self.expat.CurrentColumnNumber) def _handle_start(self, tag, attrib): - self._enqueue(START, (QName(tag), Attributes(attrib.items()))) + self._enqueue(START, (QName(tag), Attributes(zip(*[iter(attrib)] * 2)))) def _handle_end(self, tag): self._enqueue(END, QName(tag))
--- a/markup/tests/input.py +++ b/markup/tests/input.py @@ -41,6 +41,17 @@ if sys.version_info[:2] >= (2, 4): self.assertEqual((None, 1, -1), pos) + def test_element_attribute_order(self): + text = '<elem title="baz" id="foo" class="bar" />' + events = list(XMLParser(StringIO(text))) + kind, data, pos = events[0] + self.assertEqual(Stream.START, kind) + tag, attrib = data + self.assertEqual(u'elem', tag) + self.assertEqual((u'title', u'baz'), attrib[0]) + self.assertEqual((u'id', u'foo'), attrib[1]) + self.assertEqual((u'class', u'bar'), attrib[2]) + class HTMLParserTestCase(unittest.TestCase):