[Zope-CVS] CVS: Packages/pypes/pypes - expression.py:1.18
Casey Duncan
casey at zope.com
Thu Jul 1 23:14:51 EDT 2004
Update of /cvs-repository/Packages/pypes/pypes
In directory cvs.zope.org:/tmp/cvs-serv16938
Modified Files:
expression.py
Log Message:
Add criteria and sort expressions for queries
=== Packages/pypes/pypes/expression.py 1.17 => 1.18 ===
--- Packages/pypes/pypes/expression.py:1.17 Tue May 11 23:58:40 2004
+++ Packages/pypes/pypes/expression.py Thu Jul 1 23:14:21 2004
@@ -23,7 +23,7 @@
from compiler import parse, ast, misc
from compiler.pycodegen import ExpressionCodeGenerator, ModuleCodeGenerator
from zope.interface import implements
-from pypes.interfaces import IExpression
+from pypes.interfaces import IExpression, IOrderExpression
from pypes.exceptions import PypesError
class Expression(object):
@@ -249,6 +249,8 @@
combined if names common between them are assigned the same values
and unbound names in one are not bound by the other.
"""
+ if self._bindings is other._bindings:
+ return self._bindings
self_bound = Set(self._bindings)
other_bound = Set(other._bindings)
for name in other_bound & self_bound:
@@ -279,6 +281,33 @@
return "Expression('%s')" % self._expr
__repr__ = __str__
+
+
+class Criteria(Expression):
+ """Query criteria expression. Automatically binds names from the
+ Python stack frame into the expression
+ """
+
+ def __init__(self, expr, namespace=None):
+ frame_locals = sys._getframe(1).f_locals.copy()
+ if namespace is not None:
+ frame_locals.update(namespace)
+ super(Criteria, self).__init__(expr, frame_locals)
+
+
+class Asc(Criteria):
+ """Ascending order expression"""
+
+ implements(IOrderExpression)
+ order = 1
+
+
+class Desc(Criteria):
+ """Descendng order expression"""
+
+ implements(IOrderExpression)
+ order = -1
+
def nodesEqual(node1, node2):
"""Return true if node1 and node2 are equivilant ast nodes. This is
More information about the Zope-CVS
mailing list