diff options
| author | Chris McDonough <chrism@plope.com> | 2015-04-06 05:32:47 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2015-04-06 05:32:47 -0400 |
| commit | eb3ac8e33b0fe516fb6cf8d27061eff6dec1afc2 (patch) | |
| tree | 38c8b5ce9a48225c6e367c9a82dbddef70b5d99e | |
| parent | e028e0a6fbb0050a007236721277b2fa62a00e5c (diff) | |
| download | pyramid-eb3ac8e33b0fe516fb6cf8d27061eff6dec1afc2.tar.gz pyramid-eb3ac8e33b0fe516fb6cf8d27061eff6dec1afc2.tar.bz2 pyramid-eb3ac8e33b0fe516fb6cf8d27061eff6dec1afc2.zip | |
break out _call_view into separate importable callable for use in scripts
| -rw-r--r-- | pyramid/router.py | 52 | ||||
| -rw-r--r-- | pyramid/view.py | 26 |
2 files changed, 47 insertions, 31 deletions
diff --git a/pyramid/router.py b/pyramid/router.py index 9ce5d2487..4054ef52e 100644 --- a/pyramid/router.py +++ b/pyramid/router.py @@ -22,10 +22,9 @@ from pyramid.events import ( NewResponse, ) -from pyramid.exceptions import PredicateMismatch from pyramid.httpexceptions import HTTPNotFound from pyramid.request import Request -from pyramid.view import _find_views +from pyramid.view import _call_view from pyramid.request import apply_request_extensions from pyramid.threadlocal import manager @@ -138,40 +137,31 @@ class Router(object): # find a view callable context_iface = providedBy(context) - view_callables = _find_views( + response = _call_view( registry, - request.request_iface, + request, + context, context_iface, - view_name, + view_name ) - pme = None + if response is None: + if self.debug_notfound: + msg = ( + 'debug_notfound of url %s; path_info: %r, ' + 'context: %r, view_name: %r, subpath: %r, ' + 'traversed: %r, root: %r, vroot: %r, ' + 'vroot_path: %r' % ( + request.url, request.path_info, context, + view_name, subpath, traversed, root, vroot, + vroot_path) + ) + logger and logger.debug(msg) + else: + msg = request.path_info + raise HTTPNotFound(msg) - for view_callable in view_callables: - # look for views that meet the predicate criteria - try: - response = view_callable(context, request) - return response - except PredicateMismatch as _pme: - pme = _pme - - if pme is not None: - raise pme - - if self.debug_notfound: - msg = ( - 'debug_notfound of url %s; path_info: %r, ' - 'context: %r, view_name: %r, subpath: %r, ' - 'traversed: %r, root: %r, vroot: %r, ' - 'vroot_path: %r' % ( - request.url, request.path_info, context, - view_name, subpath, traversed, root, vroot, - vroot_path) - ) - logger and logger.debug(msg) - else: - msg = request.path_info - raise HTTPNotFound(msg) + return response def invoke_subrequest(self, request, use_tweens=False): """Obtain a response object from the Pyramid application based on diff --git a/pyramid/view.py b/pyramid/view.py index 127122a36..8565cd875 100644 --- a/pyramid/view.py +++ b/pyramid/view.py @@ -16,6 +16,8 @@ from pyramid.compat import ( decode_path_info, ) +from pyramid.exceptions import PredicateMismatch + from pyramid.httpexceptions import ( HTTPFound, default_exceptionresponse_view, @@ -446,3 +448,27 @@ def _find_views(registry, request_iface, context_iface, view_name): with registry._lock: cache[(request_iface, context_iface, view_name)] = views return views + +def _call_view(registry, request, context, context_iface, view_name): + view_callables = _find_views( + registry, + request.request_iface, + context_iface, + view_name, + ) + + pme = None + response = None + + for view_callable in view_callables: + # look for views that meet the predicate criteria + try: + response = view_callable(context, request) + return response + except PredicateMismatch as _pme: + pme = _pme + + if pme is not None: + raise pme + + return response |
