[Zope-CVS] CVS: Packages/pypes/pypes - expression.py:1.19
Casey Duncan
casey at zope.com
Fri Jul 23 01:03:39 EDT 2004
Update of /cvs-repository/Packages/pypes/pypes
In directory cvs.zope.org:/tmp/cvs-serv9532
Modified Files:
expression.py
Log Message:
Add combineOrderExprs() function for use by sort implementation
Make sure order expressions with different order directions never compare equal
Remove uneeded getCallerNamespace() function
=== Packages/pypes/pypes/expression.py 1.18 => 1.19 ===
--- Packages/pypes/pypes/expression.py:1.18 Thu Jul 1 23:14:21 2004
+++ Packages/pypes/pypes/expression.py Fri Jul 23 01:03:09 2004
@@ -300,6 +300,12 @@
implements(IOrderExpression)
order = 1
+
+ def __eq__(self, other):
+ if other.order > 0:
+ return super(Asc, self).__eq__(other)
+ else:
+ return False
class Desc(Criteria):
@@ -307,8 +313,29 @@
implements(IOrderExpression)
order = -1
-
+ def __eq__(self, other):
+ if other.order < 0:
+ return super(Desc, self).__eq__(other)
+ else:
+ return False
+
+
+def combineOrderExprs(*exprs):
+ """Return an order expression which creates a tuple of the values
+ from the input expressions
+ """
+ orderclass = exprs[0].__class__
+ bindings = {}
+ nodes = []
+ for expr in exprs:
+ if expr.__class__ is not orderclass:
+ raise PypesError('cannot combine expressions of different types')
+ bindings.update(expr.bindings())
+ nodes.append(deepcopy(expr.ast().getChildren()[0]))
+ return orderclass.fromAstNode(ast.Tuple(nodes), bindings)
+
+
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
@@ -330,10 +357,3 @@
else:
return False
return node1 == node2
-
-def getCallerNamespace():
- """Look up the stack fram and return a dict of the namespace of the code
- that envoked the caller of getCallerNamespace.
- """
- frame = sys._getframe(2)
- return frame.f_globals.copy(), frame.f_locals.copy()
More information about the Zope-CVS
mailing list