summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2013-08-30 12:18:57 -0400
committerChris McDonough <chrism@plope.com>2013-08-30 12:19:10 -0400
commitc5ed5491e8a6d736bedba45b2cb944799f36a5e4 (patch)
tree931b32f598cf4685dbf8b173743401a2182b0dd1
parent97ed56d766298ee042305ff8712df5f1fc3fbe3a (diff)
downloadpyramid-c5ed5491e8a6d736bedba45b2cb944799f36a5e4.tar.gz
pyramid-c5ed5491e8a6d736bedba45b2cb944799f36a5e4.tar.bz2
pyramid-c5ed5491e8a6d736bedba45b2cb944799f36a5e4.zip
add HTTPSuccessful base class, allowing HTTPOk to be caught independently; closes #986
-rw-r--r--CHANGES.txt15
-rw-r--r--pyramid/httpexceptions.py30
2 files changed, 33 insertions, 12 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 334785424..b3c4e6a60 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,13 @@ Next Release
Features
--------
+- A new http exception subclass named ``pyramid.httpexceptions.HTTPSuccessful``
+ was added. You can use this class as the ``context`` of an exception
+ view to catch all 200-series "exceptions" (e.g. "raise HTTPOk"). This
+ also allows you to catch *only* the ``HTTPOk`` exception itself; previously
+ this was impossible because a number of other exceptions
+ (such as ``HTTPNoContent``) inherited from ``HTTPOk``, but now they do not.
+
- You can now generate "hybrid" urldispatch/traversal URLs more easily
by using the new ``route_name``, ``route_kw`` and ``route_remainder_name``
arguments to ``request.resource_url`` and ``request.resource_path``. See
@@ -923,6 +930,14 @@ Backwards Incompatibilities
finished callbacks are executed. This is in support of the
``request.invoke_subrequest`` feature.
+- The 200-series exception responses named ``HTTPCreated``, ``HTTPAccepted``,
+ ``HTTPNonAuthoritativeInformation``, ``HTTPNoContent``, ``HTTPResetContent``,
+ and ``HTTPPartialContent`` in ``pyramid.httpexceptions`` no longer inherit
+ from ``HTTPOk``. Instead they inherit from a new base class named
+ ``HTTPSuccessful``. This will have no effect on you unless you've registered
+ an exception view for ``HTTPOk`` and expect that exception view to
+ catch all the aforementioned exceptions.
+
Documentation
-------------
diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py
index 10568b26e..fca4157b5 100644
--- a/pyramid/httpexceptions.py
+++ b/pyramid/httpexceptions.py
@@ -13,7 +13,7 @@ and 500s are server errors.
Exception
HTTPException
- HTTPOk
+ HTTPSuccessful
* 200 - HTTPOk
* 201 - HTTPCreated
* 202 - HTTPAccepted
@@ -306,21 +306,27 @@ class HTTPRedirection(HTTPException):
condition.
"""
-class HTTPOk(HTTPException):
+class HTTPSuccessful(HTTPException):
"""
Base class for exceptions with status codes in the 200s (successful
responses)
-
- code: 200, title: OK
"""
- code = 200
- title = 'OK'
############################################################
## 2xx success
############################################################
-class HTTPCreated(HTTPOk):
+class HTTPOk(HTTPSuccessful):
+ """
+ Base class for exceptions with status codes in the 200s (successful
+ responses)
+
+ code: 200, title: OK
+ """
+ code = 200
+ title = 'OK'
+
+class HTTPCreated(HTTPSuccessful):
"""
subclass of :class:`~HTTPOk`
@@ -332,7 +338,7 @@ class HTTPCreated(HTTPOk):
code = 201
title = 'Created'
-class HTTPAccepted(HTTPOk):
+class HTTPAccepted(HTTPSuccessful):
"""
subclass of :class:`~HTTPOk`
@@ -345,7 +351,7 @@ class HTTPAccepted(HTTPOk):
title = 'Accepted'
explanation = 'The request is accepted for processing.'
-class HTTPNonAuthoritativeInformation(HTTPOk):
+class HTTPNonAuthoritativeInformation(HTTPSuccessful):
"""
subclass of :class:`~HTTPOk`
@@ -358,7 +364,7 @@ class HTTPNonAuthoritativeInformation(HTTPOk):
code = 203
title = 'Non-Authoritative Information'
-class HTTPNoContent(HTTPOk):
+class HTTPNoContent(HTTPSuccessful):
"""
subclass of :class:`~HTTPOk`
@@ -372,7 +378,7 @@ class HTTPNoContent(HTTPOk):
title = 'No Content'
empty_body = True
-class HTTPResetContent(HTTPOk):
+class HTTPResetContent(HTTPSuccessful):
"""
subclass of :class:`~HTTPOk`
@@ -386,7 +392,7 @@ class HTTPResetContent(HTTPOk):
title = 'Reset Content'
empty_body = True
-class HTTPPartialContent(HTTPOk):
+class HTTPPartialContent(HTTPSuccessful):
"""
subclass of :class:`~HTTPOk`