Events¶
Events are registered in the context of an application via
tangled.web.app.Application.add_subscriber()
.
Subscribers typically have the signature subscriber(event)
. If subscriber
keyword args were passed to add_subscriber
, then the signature for the
subscriber would be subscriber(event, **kwargs)
.
Every event object will have an app
attribute. Other attributes are
event dependent.
-
class
tangled.web.events.
ApplicationCreated
(app)[source]¶ Emitted when an application is fully configured.
These events can be registered in the usual way by calling
tangled.web.app.Application.add_subscriber()
. There’s also a convenience method for this:tangled.web.app.Application.on_created()
.Attributes:
app
.
-
class
tangled.web.events.
NewRequest
(app, request)[source]¶ Emitted when an application receives a new request.
This is not emitted for static file requests.
Attributes:
app
,request
.
-
class
tangled.web.events.
NewResponse
(app, request, response)[source]¶ Emitted when the response for a request is created.
This is not emitted for static file requests.
If there’s in exception during request handling, this will not be emitted.
Attributes:
app
,request
,response
.
-
class
tangled.web.events.
ResourceFound
(app, request, resource)[source]¶ Emitted when the resource is found for a request.
Attributes:
app
,request
,resource
.
-
class
tangled.web.events.
TemplateContextCreated
(app, request, context)[source]¶ Emitted when the context for a template is created.
The template
context
is whatever data will passed to the template. E.g., for Mako, it’s a dict.This is emitted just before the template is rendered. Its purpose is to allow additional data to be injected into the template context.
Attributes:
app
,request
,context
-
tangled.web.events.
subscriber
(event_type, *args, **kw)[source]¶ Decorator for adding event subscribers.
Subscribers registered this way won’t be activated until
tangled.web.app.Application.load_config()
is called.Example:
@subscriber('tangled.web.events:ResourceFound') def on_resource_found(event): log.debug(event.resource.name)