summaryrefslogtreecommitdiff
path: root/repoze/bfg/configuration.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2010-08-08 07:25:28 +0000
committerChris McDonough <chrism@agendaless.com>2010-08-08 07:25:28 +0000
commitd96ff9144f98bb44254f77f56e55967c46b09774 (patch)
tree7cabc160ce28460ebffd70a5e419f1c74178bd96 /repoze/bfg/configuration.py
parent9192964c9ccc4b0c1c2f1948af1b62012a11ef7c (diff)
downloadpyramid-d96ff9144f98bb44254f77f56e55967c46b09774.tar.gz
pyramid-d96ff9144f98bb44254f77f56e55967c46b09774.tar.bz2
pyramid-d96ff9144f98bb44254f77f56e55967c46b09774.zip
- New public interface: ``repoze.bfg.exceptions.IExceptionResponse``.
This interface is provided by all internal exception classes (such as ``repoze.bfg.exceptions.NotFound`` and ``repoze.bfg.exceptions.Forbidden``), instances of which are both exception objects and can behave as WSGI response objects. This interface is made public so that exception classes which are also valid WSGI response factories can be configured to implement them or exception instances which are also or response instances can be configured to provide them. - New API class: ``repoze.bfg.view.AppendSlashNotFoundViewFactory`` (undoes previous custom_notfound_view on request passsed to append_slash_notfound_view). - Previously, two default view functions were registered at Configurator setup (one for ``repoze.bfg.exceptions.NotFound`` named ``default_notfound_view`` and one for ``repoze.bfg.exceptions.Forbidden`` named ``default_forbidden_view``) to render internal exception responses. Those default view functions have been removed, replaced with a generic default view function which is registered at Configurator setup for the ``repoze.bfg.interfaces.IExceptionResponse`` interface that simply returns the exception instance; the ``NotFound` and ``Forbidden`` classes are now still exception factories but they are also response factories which generate instances that implement the new ``repoze.bfg.interfaces.IExceptionResponse`` interface.
Diffstat (limited to 'repoze/bfg/configuration.py')
-rw-r--r--repoze/bfg/configuration.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/repoze/bfg/configuration.py b/repoze/bfg/configuration.py
index f694d7737..0ab4abcb5 100644
--- a/repoze/bfg/configuration.py
+++ b/repoze/bfg/configuration.py
@@ -38,6 +38,8 @@ from repoze.bfg.interfaces import ITranslationDirectories
from repoze.bfg.interfaces import ITraverser
from repoze.bfg.interfaces import IView
from repoze.bfg.interfaces import IViewClassifier
+from repoze.bfg.interfaces import IExceptionResponse
+from repoze.bfg.interfaces import IException
from repoze.bfg import chameleon_text
from repoze.bfg import chameleon_zpt
@@ -69,8 +71,7 @@ from repoze.bfg.traversal import DefaultRootFactory
from repoze.bfg.traversal import find_interface
from repoze.bfg.urldispatch import RoutesMapper
from repoze.bfg.view import render_view_to_response
-from repoze.bfg.view import default_notfound_view
-from repoze.bfg.view import default_forbidden_view
+from repoze.bfg.view import default_exceptionresponse_view
MAX_ORDER = 1 << 30
DEFAULT_PHASH = md5().hexdigest()
@@ -408,8 +409,8 @@ class Configurator(object):
authorization_policy)
for name, renderer in renderers:
self.add_renderer(name, renderer)
- self.add_view(default_notfound_view, context=NotFound)
- self.add_view(default_forbidden_view, context=Forbidden)
+ self.add_view(default_exceptionresponse_view,
+ context=IExceptionResponse)
if locale_negotiator:
registry.registerUtility(locale_negotiator, ILocaleNegotiator)
if request_factory:
@@ -2312,8 +2313,12 @@ def _attr_wrap(view, accept, order, phash):
return attr_view
def isexception(o):
- return isinstance(o, Exception) or (
- inspect.isclass(o) and issubclass(o, Exception)
+ if IInterface.providedBy(o):
+ if IException.isEqualOrExtendedBy(o):
+ return True
+ return (
+ isinstance(o, Exception) or
+ (inspect.isclass(o) and (issubclass(o, Exception)))
)
# note that ``options`` is a b/w compat alias for ``settings`` and