[Grok-dev] New feature in grokcore.component.

Sylvain Viollon sylvain at infrae.com
Tue Jan 4 12:55:57 EST 2011


  I would like to use in my project subscribers, but not for events.
  Basically, I would to be able to define the following things:

  class MyFilter(grokcore.component.MultiSubscriber):
     grok.adapts(IMyContent, IHTTPRequest)

     def __init__(self, context, request):
         self.context = context
         self.request = request

     def process(...):

  class AdvancedFilter(MyFilter):
     grok.adapts(IMyOtherContent, IHTTPRequest)

  After with the yet to be implemented function
  queryOrderedSubscribers, I should be able to do things like:

  for content_filter in queryOrderedSubscribers(
      (my_content, request), IFilter):

  To do this, we would have to add to grokcore.component:

  - A MultiSubscriber base class, that is grokked as a subscribers (like
    would do the @susbcribe decorator). You would be able to use the
    adapts, provides, implements and order directive on it (subscribers
    doesn't have a name). From what I read in zope.interface, the
    provides would be required for this usage of subscription, like for

  - Maybe to be consistent with Adapter, we could do a Subscriber base
    class, that do the same, using the context directive instead of the
    adapts one, and having a default __init__.

  - A queryOrderedMultiSubscribers: that would query the list of
    subscribers, return a list of instance of them (like do
    queryMultiAdapter), and sort them using the information of the
    grok.order directive (having not sorted events/subscribers is often
    annoying). Probably we want to add queryMultiSubscribers (do the
    same without sorting), queryOrderedSubscribers and
    querySubscribers. I don't thing there is a meaning in having get
    functions for subscribers. Well the list of those function to have
    is open to discussion, I just require the
    queryOrderedMultiSubscribers for my project.

  Unless someone thinks it is a terrible idea, I can add this to
  grokcore.component tomorrow morning. I can even do it only in a



Sylvain Viollon -- Infrae
t +31 10 243 7051 -- http://infrae.com
Hoevestraat 10 3033GC Rotterdam -- The Netherlands

More information about the Grok-dev mailing list