From cbfafba1514ce2ce2b87aadb0093c06210219372 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 17 Nov 2009 21:59:54 +0000 Subject: Move configuration methods into Configurator. --- repoze/bfg/urldispatch.py | 52 ++++++++--------------------------------------- 1 file changed, 9 insertions(+), 43 deletions(-) (limited to 'repoze/bfg/urldispatch.py') diff --git a/repoze/bfg/urldispatch.py b/repoze/bfg/urldispatch.py index 7b0d4dbb7..7fff130ef 100644 --- a/repoze/bfg/urldispatch.py +++ b/repoze/bfg/urldispatch.py @@ -1,10 +1,6 @@ import re from urllib import unquote -from zope.interface import alsoProvides - -from repoze.bfg.interfaces import IRouteRequest - from repoze.bfg.compat import all from repoze.bfg.encode import url_quote from repoze.bfg.traversal import traversal_path @@ -20,9 +16,8 @@ class Route(object): self.factory = factory self.predicates = predicates -class RoutesRootFactory(object): - def __init__(self, default_root_factory): - self.default_root_factory = default_root_factory +class RoutesMapper(object): + def __init__(self): self.routelist = [] self.routes = {} @@ -42,34 +37,13 @@ class RoutesRootFactory(object): return self.routes[name].generate(kw) def __call__(self, request): + environ = request.environ + registry = request.registry try: - # As of BFG 1.1a9, a root factory is now typically called - # with a request object (instead of a WSGI environ, as in - # previous versions) by the router. Simultaneously, as of - # 1.1a9, the RoutesRootFactory *requires* that the object - # passed to it be a request, instead of an environ, as it - # uses both the ``registry`` attribute of the request, and - # if a route is found, it decorates the object with an - # interface using alsoProvides. However, existing app - # code "in the wild" calls the root factory explicitly - # with a dictionary argument (e.g. a subscriber to - # WSGIApplicationCreatedEvent does - # ``app.root_factory({})``). It makes no sense for such - # code to depend on the side effects of a - # RoutesRootFactory, for bw compat purposes we catch the - # exception that will be raised when passed a dictionary - # and just return the result of the default root factory. - environ = request.environ - registry = request.registry - except AttributeError: - return self.default_root_factory(request) - - try: - path = environ['PATH_INFO'] + # empty if mounted under a path in mod_wsgi, for example + path = environ['PATH_INFO'] or '/' except KeyError: path = '/' - if not path: # empty if mounted under a path in mod_wsgi, for example - path = '/' for route in self.routelist: match = route.match(path) @@ -77,17 +51,9 @@ class RoutesRootFactory(object): preds = route.predicates if preds and not all((p(None, request) for p in preds)): continue - environ['wsgiorg.routing_args'] = ((), match) - environ['bfg.routes.route'] = route - environ['bfg.routes.matchdict'] = match - request.matchdict = match - iface = registry.queryUtility(IRouteRequest, name=route.name) - if iface is not None: - alsoProvides(request, iface) - factory = route.factory or self.default_root_factory - return factory(request) - - return self.default_root_factory(request) + return {'route':route, 'match':match} + + return {'route':None, 'match':None} # stolen from bobo and modified route_re = re.compile(r'(/:[a-zA-Z]\w*)') -- cgit v1.2.3