Skip to content

Commit

Permalink
sort attributes at Element creation time to make their creation order…
Browse files Browse the repository at this point in the history
… predictable
  • Loading branch information
scoder committed Mar 31, 2012
1 parent 0458e71 commit e5d7aa3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion doc/objectify.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/lxml/apihelpers.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e5d7aa3

Please sign in to comment.