[Checkins] SVN: Sandbox/faassen/iface/src/iface/ Explore AdapterRegistry's behavior in case of looking up values and

Martijn Faassen faassen at startifact.com
Sat Jan 9 12:37:09 EST 2010


Log message for revision 107951:
  Explore AdapterRegistry's behavior in case of looking up values and
  certain ambiguities. It appears the most recent registration wins.
  
  Need to implement this behavior for iface too (at least in 
  compatibility mode, but can we think of something better?)
  
  

Changed:
  A   Sandbox/faassen/iface/src/iface/compat_lookup.txt
  U   Sandbox/faassen/iface/src/iface/tests.py

-=-
Added: Sandbox/faassen/iface/src/iface/compat_lookup.txt
===================================================================
--- Sandbox/faassen/iface/src/iface/compat_lookup.txt	                        (rev 0)
+++ Sandbox/faassen/iface/src/iface/compat_lookup.txt	2010-01-09 17:37:09 UTC (rev 107951)
@@ -0,0 +1,70 @@
+Lookup Compatibility with zope.interface
+========================================
+
+Let's explore lookup scenarios now::
+
+  >>> from zope.interface import Interface
+  >>> class IFrom(Interface):
+  ...     pass
+  >>> class IBase(Interface):
+  ...     pass
+  >>> class ILookup(IBase):
+  ...     pass
+  >>> class ISub(ILookup):
+  ...     pass
+  >>> reg = AdapterRegistry()
+  >>> reg.register((IFrom,), ILookup, '', u'Value for ILookup')
+
+  >>> reg.lookup((IFrom,), ILookup)
+  u'Value for ILookup'
+  >>> reg.lookup((IFrom,), IBase)
+  u'Value for ILookup'
+  >>> print reg.lookup((IFrom,), ISub)
+  None
+
+We also register something for ``ISub`` now::
+
+  >>> reg.register((IFrom,), ISub, '', u'Value for ISub')
+  >>> reg.lookup((IFrom,), ILookup)
+  u'Value for ILookup'
+  >>> reg.lookup((IFrom,), ISub)
+  u'Value for ISub'
+  >>> reg.lookup((IFrom,), IBase)
+  u'Value for ILookup'
+
+Ambiguity::
+
+  >>> reg = AdapterRegistry()
+  >>> class ISub2(ILookup):
+  ...    pass
+  >>> reg.register((IFrom,), ISub, '', u'Value for ISub')
+  >>> reg.lookup((IFrom,), ILookup)
+  u'Value for ISub'
+  >>> reg.register((IFrom,), ISub2, '', u'Value for ISub2')
+  >>> reg.lookup((IFrom,), ILookup)
+  u'Value for ISub2'
+
+The specific lookups work normally::
+
+  >>> reg.lookup((IFrom,), ISub)
+  u'Value for ISub'
+  >>> reg.lookup((IFrom,), ISub2)
+  u'Value for ISub2'
+
+The order of registration appears to count::
+
+  >>> reg = AdapterRegistry()
+  >>> reg.register((IFrom,), ISub2, '', u'Value for ISub2')
+  >>> reg.lookup((IFrom,), ILookup)
+  u'Value for ISub2'
+  >>> reg.register((IFrom,), ISub, '', u'Value for ISub')
+  >>> reg.lookup((IFrom,), ILookup)
+  u'Value for ISub'
+
+The specific lookups still work normally::
+
+  >>> reg.lookup((IFrom,), ISub)
+  u'Value for ISub'
+  >>> reg.lookup((IFrom,), ISub2)
+  u'Value for ISub2'
+

Modified: Sandbox/faassen/iface/src/iface/tests.py
===================================================================
--- Sandbox/faassen/iface/src/iface/tests.py	2010-01-09 17:36:01 UTC (rev 107950)
+++ Sandbox/faassen/iface/src/iface/tests.py	2010-01-09 17:37:09 UTC (rev 107951)
@@ -19,7 +19,15 @@
             doctest.DocFileSuite(
                 'compatibility.txt',
                 optionflags=optionflags,
-                globs=dict(AdapterRegistry=CompatibilityAdapterRegistry)),            
+                globs=dict(AdapterRegistry=CompatibilityAdapterRegistry)),
+            doctest.DocFileSuite(
+                'compat_lookup.txt',
+                optionflags=optionflags,
+                globs=dict(AdapterRegistry=AdapterRegistry)),
+            # doctest.DocFileSuite(
+            #     'compat_lookup.txt',
+            #     optionflags=optionflags,
+            #     globs=dict(AdapterRegistry=CompatibilityAdapterRegistry)),
             ])
             
     return suite



More information about the checkins mailing list