Permalink
Browse files

sort attributes at Element creation time to make their creation order…

… predictable
  • Loading branch information...
1 parent 0458e71 commit e5d7aa3519370a8adb60101441119ad1720b31ed @scoder scoder committed Mar 31, 2012
Showing with 9 additions and 2 deletions.
  1. +7 −0 CHANGES.txt
  2. +1 −1 doc/objectify.txt
  3. +1 −1 src/lxml/apihelpers.pxi
View
7 CHANGES.txt
@@ -40,6 +40,13 @@ Bugs fixed
Other changes
--------------
+* Element attributes passed in as an ``attrib`` dict or as keyword
+ arguments are now sorted by (namespaced) name before being created
+ to make their order predictable for serialisation and iteration.
+ Note that adding or deleting attributes afterwards does not take
+ that order into account, i.e. setting a new attribute appends it
+ after the existing ones.
+
* Several classes that are for internal use only were removed
from the ``lxml.etree`` module dict:
``_InputDocument, _ResolverRegistry, _ResolverContext, _BaseContext,
View
2 doc/objectify.txt
@@ -1122,8 +1122,8 @@ XSI type name:
>>> print(objectify.dump(root))
root = None [ObjectifiedElement]
x = '5' [StringElement]
- * py:pytype = 'str'
* myattr = 'someval'
+ * py:pytype = 'str'
>>> root.x = objectify.DataElement(5, _xsi="integer")
>>> print(objectify.dump(root))
View
2 src/lxml/apihelpers.pxi
@@ -292,7 +292,7 @@ cdef _initNodeAttributes(xmlNode* c_node, _Document doc, attrib, extra):
attrib.update(extra)
if attrib:
is_html = doc._parser._for_html
- for name, value in attrib.items():
+ for name, value in sorted(attrib.items()):
attr_ns_utf, attr_name_utf = _getNsTag(name)
if not is_html:
_attributeValidOrRaise(attr_name_utf)

0 comments on commit e5d7aa3

Please sign in to comment.