[Checkins] SVN: Products.ZCatalog/trunk/src/Products/ZCatalog/ Move `plan.make_key` onto the catalog classs, as its first argument is a catalog instance anyways

Hanno Schlichting hannosch at hannosch.eu
Thu Oct 20 08:34:43 EST 2011


Log message for revision 123115:
  Move `plan.make_key` onto the catalog classs, as its first argument is a catalog instance anyways
  

Changed:
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/plan.py

-=-
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py	2011-10-20 13:25:49 UTC (rev 123114)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py	2011-10-20 13:34:43 UTC (rev 123115)
@@ -33,9 +33,8 @@
 from Lazy import LazyMap, LazyCat, LazyValues
 from CatalogBrains import AbstractCatalogBrain, NoBrainer
 from .plan import CatalogPlan
-from .plan import make_key
+from .plan import ValueIndexes
 
-
 LOG = logging.getLogger('Zope.ZCatalog')
 
 
@@ -417,9 +416,37 @@
             result[name] = self.getIndex(name).getEntryForObject(rid, "")
         return result
 
-    ## This is the Catalog search engine. Most of the heavy lifting happens
+    # This is the Catalog search engine. Most of the heavy lifting happens
     # below
 
+    def make_key(self, query):
+        if not query:
+            return None
+
+        indexes = self.indexes
+        valueindexes = ValueIndexes.determine(indexes)
+        key = keys = query.keys()
+
+        values = [name for name in keys if name in valueindexes]
+        if values:
+            # If we have indexes whose values should be considered, we first
+            # preserve all normal indexes and then add the keys whose values
+            # matter including their value into the key
+            key = [name for name in keys if name not in values]
+            for name in values:
+
+                v = query.get(name, [])
+                if isinstance(v, (tuple, list)):
+                    v = list(v)
+                    v.sort()
+
+                # We need to make sure the key is immutable, repr() is an easy way
+                # to do this without imposing restrictions on the types of values
+                key.append((name, repr(v)))
+
+        key = tuple(sorted(key))
+        return key
+
     def make_query(self, request):
         # This is a bit of a mess, but the ZCatalog API has traditionally
         # supported passing in query restrictions in almost arbitary ways
@@ -576,7 +603,7 @@
             warnings.warn('Your query %s produced no query restriction. '
                           'Currently the entire catalog content is returned. '
                           'In Zope 2.14 this will result in an empty LazyCat '
-                          'to be returned.' % repr(make_key(self, query)),
+                          'to be returned.' % repr(self.make_key(query)),
                           DeprecationWarning, stacklevel=3)
 
             rlen = len(self)

Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/plan.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/plan.py	2011-10-20 13:25:49 UTC (rev 123114)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/plan.py	2011-10-20 13:34:43 UTC (rev 123115)
@@ -177,35 +177,6 @@
         return value_indexes
 
 
-def make_key(catalog, query):
-    if not query:
-        return None
-
-    indexes = catalog.indexes
-    valueindexes = ValueIndexes.determine(indexes)
-    key = keys = query.keys()
-
-    values = [name for name in keys if name in valueindexes]
-    if values:
-        # If we have indexes whose values should be considered, we first
-        # preserve all normal indexes and then add the keys whose values
-        # matter including their value into the key
-        key = [name for name in keys if name not in values]
-        for name in values:
-
-            v = query.get(name, [])
-            if isinstance(v, (tuple, list)):
-                v = list(v)
-                v.sort()
-
-            # We need to make sure the key is immutable, repr() is an easy way
-            # to do this without imposing restrictions on the types of values
-            key.append((name, repr(v)))
-
-    key = tuple(sorted(key))
-    return key
-
-
 class CatalogPlan(object):
     """Catalog plan class to measure and identify catalog queries and plan
     their execution.
@@ -214,7 +185,7 @@
     def __init__(self, catalog, query=None, threshold=0.1):
         self.catalog = catalog
         self.query = query
-        self.key = make_key(catalog, query)
+        self.key = catalog.make_key(query)
         self.benchmark = {}
         self.threshold = threshold
         self.cid = self.get_id()



More information about the checkins mailing list