1 # Copyright (C) 2011, Thomas Leonard
2 # See the COPYING file for details, or visit http://0install.net.
4 from xml
.dom
import Node
6 def childNodes(parent
, namespaceURI
= None, localName
= None):
7 for x
in parent
.childNodes
:
8 if x
.nodeType
!= Node
.ELEMENT_NODE
: continue
9 if namespaceURI
is not None and x
.namespaceURI
!= namespaceURI
: continue
11 if localName
is None or x
.localName
== localName
:
15 assert a
.nodeType
== Node
.ELEMENT_NODE
16 assert b
.nodeType
== Node
.ELEMENT_NODE
18 if a
.namespaceURI
!= b
.namespaceURI
:
21 if a
.nodeName
!= b
.nodeName
:
24 a_attrs
= set(["%s %s" % (name
, value
) for name
, value
in a
.attributes
.itemsNS()])
25 b_attrs
= set(["%s %s" % (name
, value
) for name
, value
in b
.attributes
.itemsNS()])
27 if a_attrs
!= b_attrs
:
28 #print "%s != %s" % (a_attrs, b_attrs)
31 a_children
= list(childNodes(a
))
32 b_children
= list(childNodes(b
))
34 if len(a_children
) != len(b_children
):
37 for a_child
, b_child
in zip(a_children
, b_children
):
38 if not nodesEqual(a_child
, b_child
):