[Zope3-Users] Getting request from subscriber ?

Gary Poster gary at zope.com
Mon Feb 13 10:24:22 EST 2006


On Feb 13, 2006, at 6:02 AM, Thierry FLORAC wrote:

>
>   Hi,
>
> Probably a simple question...
>
> I need to extract request's content from an event handler defined  
> via a subscriber.
> "request" doesn't seems to be in a subscriber's context. So how can  
> I get it ??

option 1: make the subscriber listen for an event that has a request  
attribute (perhaps one you generate).
option 2: see if there's another way to do what you want
option 3: grab it by force from the thread locals--something like this:

import zope.security.management
from zope.publisher.interfaces import IRequest

def getRequest():
     i = zope.security.management.getInteraction() # raises  
NoInteraction
     for p in i.participations:
         if IRequest.providedBy(p):
             return p
     raise RuntimeError('No IRequest in interaction')

Gary


More information about the Zope3-users mailing list