[Zope-CVS] CVS: Packages/pypes/pypes - query.py:1.14

Casey Duncan casey at zope.com
Thu May 13 00:33:41 EDT 2004


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

Modified Files:
	query.py 
Log Message:
Allow joins on non-hashable values


=== Packages/pypes/pypes/query.py 1.13 => 1.14 ===
--- Packages/pypes/pypes/query.py:1.13	Wed May 12 01:10:36 2004
+++ Packages/pypes/pypes/query.py	Thu May 13 00:33:37 2004
@@ -50,7 +50,7 @@
 from itertools import imap
 from zope.interface import implements
 from compiler import ast
-from BTrees.OOBTree import OOBTree
+from BTrees.OOBTree import OOBTree, OOTreeSet
 from pypes.interfaces import IPartialResult, IExtent
 from pypes.exceptions import PypesLookupError, PypesQueryInputError, CantProcess
 from pypes.expression import Expression
@@ -230,6 +230,16 @@
             left_by_val[val].append(obj)
         except KeyError:
             left_by_val[val] = [obj]
+        except TypeError:
+            if isinstance(left_by_val, dict):
+                # Likely val is not hashable
+                # switch to using BTree which does not require hashable keys
+                # (but insertion is slower)
+                left_by_val = OOBTree(left_by_val)
+                left_by_val[val] = left_by_val.get(val, []) + [obj]
+            else:
+                raise
+    
     for right in right_iter:
         val = right_expr(right)
         try:
@@ -255,9 +265,20 @@
     for obj in right_iter:
         for val in right_expr(obj):
             try:
-                right_by_val[val].add(obj)
+                right_by_val[val].insert(obj)
             except KeyError:
-                right_by_val[val] = Set((obj,))
+                # Use of OOTreeSet allows for non-hashable objects
+                right_by_val[val] = OOTreeSet((obj,))
+            except TypeError:
+                if isinstance(right_by_val, dict):
+                    # Likely val is not hashable switch to using a
+                    # BTree which does not require hashable keys
+                    # (but insertion is slower)
+                    right_by_val = OOBTree(right_by_val)
+                    right_by_val[val] = right_by_val.get(val, []) + [obj]
+                else:
+                    raise
+                    
     for obj in left_iter:
         left = left_expr(obj)
         try:




More information about the Zope-CVS mailing list