summaryrefslogtreecommitdiff
path: root/repoze/bfg/events.py
blob: 75a5aec5a0aee8b93f3e1751c27fa2cbd2efcdb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from zope.interface import implements

from repoze.bfg.interfaces import IAfterTraversal
from repoze.bfg.interfaces import INewRequest
from repoze.bfg.interfaces import INewResponse
from repoze.bfg.interfaces import IWSGIApplicationCreatedEvent

class NewRequest(object):
    """ An instance of this class is emitted as an :term:`event`
    whenever repoze.bfg begins to process a new request.  The instance
    has an attribute, ``request``, which is a :term:`request` object.
    This class implements the ``repoze.bfg.interfaces.INewRequest``
    interface."""
    implements(INewRequest)
    def __init__(self, request):
        self.request = request

class NewResponse(object):
    """ An instance of this class is emitted as an :term:`event`
    whenever any repoze.bfg view returns a :term:`response`..  The
    instance has an attribute, ``response``, which is the response
    object returned by the view.  This class implements the
    ``repoze.bfg.interfaces.INewResponse`` interface."""
    implements(INewResponse)
    def __init__(self, response):
        self.response = response

class AfterTraversal(object):
    implements(IAfterTraversal)
    """ An instance of this class is emitted as an :term:`event` after
    the repoze.bfg :term:`router` performs traversal but before any
    view code is executed.  The instance has an attribute,
    ``request``, which is the request object generated by
    :mod:`repoze.bfg`.  Notably, the request object will have an
    attribute named ``context``, which is the context that will be
    provided to the view which will eventually be called, as well as
    other attributes defined by the traverser.  This class implements
    the ``repoze.bfg.interfaces.IAfterTraversal`` interface."""
    def __init__(self, request):
        self.request = request
    
class WSGIApplicationCreatedEvent(object):    
    """ An instance of this class is emitted as an :term:`event` when
    the ``make_wsgi_app`` method of a :term:`Configurator` is called).
    The instance has an attribute, ``app``, which is an instance of
    the ``repoze.bfg.router.Router`` class that will handle WSGI
    requests.  This class implements the
    ``repoze.bfg.interfaces.IWSGIApplicationCreatedEvent`` interface."""
    implements(IWSGIApplicationCreatedEvent)
    def __init__(self, app):
        self.app = app
        self.object = app