[Checkins] SVN: Sandbox/faassen/iface/src/iface/ fixed up MultiMap handling except for the back-tracking part

Thomas Lotze tl at gocept.com
Wed Jan 6 18:39:24 EST 2010


Log message for revision 107756:
  fixed up MultiMap handling except for the back-tracking part

Changed:
  U   Sandbox/faassen/iface/src/iface/__init__.py
  U   Sandbox/faassen/iface/src/iface/mapping.py
  U   Sandbox/faassen/iface/src/iface/mapping.txt

-=-
Modified: Sandbox/faassen/iface/src/iface/__init__.py
===================================================================
--- Sandbox/faassen/iface/src/iface/__init__.py	2010-01-06 22:55:47 UTC (rev 107755)
+++ Sandbox/faassen/iface/src/iface/__init__.py	2010-01-06 23:39:24 UTC (rev 107756)
@@ -1,2 +1,2 @@
-from iface.mapping import Map, MapKey
+from iface.mapping import Map, MultiMap, MapKey
 

Modified: Sandbox/faassen/iface/src/iface/mapping.py
===================================================================
--- Sandbox/faassen/iface/src/iface/mapping.py	2010-01-06 22:55:47 UTC (rev 107755)
+++ Sandbox/faassen/iface/src/iface/mapping.py	2010-01-06 23:39:24 UTC (rev 107756)
@@ -53,21 +53,21 @@
         key = (arity,) + tuple(key)
         map = self._by_arity
         for k in key[:-1]:
-           submap = map.get(k)
+           submap = dict(map).get(k)
            if submap is None:
                submap = map[k] = Map()
            map = submap
         map[key[-1]] = value
-                    
-    def __delitem__(self, key, value):
+
+    def __delitem__(self, key):
         arity = len(key)
         key = (arity,) + tuple(key)
         map = self._by_arity
         for k in key[:-1]:
             map = dict(map)[k]
         del map[key[-1]]
-    
-    def __getitem__(self, key, value):
+
+    def __getitem__(self, key):
         arity = len(key)
         key = (arity,) + tuple(key)
         map = self._by_arity

Modified: Sandbox/faassen/iface/src/iface/mapping.txt
===================================================================
--- Sandbox/faassen/iface/src/iface/mapping.txt	2010-01-06 22:55:47 UTC (rev 107755)
+++ Sandbox/faassen/iface/src/iface/mapping.txt	2010-01-06 23:39:24 UTC (rev 107756)
@@ -169,8 +169,46 @@
   >>> two = MapKey('two', [one])
   >>> three = MapKey('three', [two])
 
-Now we create a MultiMap
+Now we create a MultiMap and register a few values by MultiMapKeys::
 
+  >>> from iface import MultiMap
+  >>> multimap = MultiMap()
+
+  >>> multimap[(alpha, three)] = u'Value for alpha, three'
+  >>> multimap[(beta, two)] = u'Value for beta, two'
+
+When looking up any of these two MultiMapKeys, we'll get back the respective
+values::
+
+  >>> multimap[(alpha, three)]
+  u'Value for alpha, three'
+  >>> multimap[(beta, two)]
+  u'Value for beta, two'
+
+We'll also be able to look up MultiMapKeys that are more specific than
+anything registered in at least one component. When a look-up could find two
+less specific MultiMapKeys, the one with the more specific first component is
+preferred::
+
+  >>> multimap[(gamma, two)]
+  u'Value for beta, two'
+  >>> multimap[(beta, three)]
+  u'Value for beta, two'
+  >>> multimap[(gamma, three)]
+  u'Value for beta, two'
+
+However, we cannot look up MultiMapKeys that are less specific than anything
+registered in at least one component::
+
+  >>> multimap[(alpha, one)]
+  Traceback (most recent call last):
+    ...
+  KeyError: <MapKey: 'one'>
+  >>> multimap[(alpha, two)]
+  Traceback (most recent call last):
+    ...
+  KeyError: <MapKey: 'two'>
+
 next: multi lookup. What is the behavior of zope.interface? Do earlier
 entries in the lookup list always weigh more heavily than the second
 one? We need backtracking in case we don't find anything for the next



More information about the checkins mailing list