[Zope-CVS] CVS: Packages/pypes/pypes - expression.py:1.6 interfaces.py:1.13

Casey Duncan casey at zope.com
Mon Mar 1 01:36:46 EST 2004


Update of /cvs-repository/Packages/pypes/pypes
In directory cvs.zope.org:/tmp/cvs-serv6567

Modified Files:
	expression.py interfaces.py 
Log Message:
Add expression and query engine interfaces
Assert new expression interface and test


=== Packages/pypes/pypes/expression.py 1.5 => 1.6 ===
--- Packages/pypes/pypes/expression.py:1.5	Tue Feb  3 01:46:27 2004
+++ Packages/pypes/pypes/expression.py	Mon Mar  1 01:36:15 2004
@@ -13,16 +13,20 @@
 ##############################################################################
 """Pypes expression parser
 
-$Id:S"""
+$Id$"""
 
 import sys
 import __builtin__
 from sets import Set
 from compiler import parse, ast
 from compiler.pycodegen import ExpressionCodeGenerator
+from zope.interface import implements
+from pypes.interfaces import IExpression
 
 class Expression:
     """Encapsulation of an expression and namespace for later evaluation"""
+    
+    implements(IExpression)
     
     def __init__(self, expr, namespace=None):
         """Create and expression from the string expr, which must be a valid


=== Packages/pypes/pypes/interfaces.py 1.12 => 1.13 ===
--- Packages/pypes/pypes/interfaces.py:1.12	Sat Feb 28 01:02:18 2004
+++ Packages/pypes/pypes/interfaces.py	Mon Mar  1 01:36:15 2004
@@ -579,11 +579,12 @@
     
     def select(expression):
         """Return a derived query with the specified select expression. This
-        expression determines the value for each result returned. If a query
-        has no select expression specified then the value for each
-        result is the object from the single source of the query or a tuple of 
-        objects if there are multiple sources.
-        
+        expression determines the projection from which the value for each
+        result element is derived. If a query has no select expression
+        specified then the value for each result is the object from the single
+        source of the query or a tuple of  objects if there are multiple
+        sources.
+
         Typical usage::
         
           query.select("Animal.name")
@@ -629,5 +630,68 @@
         used to determine the complexity of queries and optimize them or to
         confirm that resources are properly utilized for effiency.
         """
+
+class IExpression(Interface):
+    """Introspectable, executable Python expression"""
+    
+    def names():
+        """Return a list of strings cooresponding to the names referenced in
+        the expression"""
+    
+    def freeOperands(free_names=[]):
+        """Return a list of Python ast node objects that coorespond to
+        operand subexpressions with free variables. Operands are considered
+        free if they reference a name in free_names, or a name not found
+        in bound names or Python builtins
+        """
+        
+    def optimize(free_names=[]):
+        """Optimize the expression by executing subexpressions which do not
+        contain free variables and replacing them with the resulting constant
+        values. Subexpressions referencing only bound names and Python builtins
+        not specified in free_names can be optimized. Boolean operations
+        containing free names can also be optimized out if it their result
+        can be predetermined by operands not referencing free variables,
+        i.e. "and" expressions where one operand optimizes to False.
+        """
+        
+    def __call__(namespace={}):
+        """Execute the expression using the names provided in namespace as
+        locals. Bound variables and builtins are used as globals. Return the
+        result of expression execution
+        """
+
+class IQueryEngine(Interface):
+    """Mechanism for performing the primitive operations on inputs required to
+    execute queries and generate results"""
+    
+    def inputs():
+        """Return the query inputs and names as a sequence of 
+        (name, input) pairs
+        """
+        
+    def rawResults():
+        """Return the current results in raw form cooresponding to the inputs: 
+        a sequence of (input name, result collection) pairs
+        """
+        
+    def results(projection):
+        """Return the current results processed as specified by the 
+        projection expression which is used to derive each result element
+        """
+    
+    def filter(expression):
+        """Mutate the current results using the expression object provided to
+        filter those results for which the expression returns a true value 
+        """
+
+    def sort(expression, order='ascending'):
+        """Sort the current results in place using the expression object
+        provided to derive the sort keys. A sort is a stable operation so that
+        multiple sort passes can be applied during the query to sort by
+        multiple expression simultaneously. order is either 'ascending' or
+        'descending'.
+        """
+    
     
     




More information about the Zope-CVS mailing list