diff options
| -rw-r--r-- | CHANGES.txt | 11 | ||||
| -rw-r--r-- | docs/api.rst | 1 | ||||
| -rw-r--r-- | docs/api/httpexceptions.rst | 98 | ||||
| -rw-r--r-- | docs/narr/views.rst | 11 | ||||
| -rw-r--r-- | docs/narr/webob.rst | 27 | ||||
| -rw-r--r-- | docs/tutorials/wiki/definingviews.rst | 10 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/authorization/tutorial/login.py | 2 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/authorization/tutorial/views.py | 2 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/viewdecorators/tutorial/views.py | 2 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/views/tutorial/views.py | 2 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/definingviews.rst | 4 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/authorization/tutorial/login.py | 3 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/authorization/tutorial/views.py | 3 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/views/tutorial/views.py | 3 | ||||
| -rw-r--r-- | pyramid/httpexceptions.py | 115 |
15 files changed, 202 insertions, 92 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index ef5c89373..cf40de0e6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,17 @@ Next release ============ +Features (delta from BFG 1.3.X) +------------------------------- + +- Add ``pyramid.httpexceptions`` module, which is a facade for the + ``webob.exc`` module. + +Documentation (delta from BFG 1.3) +----------------------------------- + +- Added a ``pyramid.httpexceptions`` API documentation chapter. + Backwards Incompatibilities (with BFG 1.3.X) -------------------------------------------- diff --git a/docs/api.rst b/docs/api.rst index 5bd24d6b2..a4d853942 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -15,6 +15,7 @@ documentation is organized alphabetically by module name. api/configuration api/events api/exceptions + api/httpexceptions api/i18n api/interfaces api/location diff --git a/docs/api/httpexceptions.rst b/docs/api/httpexceptions.rst new file mode 100644 index 000000000..57ca8092c --- /dev/null +++ b/docs/api/httpexceptions.rst @@ -0,0 +1,98 @@ +.. _httpexceptions_module: + +:mod:`pyramid.httpexceptions` +-------------------------------- + +.. automodule:: pyramid.httpexceptions + + .. attribute:: status_map + + A mapping of integer status code to exception class (eg. the + integer "401" maps to + :class:`pyramid.httpexceptions.HTTPUnauthorized`). + + .. autoclass:: HTTPException + + .. autoclass:: HTTPOk + + .. autoclass:: HTTPRedirection + + .. autoclass:: HTTPError + + .. autoclass:: HTTPClientError + + .. autoclass:: HTTPServerError + + .. autoclass:: HTTPCreated + + .. autoclass:: HTTPAccepted + + .. autoclass:: HTTPNonAuthoritativeInformation + + .. autoclass:: HTTPNoContent + + .. autoclass:: HTTPResetContent + + .. autoclass:: HTTPPartialContent + + .. autoclass:: HTTPMultipleChoices + + .. autoclass:: HTTPMovedPermanently + + .. autoclass:: HTTPFound + + .. autoclass:: HTTPSeeOther + + .. autoclass:: HTTPNotModified + + .. autoclass:: HTTPUseProxy + + .. autoclass:: HTTPTemporaryRedirect + + .. autoclass:: HTTPBadRequest + + .. autoclass:: HTTPUnauthorized + + .. autoclass:: HTTPPaymentRequired + + .. autoclass:: HTTPForbidden + + .. autoclass:: HTTPNotFound + + .. autoclass:: HTTPMethodNotAllowed + + .. autoclass:: HTTPNotAcceptable + + .. autoclass:: HTTPProxyAuthenticationRequired + + .. autoclass:: HTTPRequestTimeout + + .. autoclass:: HTTPConflict + + .. autoclass:: HTTPGone + + .. autoclass:: HTTPLengthRequired + + .. autoclass:: HTTPPreconditionFailed + + .. autoclass:: HTTPRequestEntityTooLarge + + .. autoclass:: HTTPRequestURITooLong + + .. autoclass:: HTTPUnsupportedMediaType + + .. autoclass:: HTTPRequestRangeNotSatisfiable + + .. autoclass:: HTTPExpectationFailed + + .. autoclass:: HTTPInternalServerError + + .. autoclass:: HTTPNotImplemented + + .. autoclass:: HTTPBadGateway + + .. autoclass:: HTTPServiceUnavailable + + .. autoclass:: HTTPGatewayTimeout + + .. autoclass:: HTTPVersionNotSupported diff --git a/docs/narr/views.rst b/docs/narr/views.rst index f52df9557..2969487d3 100644 --- a/docs/narr/views.rst +++ b/docs/narr/views.rst @@ -298,16 +298,17 @@ particular kind of response. .. code-block:: python :linenos: - from webob.exc import HTTPFound + from pyramid.httpexceptions import HTTPFound def myview(request): return HTTPFound(location='http://example.com') All exception types from the :mod:`webob.exc` module implement the -Webob :term:`Response` interface; any can be returned as the response -from a view. See :term:`WebOb` for the documentation for this module; -it includes other response types that imply other HTTP response codes, -such as ``401 Unauthorized``. +WebOb :term:`Response` interface; any can be returned as the response +from a view. See :mod:`pyramid.httpexceptions` for the documentation +for the ``HTTPFound`` exception; it also includes other response types +that imply other HTTP response codes, such as ``HTTPUnauthorized`` for +``401 Unauthorized``. .. index:: single: renderer diff --git a/docs/narr/webob.rst b/docs/narr/webob.rst index 82416a44d..b3bec882e 100644 --- a/docs/narr/webob.rst +++ b/docs/narr/webob.rst @@ -309,20 +309,23 @@ default to anything, though if you subclass ``Response`` and set Exceptions ++++++++++ -To facilitate error responses like 404 Not Found, the module -``webob.exc`` contains classes for each kind of error response. These -include boring but appropriate error bodies. - -Each class is named ``webob.exc.HTTP*``, where ``*`` is the reason for -the error. For instance, ``webob.exc.HTTPNotFound``. It subclasses -``Response``, so you can manipulate the instances in the same way. A -typical example is: +To facilitate error responses like ``404 Not Found``, the module +:mod:`webob.exc` contains classes for each kind of error response. +These include boring but appropriate error bodies. The exceptions +exposed by this module, when used under :mod:`pyramid`, should be +imported from the :mod:`pyramid.httpexceptions` "facade" module. + +Each class is named ``pyramid.httpexceptions.HTTP*``, where ``*`` is +the reason for the error. For instance, +``pyramid.httpexceptions.HTTPNotFound``. It subclasses ``Response``, +so you can manipulate the instances in the same way. A typical +example is: .. ignore-next-block .. code-block:: python - from webob.exc import HTTPNotFound - from webob.exc import HTTPMovedPermanently + from pyramid.httpexceptions import HTTPNotFound + from pyramid.httpexceptions import HTTPMovedPermanently response = HTTPNotFound('There is no such resource') # or: @@ -336,8 +339,8 @@ You can use this like: .. code-block:: python :linenos: - from webob.exc import HTTPException - from webob.exc import HTTPNotFound + from pyramid.httpexceptions import HTTPException + from pyramid.httpexceptions import HTTPNotFound def aview(request): try: diff --git a/docs/tutorials/wiki/definingviews.rst b/docs/tutorials/wiki/definingviews.rst index f4d92371a..41a9ad373 100644 --- a/docs/tutorials/wiki/definingviews.rst +++ b/docs/tutorials/wiki/definingviews.rst @@ -54,11 +54,11 @@ The ``view_wiki`` view function The ``view_wiki`` function will be configured to respond as the default view of a ``Wiki`` model object. It always redirects to the ``Page`` object named "FrontPage". It returns an instance of the -:class:`webob.exc.HTTPFound` class (instances of which implement the -WebOb :term:`response` interface), and the -:func:`pyramid.url.model_url` API. -:func:`pyramid.url.model_url` constructs a URL to the ``FrontPage`` -page (e.g. ``http://localhost:6543/FrontPage``), and uses it as the +:class:`pyramid.httpexceptions.HTTPFound` class (instances of which +implement the WebOb :term:`response` interface), and the +:func:`pyramid.url.model_url` API. :func:`pyramid.url.model_url` +constructs a URL to the ``FrontPage`` page +(e.g. ``http://localhost:6543/FrontPage``), and uses it as the "location" of the HTTPFound response, forming an HTTP redirect. The ``view_page`` view function diff --git a/docs/tutorials/wiki/src/authorization/tutorial/login.py b/docs/tutorials/wiki/src/authorization/tutorial/login.py index c029f25ce..ee67d9a5e 100644 --- a/docs/tutorials/wiki/src/authorization/tutorial/login.py +++ b/docs/tutorials/wiki/src/authorization/tutorial/login.py @@ -1,4 +1,4 @@ -from webob.exc import HTTPFound +from pyramid.httpexceptions import HTTPFound from pyramid.view import bfg_view from pyramid.url import model_url diff --git a/docs/tutorials/wiki/src/authorization/tutorial/views.py b/docs/tutorials/wiki/src/authorization/tutorial/views.py index f0fef5d81..8c35afcd6 100644 --- a/docs/tutorials/wiki/src/authorization/tutorial/views.py +++ b/docs/tutorials/wiki/src/authorization/tutorial/views.py @@ -1,7 +1,7 @@ from docutils.core import publish_parts import re -from webob.exc import HTTPFound +from pyramid.httpexceptions import HTTPFound from pyramid.url import model_url from pyramid.security import authenticated_userid diff --git a/docs/tutorials/wiki/src/viewdecorators/tutorial/views.py b/docs/tutorials/wiki/src/viewdecorators/tutorial/views.py index 60cb49faa..937a67344 100644 --- a/docs/tutorials/wiki/src/viewdecorators/tutorial/views.py +++ b/docs/tutorials/wiki/src/viewdecorators/tutorial/views.py @@ -1,7 +1,7 @@ from docutils.core import publish_parts import re -from webob.exc import HTTPFound +from pyramid.httpexceptions import HTTPFound from pyramid.url import model_url from pyramid.view import bfg_view diff --git a/docs/tutorials/wiki/src/views/tutorial/views.py b/docs/tutorials/wiki/src/views/tutorial/views.py index f13ed0381..acc1bbb57 100644 --- a/docs/tutorials/wiki/src/views/tutorial/views.py +++ b/docs/tutorials/wiki/src/views/tutorial/views.py @@ -1,7 +1,7 @@ from docutils.core import publish_parts import re -from webob.exc import HTTPFound +from pyramid.httpexceptions import HTTPFound from pyramid.url import model_url from tutorial.models import Page diff --git a/docs/tutorials/wiki2/definingviews.rst b/docs/tutorials/wiki2/definingviews.rst index 1bba7efea..559e6df2f 100644 --- a/docs/tutorials/wiki2/definingviews.rst +++ b/docs/tutorials/wiki2/definingviews.rst @@ -85,8 +85,8 @@ The ``view_wiki`` view function The ``view_wiki`` function will respond as the :term:`default view` of a ``Wiki`` model object. It always redirects to a URL which represents the path to our "FrontPage". It returns an instance of the -:class:`webob.exc.HTTPFound` class (instances of which implement the -WebOb :term:`response` interface), It will use the +:class:`pyramid.httpexceptions.HTTPFound` class (instances of which +implement the WebOb :term:`response` interface), It will use the :func:`pyramid.url.route_url` API to construct a URL to the ``FrontPage`` page (e.g. ``http://localhost:6543/FrontPage``), and will use it as the "location" of the HTTPFound response, forming an diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/login.py b/docs/tutorials/wiki2/src/authorization/tutorial/login.py index 1a54d575c..7a1d1f663 100644 --- a/docs/tutorials/wiki2/src/authorization/tutorial/login.py +++ b/docs/tutorials/wiki2/src/authorization/tutorial/login.py @@ -1,5 +1,4 @@ -from webob.exc import HTTPFound - +from pyramid.httpexceptions import HTTPFound from pyramid.security import remember from pyramid.security import forget from pyramid.url import route_url diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/views.py b/docs/tutorials/wiki2/src/authorization/tutorial/views.py index a7e7a57c7..5abd8391e 100644 --- a/docs/tutorials/wiki2/src/authorization/tutorial/views.py +++ b/docs/tutorials/wiki2/src/authorization/tutorial/views.py @@ -2,8 +2,7 @@ import re from docutils.core import publish_parts -from webob.exc import HTTPFound - +from pyramid.httpexceptions import HTTPFound from pyramid.security import authenticated_userid from pyramid.url import route_url diff --git a/docs/tutorials/wiki2/src/views/tutorial/views.py b/docs/tutorials/wiki2/src/views/tutorial/views.py index c0d793d38..b8896abe7 100644 --- a/docs/tutorials/wiki2/src/views/tutorial/views.py +++ b/docs/tutorials/wiki2/src/views/tutorial/views.py @@ -2,8 +2,7 @@ import re from docutils.core import publish_parts -from webob.exc import HTTPFound - +from pyramid.httpexceptions import HTTPFound from pyramid.url import route_url from tutorial.models import DBSession diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py index 440b88a85..130c3ee8d 100644 --- a/pyramid/httpexceptions.py +++ b/pyramid/httpexceptions.py @@ -1,66 +1,66 @@ -"""HTTP Exceptions +"""HTTP Exceptions. -HTTP Exceptions can be returned from handlers and views, or when using Python -2.5+ may be raised as normal (Python 2.4 doesn't support raising new-style -class exceptions). +HTTP Exceptions can be returned from handlers and views (they are +valid :term:`Response` objects). -All HTTP Exceptions are sub-classes of HTTPException, with additional -sub-classes for each of the major types of HTTP Response. For example, all -200-class HTTP exceptions sub-class HTTPOk, which sub-classes HTTPException. +All HTTP exceptions are sub-classes of HTTPException, with additional +sub-classes for each of the major types of HTTP response. For example, +all 200-class HTTP exceptions sub-class HTTPOk, which sub-classes +HTTPException. -A status_map dict is also provided, which allows for key based access to -exception objects by the HTTP status code. +A status_map dict is also provided, which allows for key based access +to exception objects by the HTTP status code. The exceptions are ordered into a class hierarchy based on status code -divisions to allow for capturing of various types of HTTP exceptions as -well. +divisions to allow for capturing of various types of HTTP exceptions +as well:: -Exception - HTTPException - HTTPOk - * 200 - HTTPOk - * 201 - HTTPCreated - * 202 - HTTPAccepted - * 203 - HTTPNonAuthoritativeInformation - * 204 - HTTPNoContent - * 205 - HTTPResetContent - * 206 - HTTPPartialContent - HTTPRedirection - * 300 - HTTPMultipleChoices - * 301 - HTTPMovedPermanently - * 302 - HTTPFound - * 303 - HTTPSeeOther - * 304 - HTTPNotModified - * 305 - HTTPUseProxy - * 306 - Unused (not implemented, obviously) - * 307 - HTTPTemporaryRedirect - HTTPError - HTTPClientError - * 400 - HTTPBadRequest - * 401 - HTTPUnauthorized - * 402 - HTTPPaymentRequired - * 403 - HTTPForbidden - * 404 - HTTPNotFound - * 405 - HTTPMethodNotAllowed - * 406 - HTTPNotAcceptable - * 407 - HTTPProxyAuthenticationRequired - * 408 - HTTPRequestTimeout - * 409 - HTTPConflict - * 410 - HTTPGone - * 411 - HTTPLengthRequired - * 412 - HTTPPreconditionFailed - * 413 - HTTPRequestEntityTooLarge - * 414 - HTTPRequestURITooLong - * 415 - HTTPUnsupportedMediaType - * 416 - HTTPRequestRangeNotSatisfiable - * 417 - HTTPExpectationFailed - HTTPServerError - * 500 - HTTPInternalServerError - * 501 - HTTPNotImplemented - * 502 - HTTPBadGateway - * 503 - HTTPServiceUnavailable - * 504 - HTTPGatewayTimeout - * 505 - HTTPVersionNotSupported + Exception + HTTPException + HTTPOk + * 200 - HTTPOk + * 201 - HTTPCreated + * 202 - HTTPAccepted + * 203 - HTTPNonAuthoritativeInformation + * 204 - HTTPNoContent + * 205 - HTTPResetContent + * 206 - HTTPPartialContent + HTTPRedirection + * 300 - HTTPMultipleChoices + * 301 - HTTPMovedPermanently + * 302 - HTTPFound + * 303 - HTTPSeeOther + * 304 - HTTPNotModified + * 305 - HTTPUseProxy + * 306 - Unused (not implemented, obviously) + * 307 - HTTPTemporaryRedirect + HTTPError + HTTPClientError + * 400 - HTTPBadRequest + * 401 - HTTPUnauthorized + * 402 - HTTPPaymentRequired + * 403 - HTTPForbidden + * 404 - HTTPNotFound + * 405 - HTTPMethodNotAllowed + * 406 - HTTPNotAcceptable + * 407 - HTTPProxyAuthenticationRequired + * 408 - HTTPRequestTimeout + * 409 - HTTPConflict + * 410 - HTTPGone + * 411 - HTTPLengthRequired + * 412 - HTTPPreconditionFailed + * 413 - HTTPRequestEntityTooLarge + * 414 - HTTPRequestURITooLong + * 415 - HTTPUnsupportedMediaType + * 416 - HTTPRequestRangeNotSatisfiable + * 417 - HTTPExpectationFailed + HTTPServerError + * 500 - HTTPInternalServerError + * 501 - HTTPNotImplemented + * 502 - HTTPBadGateway + * 503 - HTTPServiceUnavailable + * 504 - HTTPGatewayTimeout + * 505 - HTTPVersionNotSupported """ from webob.exc import status_map @@ -74,7 +74,6 @@ from webob.exc import HTTPClientError from webob.exc import HTTPServerError # Child classes -from webob.exc import HTTPOk from webob.exc import HTTPCreated from webob.exc import HTTPAccepted from webob.exc import HTTPNonAuthoritativeInformation |
