Decorator activated via a scan which treats the function being decorated as an event subscriber for the set of interfaces passed as
*ifacesto the decorator constructor.
from pyramid.events import NewRequest from pyramid.events import subscriber @subscriber(NewRequest) def mysubscriber(event): event.request.foo = 1
More than one event type can be passed as a construtor argument. The decorated subscriber will be called for each event type.
from pyramid.events import NewRequest, NewResponse from pyramid.events import subscriber @subscriber(NewRequest, NewResponse) def mysubscriber(event): print event
subscriberdecorator is used without passing an arguments, the function it decorates is called for every event sent:
from pyramid.events import subscriber @subscriber() def mysubscriber(event): print event
This method will have no effect until a scan is performed against the package or module which contains it, ala:
from pyramid.config import Configurator config = Configurator() config.scan('somepackage_containing_subscribers')
An instance of this class is emitted as an event when the
pyramid.config.Configurator.make_wsgi_app()is called. The instance has an attribute,
app, which is an instance of the router that will handle WSGI requests. This class implements the
For backwards compatibility purposes, this class can also be imported as
pyramid.events.WSGIApplicationCreatedEvent. This was the name of the event class before Pyramid 1.0.
An instance of this class is emitted as an event whenever Pyramid begins to process a new request. The even instance has an attribute,
request, which is a request object. This event class implements the
An instance of this class is emitted as an event after the Pyramid router finds a context object (after it performs traversal) but before any view code is executed. The instance has an attribute,
request, which is the request object generated by Pyramid.
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 attached by context-finding code.
This class implements the
As of Pyramid 1.0, for backwards compatibility purposes, this event may also be imported as
The instance has two attributes:
request, which is the request which caused the response, and
response, which is the response object returned by a view or renderer.
responsewas generated by an exception view, the request will have an attribute named
exception, which is the exception object which caused the exception view to be executed. If the response was generated by a ‘normal’ view, this attribute of the request will be
This event will not be generated if a response cannot be created due to an exception that is not caught by an exception view (no response is created under this circumstace).
This class implements the
Subscribers to this event may introspect the and modify the set of renderer globals before they are passed to a renderer. This event object iself has a dictionary-like interface that can be used for this purpose. For example:
from repoze.events import subscriber from pyramid.events import BeforeRender @subscriber(BeforeRender) def add_global(event): event['mykey'] = 'foo'
An object of this type is sent as an event just before a renderer is invoked (but after the – deprecated – application-level renderer globals factory added via
pyramid.config.Configurator.set_renderer_globals_factory, if any, has injected its own keys into the renderer globals dictionary).
If a subscriber adds a key via
__setitem__or that already exists in the renderer globals dictionary, it will overwrite an older value that is already in the globals dictionary. This can be problematic because event subscribers to the BeforeRender event do not possess any relative ordering. For maximum interoperability with other third-party subscribers, if you write an event subscriber meant to be used as a BeforeRender subscriber, your subscriber code will need to (using
__contains__of the event object) ensure no value already exists in the renderer globals dictionary before setting an overriding value.
The event has an additional attribute named
rendering_val. This is the (non-system) value returned by a view or passed to
value. This feature is new in Pyramid 1.2.
Update D from dict/iterable E and F. If E has a .keys() method, does: for k in E: D[k] = E[k] If E lacks .keys() method, does: for (k, v) in E: D[k] = v. In either case, this is followed by: for k in F: D[k] = F[k].
clear() → None. Remove all items from D.¶
copy() → a shallow copy of D¶
fromkeys(S[, v]) → New dict with keys from S and values equal to v.¶
v defaults to None.
get(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
has_key(k) → True if D has a key k, else False¶
items() → list of D's (key, value) pairs, as 2-tuples¶
iteritems() → an iterator over the (key, value) items of D¶
iterkeys() → an iterator over the keys of D¶
itervalues() → an iterator over the values of D¶
keys() → list of D's keys¶
pop(k[, d]) → v, remove specified key and return the corresponding value.¶
If key is not found, d is returned if given, otherwise KeyError is raised
popitem() → (k, v), remove and return some (key, value) pair as a¶
2-tuple; but raise KeyError if D is empty.
setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
values() → list of D's values¶
viewitems() → a set-like object providing a view on D's items¶
viewkeys() → a set-like object providing a view on D's keys¶
viewvalues() → an object providing a view on D's values¶
See Using Events for more information about how to register code which subscribes to these events.