summaryrefslogtreecommitdiff
path: root/docs/narr
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-06-04 18:43:25 -0400
committerChris McDonough <chrism@plope.com>2011-06-04 18:43:25 -0400
commitdf15ed98612e7962e3122da52d8d5f5b9d8882b2 (patch)
treeb862f334a286fd0545a134a73c89d295a57d7a64 /docs/narr
parent71738bc9418170cebfd532fbed6bb48ac8c3fb40 (diff)
downloadpyramid-df15ed98612e7962e3122da52d8d5f5b9d8882b2.tar.gz
pyramid-df15ed98612e7962e3122da52d8d5f5b9d8882b2.tar.bz2
pyramid-df15ed98612e7962e3122da52d8d5f5b9d8882b2.zip
- It is now possible to control how the Pyramid router calls the WSGI
``start_response`` callable and obtains the WSGI ``app_iter`` based on adapting the response object to the new ``pyramid.interfaces.IResponder`` interface. The default ``IResponder`` uses Pyramid 1.0's logic to do this. To override the responder:: from pyramid.interfaces import IResponder from pyramid.response import Response from myapp import MyResponder config.registry.registerAdapter(MyResponder, (Response,), IResponder, name='') This makes it possible to reuse response object implementations which have, for example, their own ``__call__`` expected to be used as a WSGI application (like ``pyramid.response.Response``), e.g.: class MyResponder(object): def __init__(self, response): """ Obtain a reference to the response """ self.response = response def __call__(self, request, start_response): """ Call start_response and return an app_iter """ app_iter = self.response(request.environ, start_response) return app_iter
Diffstat (limited to 'docs/narr')
-rw-r--r--docs/narr/hooks.rst36
1 files changed, 36 insertions, 0 deletions
diff --git a/docs/narr/hooks.rst b/docs/narr/hooks.rst
index d620b5672..aa151d281 100644
--- a/docs/narr/hooks.rst
+++ b/docs/narr/hooks.rst
@@ -522,6 +522,42 @@ The default context URL generator is available for perusal as the class
:term:`Pylons` GitHub Pyramid repository.
.. index::
+ single: IResponder
+
+.. _using_iresponder:
+
+Changing How Pyramid Treats Response Objects
+--------------------------------------------
+
+It is possible to control how the Pyramid :term:`router` calls the WSGI
+``start_response`` callable and obtains the WSGI ``app_iter`` based on
+adapting the response object to the :class: `pyramid.interfaces.IResponder`
+interface. The default ``IResponder`` uses the three attributes ``status``,
+``headerlist``, and ``app_iter`` attached to the response object, and calls
+``start_response`` with the status and headerlist, returning the
+``app_iter``. To override the responder::
+
+ from pyramid.interfaces import IResponder
+ from pyramid.response import Response
+ from myapp import MyResponder
+
+ config.registry.registerAdapter(MyResponder, (Response,),
+ IResponder, name='')
+
+Overriding makes it possible to reuse response object implementations which
+have, for example, their own ``__call__`` expected to be used as a WSGI
+application (like :class:`pyramid.response.Response`), e.g.:
+
+ class MyResponder(object):
+ def __init__(self, response):
+ """ Obtain a reference to the response """
+ self.response = response
+ def __call__(self, request, start_response):
+ """ Call start_response and return an app_iter """
+ app_iter = self.response(request.environ, start_response)
+ return app_iter
+
+.. index::
single: view mapper
.. _using_a_view_mapper: