summaryrefslogtreecommitdiff
path: root/repoze/bfg/router.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-06-18 21:49:33 +0000
committerChris McDonough <chrism@agendaless.com>2009-06-18 21:49:33 +0000
commitf5c25ef97393f7b4bf1353b11eeb841c53e2feaf (patch)
tree7c820aaa1a769dfc096aed05c50116821e89707a /repoze/bfg/router.py
parent7687344b77fbc9c4bf998d20828b10a339b90eed (diff)
downloadpyramid-f5c25ef97393f7b4bf1353b11eeb841c53e2feaf.tar.gz
pyramid-f5c25ef97393f7b4bf1353b11eeb841c53e2feaf.tar.bz2
pyramid-f5c25ef97393f7b4bf1353b11eeb841c53e2feaf.zip
- Allow views to be *optionally* defined as callables that accept only
a request object, instead of both a context and a request (which still works, and always will). The following types work as views in this style: - functions that accept a single argument ``request``, e.g.:: def aview(request): pass - new and old-style classes that have an ``__init__`` method that accepts ``self, request``, e.g.:: def View(object): __init__(self, request): pass - Arbitrary callables that have a ``__call__`` method that accepts ``self, request``, e.g.:: def AView(object): def __call__(self, request): pass view = AView() This likely should have been the calling convention all along, as the request has ``context`` as an attribute already, and with views called as a result of URL dispatch, having the context in the arguments is not very useful. C'est la vie.
Diffstat (limited to 'repoze/bfg/router.py')
-rw-r--r--repoze/bfg/router.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/repoze/bfg/router.py b/repoze/bfg/router.py
index a5bea3f69..d85f599b2 100644
--- a/repoze/bfg/router.py
+++ b/repoze/bfg/router.py
@@ -2,6 +2,7 @@ from cgi import escape
import sys
from webob import Response
+from zope.interface import providedBy
from zope.component.event import dispatch
from zope.component import queryUtility
@@ -205,16 +206,15 @@ class Router(object):
msg = str(permitted)
else:
msg = 'Unauthorized: failed security policy check'
-
environ['repoze.bfg.message'] = msg
-
return respond(self.forbidden_view(context, request),
'<IForbiddenView>')
- response = registry.queryMultiAdapter(
- (context, request), IView, name=view_name)
+ view_callable = registry.adapters.lookup(
+ map(providedBy, (context, request)), IView, name=view_name,
+ default=None)
- if response is None:
+ if view_callable is None:
if self.debug_notfound:
msg = (
'debug_notfound of url %s; path_info: %r, context: %r, '
@@ -230,6 +230,7 @@ class Router(object):
return respond(self.notfound_view(context, request),
'<INotFoundView>')
+ response = view_callable(context, request)
return respond(response, view_name)
finally: