diff options
| author | Chris McDonough <chrism@plope.com> | 2011-05-30 03:23:31 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-05-30 03:23:31 -0400 |
| commit | 966b5cfe03009069d7bbe92cc047b32a5e3cd4e6 (patch) | |
| tree | a8362388c495259f02e7e8aee52a61722381b759 | |
| parent | 356d0327c22d7ced5fe28f9e5cb73671fe63a69b (diff) | |
| download | pyramid-966b5cfe03009069d7bbe92cc047b32a5e3cd4e6.tar.gz pyramid-966b5cfe03009069d7bbe92cc047b32a5e3cd4e6.tar.bz2 pyramid-966b5cfe03009069d7bbe92cc047b32a5e3cd4e6.zip | |
- Fix older CHANGES entries.
- The ``pyramid.request.Request`` class now has a ``ResponseClass`` interface
which points at ``pyramid.response.Response``.
- The ``pyramid.request.Response`` class now has a ``RequestClass`` interface
which points at ``pyramid.response.Request``.
- ``pyramid.response.Response`` is now a *subclass* of
``webob.response.Response``. It also inherits from the built-in Python
``Exception`` class and implements the
``pyramid.interfaces.IExceptionResponse`` class so it can be raised as an
exception from view code.
| -rw-r--r-- | CHANGES.txt | 37 | ||||
| -rw-r--r-- | pyramid/__init__.py | 7 | ||||
| -rw-r--r-- | pyramid/config.py | 13 | ||||
| -rw-r--r-- | pyramid/exceptions.py | 4 | ||||
| -rw-r--r-- | pyramid/response.py | 10 |
5 files changed, 47 insertions, 24 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 756d1345c..15c86c13c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -104,12 +104,13 @@ Features section entitled "Static Routes" in the URL Dispatch narrative chapter for more information. -- A default exception view for the context ``webob.exc.HTTPException`` (aka - ``pyramid.httpexceptions.HTTPException``) is now registered by default. - This means that an instance of any exception class imported from - ``pyramid.httpexceptions`` (such as ``HTTPFound``) can now be raised from - within view code; when raised, this exception view will render the - exception to a response. +- A default exception view for the context + ``pyramid.interfaces.IExceptionResponse`` (aka + ``pyramid.response.Response`` or ``pyramid.httpexceptions.HTTPException``) + is now registered by default. This means that an instance of any exception + response class imported from ``pyramid.httpexceptions`` (such as + ``HTTPFound``) can now be raised from within view code; when raised, this + exception view will render the exception to a response. - New functions named ``pyramid.httpexceptions.abort`` and ``pyramid.httpexceptions.redirect`` perform the equivalent of their Pylons @@ -118,12 +119,18 @@ Features ``webob.exc.HTTPException``. - The Configurator now accepts an additional keyword argument named - ``httpexception_view``. By default, this argument is populated with a - default exception view function that will be used when an HTTP exception is - raised. When ``None`` is passed for this value, an exception view for HTTP - exceptions will not be registered. Passing ``None`` returns the behavior - of raising an HTTP exception to that of Pyramid 1.0 (the exception will - propagate to middleware and to the WSGI server). + ``exceptionresponse_view``. By default, this argument is populated with a + default exception view function that will be used when a response is raised + as an exception. When ``None`` is passed for this value, an exception view + for responses will not be registered. Passing ``None`` returns the + behavior of raising an HTTP exception to that of Pyramid 1.0 (the exception + will propagate to middleware and to the WSGI server). + +- The ``pyramid.request.Request`` class now has a ``ResponseClass`` interface + which points at ``pyramid.response.Response``. + +- The ``pyramid.request.Response`` class now has a ``RequestClass`` interface + which points at ``pyramid.response.Request``. Bug Fixes --------- @@ -289,6 +296,12 @@ Behavior Changes implements its own ``__getattr__``, ``__setattr__`` or ``__delattr__`` as a result. +- ``pyramid.response.Response`` is now a *subclass* of + ``webob.response.Response``. It also inherits from the built-in Python + ``Exception`` class and implements the + ``pyramid.interfaces.IExceptionResponse`` class so it can be raised as an + exception from view code. + Dependencies ------------ diff --git a/pyramid/__init__.py b/pyramid/__init__.py index 5f6a326f8..473d5e1c6 100644 --- a/pyramid/__init__.py +++ b/pyramid/__init__.py @@ -1,2 +1,5 @@ -# pyramid package - +from pyramid.request import Request +from pyramid.response import Response +Response.RequestClass = Request +Request.ResponseClass = Response +del Request, Response diff --git a/pyramid/config.py b/pyramid/config.py index 1013456ec..ce5201ed3 100644 --- a/pyramid/config.py +++ b/pyramid/config.py @@ -260,12 +260,13 @@ class Configurator(object): If ``exceptionresponse_view`` is passed, it must be a :term:`view callable` or ``None``. If it is a view callable, it will be used as an exception view callable when an :term:`exception response` is raised (any - named exception from the ``pyramid.exceptions`` module that begins with - ``HTTP`` as well as the ``NotFound`` and ``Forbidden`` exceptions) as - well as exceptions raised via :func:`pyramid.exceptions.abort`, - :func:`pyramid.exceptions.redirect`. If ``exceptionresponse_view`` is - ``None``, no exception response view will be registered, and all - raised exception responses will be bubbled up to Pyramid's caller. By + object that implements the :class:`pyramid.interaces.IExceptionResponse` + interface, such as a :class:`pyramid.response.Response` object or any + ``HTTP`` exception documented in :mod:`pyramid.httpexceptions` as well as + exception responses raised via :func:`pyramid.exceptions.abort`, + :func:`pyramid.exceptions.redirect`). If ``exceptionresponse_view`` is + ``None``, no exception response view will be registered, and all raised + exception responses will be bubbled up to Pyramid's caller. By default, the ``pyramid.exceptions.default_exceptionresponse_view`` function is used as the ``exceptionresponse_view``. This argument is new in Pyramid 1.1. """ diff --git a/pyramid/exceptions.py b/pyramid/exceptions.py index c1af43692..678529c1e 100644 --- a/pyramid/exceptions.py +++ b/pyramid/exceptions.py @@ -128,7 +128,8 @@ def _no_escape(value): value = str(value) return value -class HTTPException(Exception): + +class HTTPException(Exception): # bw compat pass class WSGIHTTPException(Response, HTTPException): @@ -1040,7 +1041,6 @@ def default_exceptionresponse_view(context, request): # config.set_notfound_view or config.set_forbidden_view # instead of as a proper exception view context = request.exception or context - # WSGIHTTPException, a Response (2.5+) return context status_map={} diff --git a/pyramid/response.py b/pyramid/response.py index 26f27b142..e9f5528a5 100644 --- a/pyramid/response.py +++ b/pyramid/response.py @@ -1,2 +1,8 @@ -from webob import Response -Response = Response # pyflakes +from webob import Response as _Response +from zope.interface import implements + +from pyramid.interfaces import IExceptionResponse + +class Response(_Response, Exception): + implements(IExceptionResponse) + |
