From bda1306749c62ef4f11cfe567ed7d56c8ad94240 Mon Sep 17 00:00:00 2001 From: Michael Merickel <github@m.merickel.org> Date: Mon, 15 Oct 2018 16:56:42 +0200 Subject: [PATCH] Merge pull request #3388 from mmerickel/black --- src/pyramid/scripts/pviews.py | 76 +++++++++++++++++-------------------- 1 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/pyramid/scripts/pviews.py b/src/pyramid/scripts/pviews.py index c0df2f0..891dc47 100644 --- a/src/pyramid/scripts/pviews.py +++ b/src/pyramid/scripts/pviews.py @@ -9,9 +9,11 @@ from pyramid.scripts.common import parse_vars from pyramid.view import _find_views + def main(argv=sys.argv, quiet=False): command = PViewsCommand(argv, quiet) return command.run() + class PViewsCommand(object): description = """\ @@ -31,38 +33,41 @@ parser = argparse.ArgumentParser( description=textwrap.dedent(description), formatter_class=argparse.RawDescriptionHelpFormatter, - ) + ) - parser.add_argument('config_uri', - nargs='?', - default=None, - help='The URI to the configuration file.') + parser.add_argument( + 'config_uri', + nargs='?', + default=None, + help='The URI to the configuration file.', + ) - parser.add_argument('url', - nargs='?', - default=None, - help='The path info portion of the URL.') + parser.add_argument( + 'url', + nargs='?', + default=None, + help='The path info portion of the URL.', + ) parser.add_argument( 'config_vars', nargs='*', default=(), help="Variables required by the config file. For example, " - "`http_port=%%(http_port)s` would expect `http_port=8080` to be " - "passed here.", - ) + "`http_port=%%(http_port)s` would expect `http_port=8080` to be " + "passed here.", + ) - - bootstrap = staticmethod(bootstrap) # testing - setup_logging = staticmethod(setup_logging) # testing + bootstrap = staticmethod(bootstrap) # testing + setup_logging = staticmethod(setup_logging) # testing def __init__(self, argv, quiet=False): self.quiet = quiet self.args = self.parser.parse_args(argv[1:]) - def out(self, msg): # pragma: no cover + def out(self, msg): # pragma: no cover if not self.quiet: print(msg) - + def _find_multi_routes(self, mapper, request): infos = [] path = request.environ['PATH_INFO'] @@ -70,7 +75,7 @@ for route in mapper.get_routes(): match = route.match(path) if match is not None: - info = {'match':match, 'route':route} + info = {'match': match, 'route': route} infos.append(info) return infos @@ -99,22 +104,17 @@ @implementer(IMultiView) class RoutesMultiView(object): - def __init__(self, infos, context_iface, root_factory, request): self.views = [] for info in infos: match, route = info['match'], info['route'] if route is not None: request_iface = registry.queryUtility( - IRouteRequest, - name=route.name, - default=IRequest) + IRouteRequest, name=route.name, default=IRequest + ) views = _find_views( - request.registry, - request_iface, - context_iface, - '' - ) + request.registry, request_iface, context_iface, '' + ) if not views: continue view = views[0] @@ -148,9 +148,8 @@ attrs['matched_route'] = route request.environ['bfg.routes.matchdict'] = match request_iface = registry.queryUtility( - IRouteRequest, - name=route.name, - default=IRequest) + IRouteRequest, name=route.name, default=IRequest + ) root_factory = route.factory or root_factory if len(infos) > 1: routes_multiview = infos @@ -171,11 +170,8 @@ context_iface = providedBy(context) if routes_multiview is None: views = _find_views( - request.registry, - request_iface, - context_iface, - view_name, - ) + request.registry, request_iface, context_iface, view_name + ) if views: view = views[0] else: @@ -186,11 +182,8 @@ # routes are not registered with a view name if view is None: views = _find_views( - request.registry, - request_iface, - context_iface, - '', - ) + request.registry, request_iface, context_iface, '' + ) if views: view = views[0] else: @@ -285,5 +278,6 @@ env['closer']() return 0 -if __name__ == '__main__': # pragma: no cover + +if __name__ == '__main__': # pragma: no cover sys.exit(main() or 0) -- Gitblit v1.9.3