From 0c29cf2df41600d3906d521c72991c7686018b71 Mon Sep 17 00:00:00 2001 From: Michael Merickel <michael@merickel.org> Date: Mon, 15 Oct 2018 16:24:07 +0200 Subject: [PATCH] format source using black --- src/pyramid/view.py | 100 ++++++++++++++++++++++++++++---------------------- 1 files changed, 56 insertions(+), 44 deletions(-) diff --git a/src/pyramid/view.py b/src/pyramid/view.py index 7693283..c45b976 100644 --- a/src/pyramid/view.py +++ b/src/pyramid/view.py @@ -13,30 +13,25 @@ IViewClassifier, IRequest, IExceptionViewClassifier, - ) +) from pyramid.compat import decode_path_info from pyramid.compat import reraise as reraise_ -from pyramid.exceptions import ( - ConfigurationError, - PredicateMismatch, -) +from pyramid.exceptions import ConfigurationError, PredicateMismatch from pyramid.httpexceptions import ( HTTPNotFound, HTTPTemporaryRedirect, default_exceptionresponse_view, - ) +) -from pyramid.threadlocal import ( - get_current_registry, - manager, - ) +from pyramid.threadlocal import get_current_registry, manager from pyramid.util import hide_attrs _marker = object() + def render_view_to_response(context, request, name='', secure=True): """ Call the :term:`view callable` configured with a :term:`view @@ -84,9 +79,9 @@ name, secure=secure, request_iface=request_iface, - ) + ) - return response # NB: might be None + return response # NB: might be None def render_view_to_iterable(context, request, name='', secure=True): @@ -119,6 +114,7 @@ return None return response.app_iter + def render_view(context, request, name='', secure=True): """ Call the :term:`view callable` configured with a :term:`view configuration` that matches the :term:`view name` ``name`` @@ -145,6 +141,7 @@ if iterable is None: return None return b''.join(iterable) + class view_config(object): """ A function, class or method :term:`decorator` which allows a @@ -213,7 +210,9 @@ because of the limitation of ``venusian.Scanner.scan``. """ - venusian = venusian # for testing injection + + venusian = venusian # for testing injection + def __init__(self, **settings): if 'for_' in settings: if settings.get('context') is None: @@ -229,8 +228,9 @@ config = context.config.with_package(info.module) config.add_view(view=ob, **settings) - info = self.venusian.attach(wrapped, callback, category=category, - depth=depth + 1) + info = self.venusian.attach( + wrapped, callback, category=category, depth=depth + 1 + ) if info.scope == 'class': # if the decorator was attached to a method in a class, or @@ -239,10 +239,12 @@ if settings.get('attr') is None: settings['attr'] = wrapped.__name__ - settings['_info'] = info.codeinfo # fbo "action_method" + settings['_info'] = info.codeinfo # fbo "action_method" return wrapped -bfg_view = view_config # bw compat (forever) + +bfg_view = view_config # bw compat (forever) + class view_defaults(view_config): """ A class :term:`decorator` which, when applied to a class, will @@ -256,6 +258,7 @@ def __call__(self, wrapped): wrapped.__view_defaults__ = self.__dict__.copy() return wrapped + class AppendSlashNotFoundViewFactory(object): """ There can only be one :term:`Not Found view` in any @@ -292,7 +295,10 @@ .. deprecated:: 1.3 """ - def __init__(self, notfound_view=None, redirect_class=HTTPTemporaryRedirect): + + def __init__( + self, notfound_view=None, redirect_class=HTTPTemporaryRedirect + ): if notfound_view is None: notfound_view = default_exceptionresponse_view self.notfound_view = notfound_view @@ -309,8 +315,11 @@ qs = request.query_string if qs: qs = '?' + qs - return self.redirect_class(location=request.path + '/' + qs) + return self.redirect_class( + location=request.path + '/' + qs + ) return self.notfound_view(context, request) + append_slash_notfound_view = AppendSlashNotFoundViewFactory() append_slash_notfound_view.__doc__ = """\ @@ -336,6 +345,7 @@ .. deprecated:: 1.3 """ + class notfound_view_config(object): """ @@ -417,8 +427,9 @@ config = context.config.with_package(info.module) config.add_notfound_view(view=ob, **settings) - info = self.venusian.attach(wrapped, callback, category=category, - depth=depth + 1) + info = self.venusian.attach( + wrapped, callback, category=category, depth=depth + 1 + ) if info.scope == 'class': # if the decorator was attached to a method in a class, or @@ -427,8 +438,9 @@ if settings.get('attr') is None: settings['attr'] = wrapped.__name__ - settings['_info'] = info.codeinfo # fbo "action_method" + settings['_info'] = info.codeinfo # fbo "action_method" return wrapped + class forbidden_view_config(object): """ @@ -479,8 +491,9 @@ config = context.config.with_package(info.module) config.add_forbidden_view(view=ob, **settings) - info = self.venusian.attach(wrapped, callback, category=category, - depth=depth + 1) + info = self.venusian.attach( + wrapped, callback, category=category, depth=depth + 1 + ) if info.scope == 'class': # if the decorator was attached to a method in a class, or @@ -489,8 +502,9 @@ if settings.get('attr') is None: settings['attr'] = wrapped.__name__ - settings['_info'] = info.codeinfo # fbo "action_method" + settings['_info'] = info.codeinfo # fbo "action_method" return wrapped + class exception_view_config(object): """ @@ -526,6 +540,7 @@ Added the ``_depth`` and ``_category`` arguments. """ + venusian = venusian def __init__(self, *args, **settings): @@ -545,8 +560,9 @@ config = context.config.with_package(info.module) config.add_exception_view(view=ob, **settings) - info = self.venusian.attach(wrapped, callback, category=category, - depth=depth + 1) + info = self.venusian.attach( + wrapped, callback, category=category, depth=depth + 1 + ) if info.scope == 'class': # if the decorator was attached to a method in a class, or @@ -555,8 +571,9 @@ if settings.get('attr') is None: settings['attr'] = wrapped.__name__ - settings['_info'] = info.codeinfo # fbo "action_method" + settings['_info'] = info.codeinfo # fbo "action_method" return wrapped + def _find_views( registry, @@ -565,7 +582,7 @@ view_name, view_types=None, view_classifier=None, - ): +): if view_types is None: view_types = (IView, ISecuredView, IMultiView) if view_classifier is None: @@ -581,9 +598,7 @@ source_ifaces = (view_classifier, req_type, ctx_type) for view_type in view_types: view_callable = registered( - source_ifaces, - view_type, - name=view_name, + source_ifaces, view_type, name=view_name ) if view_callable is not None: views.append(view_callable) @@ -599,6 +614,7 @@ return views + def _call_view( registry, request, @@ -609,7 +625,7 @@ view_classifier=None, secure=True, request_iface=None, - ): +): if request_iface is None: request_iface = getattr(request, 'request_iface', IRequest) view_callables = _find_views( @@ -619,7 +635,7 @@ view_name, view_types=view_types, view_classifier=view_classifier, - ) + ) pme = None response = None @@ -631,10 +647,8 @@ # the view will have a __call_permissive__ attribute if it's # secured; otherwise it won't. view_callable = getattr( - view_callable, - '__call_permissive__', - view_callable - ) + view_callable, '__call_permissive__', view_callable + ) # if this view is secured, it will raise a Forbidden # appropriately if the executing user does not have the proper @@ -649,15 +663,13 @@ return response + class ViewMethodsMixin(object): """ Request methods mixin for BaseRequest having to do with executing views """ + def invoke_exception_view( - self, - exc_info=None, - request=None, - secure=True, - reraise=False, + self, exc_info=None, request=None, secure=True, reraise=False ): """ Executes an exception view related to the request it's called upon. The arguments it takes are these: @@ -742,7 +754,7 @@ view_classifier=IExceptionViewClassifier, secure=secure, request_iface=request_iface.combined, - ) + ) except Exception: if reraise: reraise_(*exc_info) -- Gitblit v1.9.3