[Zope-CVS] CVS: Packages/pypes/pypes - expression.py:1.4
Casey Duncan
casey at zope.com
Sat Jan 31 01:09:56 EST 2004
Update of /cvs-repository/Packages/pypes/pypes
In directory cvs.zope.org:/tmp/cvs-serv25525
Modified Files:
expression.py
Log Message:
Add helper function to compare ast nodes
=== Packages/pypes/pypes/expression.py 1.3 => 1.4 ===
--- Packages/pypes/pypes/expression.py:1.3 Sat Jan 31 00:23:30 2004
+++ Packages/pypes/pypes/expression.py Sat Jan 31 01:09:26 2004
@@ -94,6 +94,28 @@
return "Expression('%s')" % self._expr
__repr__ = __str__
+
+def nodesEqual(node1, node2):
+ """Return true if node1 and node2 are equivilant ast nodes. This is
+ a workaround for the fact that ast nodes themselves do not implement
+ comparison
+ """
+ if isinstance(node1, ast.Node) and isinstance(node2, ast.Node):
+ if node1.__class__ is node2.__class__:
+ children1 = node1.getChildren()
+ children2 = node2.getChildren()
+ if isinstance(children1, tuple) and isinstance(children2, tuple):
+ if len(children1) != len(children2):
+ return False
+ for c1, c2 in zip(children1, children2):
+ if not nodesEqual(c1, c2):
+ return False
+ return True
+ else:
+ return children1 == children2
+ else:
+ return False
+ return node1 == node2
def getCallerNamespace():
"""Look up the stack fram and return a dict of the namespace of the code
More information about the Zope-CVS
mailing list