All the following are great, especially the (SF) ones ;-)

Tres Seaver wrote:
  >>> from zope.interface import Interface, Attribute
  >>> from zope.interface import implements, directlyProvides
  >>> from zope.component import provideUtility, provideAdapter, adapts
  >>> class IFoo(Interface):
  ...     name = Attribute(u'Name')
  >>> class FooUtil:
  ...     implements(IFoo)
  ...     def __init__(self, name):
  ... = name
  >>> fooUtil = FooUtil('default')
  >>> provideUtility(fooUtil)
  >>> fooUtilNamed = FooUtil('named')
  >>> provideUtility(fooUtilNamed, name='named')
  >>> class FooAdapter:
  ...     implements(IFoo)
  ...     adapts(None)
  ...     name = 'default'
  ...     def __init__(self, context,*args):
  ...         self.context = context
  >>> class FooAdapterNamed(FooAdapter):
  ...     name = 'named'
  >>> provideAdapter(FooAdapter)
  >>> provideAdapter(FooAdapterNamed, name='named')

Now the usage.  Things which *don't* work today are marked '(SF)'.

Interfaces called with *no* context argument return
utilities, not adapters (SF)::

  >>> u_default = IFoo() # return the default utility
  >>> u_default.__class__.__name__,
  ('FooUtil', 'default')

Named utilities can also be looked up (SF)::

  >>> u_named = IFoo(name='named')
  >>> u_named.__class__.__name__,
  ('FooUtil', 'named')

Default adapter lookup works as expected::

  >>> context = object()
  >>> a_default = IFoo(context)
  >>> a_default.__class__.__name__,
  ('FooAdapter', 'default')

But we can also do named adapter lookup (SF)::

  >>> a_named = IFoo(context, name='named')
  >>> a_named.__class__.__name__,
  ('FooAdapterNamed', 'named')

I'll note that none of these appear to do contextual lookup.
Would we want a spelling like this which worked with contextual lookup?

One thing I think I mentioned before would be the ability to use "calling the interface" to get a multi-adapter:

a_default = IFoo(objects=(context,context))
('FooAdapter', 'default')

One other thing, where is the code that gets called when you do ISomething(..etc...)? I had a look in and couldn't find anything :-S

I'd be interested in knocking the above set of extras up on a branch and seeing what people think...



Simplistix - Content Management, Zope & Python Consulting

Zope3-dev mailing list

Reply via email to