[Checkins] SVN: Sandbox/adamg/ocql/trunk/src/ocql/ use interface.providedBy instead of isinstance

Adam Groszer agroszer at gmail.com
Tue Aug 26 11:49:18 EDT 2008


Log message for revision 90348:
  use interface.providedBy instead of isinstance

Changed:
  U   Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py
  U   Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py
  U   Sandbox/adamg/ocql/trunk/src/ocql/rewriter/rewriter.py

-=-
Modified: Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py	2008-08-26 15:48:23 UTC (rev 90347)
+++ Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py	2008-08-26 15:49:17 UTC (rev 90348)
@@ -11,7 +11,7 @@
 from BTrees.IFBTree import difference
 
 from ocql.interfaces import IDB
-from ocql.database.index import AllIndex
+from ocql.database.index import IAllIndex
 from ocql.exceptions import ReanalyzeRequired
 
 class MetaType:
@@ -124,7 +124,7 @@
         intids = getUtility(IIntIds)
         for name, catalog in catalogs:
             for iname, index in catalog.items():
-                if isinstance(index, AllIndex):
+                if IAllIndex.providedBy(index):
                     if index.interface.__name__ == klassname:
                         results = catalog.apply({iname:(1,1)})
                         obj_list = [intids.getObject(result) for result in results]

Modified: Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py	2008-08-26 15:48:23 UTC (rev 90347)
+++ Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py	2008-08-26 15:49:17 UTC (rev 90348)
@@ -289,7 +289,7 @@
 
     def get_collection_type(self):
         t = self.left.get_class()
-        if isinstance(self.right, Identifier):
+        if IIdentifier.providedBy(self.right):
             try:
                 r = t[self.right.name]
             except:
@@ -300,7 +300,7 @@
                 r = t[self.right.left.name]
             except:
                 from pub.dbgpclient import brk; brk()
-            
+
         return r
 
         #else:

Modified: Sandbox/adamg/ocql/trunk/src/ocql/rewriter/rewriter.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/rewriter/rewriter.py	2008-08-26 15:48:23 UTC (rev 90347)
+++ Sandbox/adamg/ocql/trunk/src/ocql/rewriter/rewriter.py	2008-08-26 15:49:17 UTC (rev 90348)
@@ -61,8 +61,7 @@
                 t.addSymbol()
 
             firstTerm = self.context.terms[0]
-            if isinstance(firstTerm, ocql.queryobject.queryobject.In):
-
+            if ocql.queryobject.interfaces.IIn.providedBy(firstTerm):
                 ctype = firstTerm.get_collection_type()
 
                 rv = Iter(
@@ -82,12 +81,14 @@
                             IRewriter(firstTerm.expression)()
                             ) # FIXME: ?set? must be determined by type(firstTerm.expression)
                 )
-            elif isinstance(firstTerm, ocql.queryobject.queryobject.Alias):
+            elif ocql.queryobject.interfaces.IAlias.providedBy(firstTerm):
                 rv = Iter(
                         self.context.collection_type,
                         Lambda(IRewriter(firstTerm.identifier)(),
-                               Single(self.context.collection_type, IRewriter(firstTerm.identifier)())),
-                        Single(self.context.collection_type, IRewriter(firstTerm.expression)()))
+                               Single(self.context.collection_type,
+                                      IRewriter(firstTerm.identifier)())),
+                        Single(self.context.collection_type,
+                               IRewriter(firstTerm.expression)()))
 
             else:
                 rv = If(
@@ -157,7 +158,8 @@
 
     def __call__(self):
         return Identifier(
-            '.'.join([IRewriter(self.context.left)().name, IRewriter(self.context.right)().name]))
+            '.'.join([IRewriter(self.context.left)().name,
+                      IRewriter(self.context.right)().name]))
 
 class AddRewriter(BinaryRewriter):
     implements(IRewriter)
@@ -220,7 +222,8 @@
     adapts(IQuanted)
 
     def __call__(self, expression, operator):
-        return IRewriter(self.context.quantor)(expression, self.context.expression, operator)
+        return IRewriter(self.context.quantor)(
+            expression, self.context.expression, operator)
 
 class EveryRewriter(ChildRewriter):
     implements(IRewriter)
@@ -275,10 +278,12 @@
     adapts(ICondition)
 
     def __call__(self):
-        if isinstance(self.context.left, ocql.queryobject.queryobject.Quanted):
-            return IRewriter(self.context.left)(self.context.right, self.context)
-        if isinstance(self.context.right, ocql.queryobject.queryobject.Quanted):
-            return IRewriter(self.context.right)(self.context.left, self.context)
+        if ocql.queryobject.interfaces.IQuanted.providedBy(self.context.left):
+            return IRewriter(self.context.left)(
+                self.context.right, self.context)
+        if ocql.queryobject.interfaces.IQuanted.providedBy(self.context.right):
+            return IRewriter(self.context.right)(
+                self.context.left, self.context)
         else:
             return Binary(
                 IRewriter(self.context.left)(),



More information about the Checkins mailing list