summaryrefslogtreecommitdiff
path: root/repoze/bfg/urldispatch.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-11-17 21:59:54 +0000
committerChris McDonough <chrism@agendaless.com>2009-11-17 21:59:54 +0000
commitcbfafba1514ce2ce2b87aadb0093c06210219372 (patch)
tree41e83cf95cf4cf8920396e644a219518689e8b89 /repoze/bfg/urldispatch.py
parenta937e7d039f2c9e62e1a2771b2e6b23412ab709a (diff)
downloadpyramid-cbfafba1514ce2ce2b87aadb0093c06210219372.tar.gz
pyramid-cbfafba1514ce2ce2b87aadb0093c06210219372.tar.bz2
pyramid-cbfafba1514ce2ce2b87aadb0093c06210219372.zip
Move configuration methods into Configurator.
Diffstat (limited to 'repoze/bfg/urldispatch.py')
-rw-r--r--repoze/bfg/urldispatch.py52
1 files changed, 9 insertions, 43 deletions
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*)')