summaryrefslogtreecommitdiff
path: root/docs/narr/events.rst
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-11-14 15:29:08 +0000
committerChris McDonough <chrism@agendaless.com>2008-11-14 15:29:08 +0000
commit5f6898f5abf11d51052357d3e725298f49d10cdc (patch)
treeb704f87bdc28dfbb716bf06b08e0e060918d377e /docs/narr/events.rst
parent13831c45244b62868347339b44de42b9e008ab1a (diff)
downloadpyramid-5f6898f5abf11d51052357d3e725298f49d10cdc.tar.gz
pyramid-5f6898f5abf11d51052357d3e725298f49d10cdc.tar.bz2
pyramid-5f6898f5abf11d51052357d3e725298f49d10cdc.zip
Fix code and improve narrative.
Diffstat (limited to 'docs/narr/events.rst')
-rw-r--r--docs/narr/events.rst22
1 files changed, 12 insertions, 10 deletions
diff --git a/docs/narr/events.rst b/docs/narr/events.rst
index 2e94c4407..376d7b796 100644
--- a/docs/narr/events.rst
+++ b/docs/narr/events.rst
@@ -106,16 +106,17 @@ Using An Event to Vary the Request Type
---------------------------------------
The most common usage of the ``INewRequestEvent`` is to attach an
-:term:`interface` to the request to be able to differentiate a request
-issued by a browser from a request issued by an XML-RPC from a request
-issued by a REST client. This makes it possible to register different
-views against different ``request_type`` interfaces; for instance,
-depending on request headers, you might return JSON or XML data.
+:term:`interface` to the request to be able to differentiate, for
+example, a request issued by a browser from a request issued by an
+XML-RPC from a request issued by a REST client. This differentiation
+makes it possible to register different views against different
+``request_type`` interfaces; for instance, depending on request
+headers, you might return JSON or XML data.
To do this, you should subscribe an function to the ``INewRequest``
-event type, and use the ``zope.interface.alsoProvides`` API within the
-function to add one or more interfaces to the request object provided
-by the event. Here's an example.
+event type, and you should use the ``zope.interface.alsoProvides`` API
+within the function to add one or more interfaces to the request
+object provided by the event. Here's an example.
.. code-block:: python
:linenos:
@@ -128,14 +129,15 @@ by the event. Here's an example.
application/xml header"""
class IJSONRequest(Interface):
- """ A request from a JSON client """
+ """ A request from a JSON client that sets and Accept:
+ application/json header """
def categorize_request(event):
request = event.request
accept = request.headers.get('accept', '')
if 'application/xml' in accept:
alsoProvides(request, IRestRequest)
- if 'application.json' in accept:
+ if 'application/json' in accept:
alsoProvides(request, IJSONRequest)
Then in your view registration ZCML, you can use the ``request_type``