summaryrefslogtreecommitdiff
path: root/repoze/bfg/view.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2010-04-25 18:49:29 +0000
committerChris McDonough <chrism@agendaless.com>2010-04-25 18:49:29 +0000
commit30e64f38f3a01d71f8a728df9d56f31d950ebd20 (patch)
treeebfdc1c832713e2ea737794fe090b766d3422407 /repoze/bfg/view.py
parent36ca7c9f7f1b177d69be792f98fda054d7c36c45 (diff)
downloadpyramid-30e64f38f3a01d71f8a728df9d56f31d950ebd20.tar.gz
pyramid-30e64f38f3a01d71f8a728df9d56f31d950ebd20.tar.bz2
pyramid-30e64f38f3a01d71f8a728df9d56f31d950ebd20.zip
Make default_notfound_view and default_forbidden_view expect an exception as
a context. Cause append_slash_notfound_view to work in case it is registered via set_notfound_view.
Diffstat (limited to 'repoze/bfg/view.py')
-rw-r--r--repoze/bfg/view.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/repoze/bfg/view.py b/repoze/bfg/view.py
index f88d8e973..d794f74d3 100644
--- a/repoze/bfg/view.py
+++ b/repoze/bfg/view.py
@@ -512,8 +512,8 @@ class bfg_view(object):
def default_view(context, request, status):
try:
- msg = cgi.escape(request.environ['repoze.bfg.message'])
- except KeyError:
+ msg = cgi.escape('%s' % context.args[0])
+ except Exception:
msg = ''
html = """
<html>
@@ -526,12 +526,12 @@ def default_view(context, request, status):
""" % (status, status, msg)
headers = [('Content-Length', str(len(html))),
('Content-Type', 'text/html')]
- response_factory = Response
- registry = getattr(request, 'registry', None)
- if registry is not None:
- # be kind to old tests
- response_factory = registry.queryUtility(IResponseFactory,
- default=Response)
+ try:
+ registry = request.registry
+ except AttributeError:
+ registry = get_current_registry()
+ response_factory = registry.queryUtility(IResponseFactory,
+ default=Response)
return response_factory(status = status,
headerlist = headers,
app_iter = [html])
@@ -558,21 +558,27 @@ def append_slash_notfound_view(context, request):
If you use :term:`ZCML`, add the following to your application's
``configure.zcml`` to use this view as the Not Found view::
- <notfound
+ <view
+ context="repoze.bfg.exceptions.NotFound"
view="repoze.bfg.view.append_slash_notfound_view"/>
Or use the
- :meth:`repoze.bfg.configuration.Configurator.set_notfound_view`
+ :meth:`repoze.bfg.configuration.Configurator.add_view`
method if you don't use ZCML::
+ from repoze.bfg.exceptions import NotFound
from repoze.bfg.view import append_slash_notfound_view
- config.set_notfound_view(append_slash_notfound_view)
+ config.add_view(append_slash_notfound_view, context=NotFound)
See also :ref:`changing_the_notfound_view`.
.. note:: This function is new as of :mod:`repoze.bfg` version 1.1.
"""
+ if not isinstance(context, Exception):
+ # backwards compat for an append_notslash_view registered via
+ # config.set_notfound_view instead of as a proper exception view
+ context = getattr(request, 'exception', None)
path = request.environ.get('PATH_INFO', '/')
registry = request.registry
mapper = registry.queryUtility(IRoutesMapper)