[Zope-CVS] CVS: Packages/pypes/pypes - interfaces.py:1.28

Casey Duncan casey at zope.com
Thu Jul 1 23:19:57 EDT 2004


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

Modified Files:
	interfaces.py 
Log Message:
Finalize query interfaces


=== Packages/pypes/pypes/interfaces.py 1.27 => 1.28 ===
--- Packages/pypes/pypes/interfaces.py:1.27	Thu Jun 17 00:44:53 2004
+++ Packages/pypes/pypes/interfaces.py	Thu Jul  1 23:19:56 2004
@@ -490,7 +490,7 @@
     expressions.
     """
     
-    def __call__(inputs, criteria=None, order=None, limit=None):
+    def __call__(inputs=None, criteria=None, order=None, limit=None):
         """Create and return an IQuery object. Argument values override
         defaults provided by the query class (if any).Query classes that 
         supply defaults for  all the necessary arguments can be constructed
@@ -513,7 +513,7 @@
         specifying order.
 
         Missing mandatory or inappropriate argument values should fail early
-        and raise an appropriate PypesQueryError.
+        and raise an appropriate QueryError.
         """
 
 class IQuery(Interface):
@@ -533,23 +533,21 @@
     more IExpression objects.
     """
     
-    def inputMap():
-        """Return a dict containing the input names and input objects for its
-        respective keys and values.
-        """
-    
-    def criteriaExpr():
-        """Return the IExpression object used as the query criteria"""
-        
-    def orderExprs():
-        """Return a sequence of IOrderExpression objects that determine the
-        result order
-        """
-        
-    def lengthLimit():
-        """Return the integer result length limit for the query or None if
-        all should be returned
-        """
+    inputs = Attribute('inputs',
+        """Dict containing the input names and input objects for its
+        respective keys and values.""")
+    
+    criteria = Attribute('criteria',
+        """The IExpression object used as the query criteria or None
+        if there is no criteria""")
+        
+    order = Attribute('order',
+        """Sequence of IOrderExpression objects that determine the
+        result order or None if the query is unordered""")
+        
+    limit = Attribute('limit',
+        """The integer result length limit for the query or None if
+        all should be returned""")
     
     def select(*input_names):
         """Execute the query and return the results as an IQueryResult.
@@ -558,7 +556,7 @@
         specified, then all inputs are returned in the results. Note that
         the order of the output names is arbitrary if the inputs were defined
         using an unordered mapping, such as a dictionary. If a name
-        not cooresponding to an input is specifed, raise PypesQueryError.
+        not cooresponding to an input is specifed, raise QueryError.
         
         If one input is selected, then the result items are simply the objects
         matched by the query. If multiple inputs are selected, then the result
@@ -578,26 +576,16 @@
            for species, habitat in query.select("Species", "Habitat"):
                ...
         """
-
-    def resultSet(input_name):
-        """Execute the query and return an ISet object containing the
-        objects from input_name that were selected by the criteria. This
-        may return the input itself if the criteria selected all of its
-        members.
-        
-        Typical usage::
-            
-          habitats = query.resultSet("Habitat")
-        """
     
     def selectOne(*input_names):
         """Execute a query that matches one distinct result and return it. For
         a single input name, return the resulting object from that input. For
-        multiple input names, return a tuple of the matching objects from the
-        inputs.
+        multiple input names, return a tuple of the matching joined objects 
+        from the inputs.
         
-        The query **must** return a single result for the call to succeed. If
-        multiple results match raise PypesQueryError.
+        The query **must** return a single result for the call to succeed. If 
+        no results are found raise NoResultsError. If multiple results are
+        found raise MultipleResultsError.        
 
         Typical usage::
             
@@ -605,13 +593,24 @@
             
           query.selectOne("Winner")
         """
+
+    def resultSet(input_name):
+        """Execute the query and return an ISet object containing the
+        objects from input_name that were selected by the criteria. This
+        may return the input itself if the criteria selected all of its
+        members.
         
-    def analyse():
-        """Return a human-readable analysis string of the steps and resources
-        that would be used to execute the query. This information can be
-        used to determine the complexity of queries and optimize them or to
-        confirm that resources are properly utilized for efficiency.
+        Typical usage::
+            
+          habitats = query.resultSet("Habitat")
         """
+        
+#    def analyse():
+#        """Return a human-readable analysis string of the steps and resources
+#        that would be used to execute the query. This information can be
+#        used to determine the complexity of queries and optimize them or to
+#        confirm that resources are properly utilized for efficiency.
+#        """
 
 class IExpression(Interface):
     """Introspectable, executable Python expression"""
@@ -722,13 +721,13 @@
     def union(other):
         """Returns a new partial result which is the union of the members of 
         both results. Other must have the same input names or raise
-        PypesQueryError.
+        QueryError.
         """
     
     def intersection(other):
         """Returns a new partial result which contains the member in both self
         and other. Other must have the same input names or raise 
-        PypesQueryError.
+        QueryError.
         """
         
     #def magnitude(*names):
@@ -752,7 +751,7 @@
         (if any). Fixed values are generally used when calling iterResults
         from inside another generator which needs to control the output in
         some way (i.e., enforcing joins or a sort order). If a fixed kwarg
-        is provided that does not match an input name, raise PypesQueryError.
+        is provided that does not match an input name, raise QueryError.
         """
         
     def resultSet(name):
@@ -760,18 +759,38 @@
         that are matched by the criteria. If the input is not filtered by the
         criteria, then it may be returned.
         
-        If name does not coorespond to an input, raise PypesQueryError.
+        If name does not coorespond to an input, raise QueryError.
         """
 
+class IActualizedPartialResult(IPartialResult):
+    """A partial result which is fully actualized.
+    
+    The criteria is fully evaluated, thus iteration and length can be performed
+    efficiently without further comparisons"""
+    
+    def __len__():
+        """Return the result count"""
+   
+
 class IQueryResult(Interface):
     """Result from running a query"""
     
     def query():
-        """Return the query object which generated this result"""
+        """Return the IQuery object which generated this result"""
         
     def names():
-        """Return a sequence of input names selected for query output"""
-    
+        """Return the sequence of input names selected for query output"""
+
+    def evaluated():
+        """Return true if the query is fully evaluated, false if not. 
+        
+        A fully evaluated query requires no additional criteria selection or
+        sorting computation and its length is already calculated. Queries are
+        generally fully evaluated if they are fulfilled entirely by indexes,
+        already have been fully iterated, had their length calculated or are
+        very simple.
+        """
+        
     def __iter__():
         """Return an iterator of the query output.
         
@@ -786,19 +805,10 @@
         This requires full evaluation of the query result which may be
         expensive if it has not already been performed. An application can test
         if the query is already fully evaluated by calling the evaluated()
-        method. If it returns true then the length compution is already done,
-        if false then it requires computation to return.
+        method. If it is true then the length compution is already done,
+        if false then len() requires computation to return.
         """
         
     def __contains__(item):
         """Return true if item is a result in the query output"""
-    
-    def evaluated():
-        """Return true if the query is fully evaluated, false if not. 
-        
-        A fully evaluated query requires no additional criteria selection or
-        sorting computation and its length is already calculated. Queries are
-        generally fully evaluated if they are fulfilled entirely by indexes,
-        already have been fully iterated, had their length calculated or are
-        very simple.
-        """
+



More information about the Zope-CVS mailing list