From 6fec211488f87f9207fda9c39b21e83c6359c727 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 23 Nov 2009 04:51:35 +0000 Subject: - The ``repoze.bfg.scripting.get_root`` API now uses a 'real' WebOb request rather than a FakeRequest when it sets up the request as a threadlocal. - The ``repoze.bfg.traversal.traverse`` API now uses a 'real' WebOb request rather than a FakeRequest when it calls the traverser. - The ``repoze.bfg.request.FakeRequest`` class has been removed. ``repoze.bfg.url.route_url`` ``repoze.bfg.url.model_url`` ``repoze.bfg.url.static_url`` ``repoze.bfg.traversal.virtual_root`` Each of these functions now expects to be called with a request object that has a ``registry`` attribute which represents the current ZCA registry. Get rid of extraneous uses of ZCA threadlocal API. --- repoze/bfg/url.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'repoze/bfg/url.py') diff --git a/repoze/bfg/url.py b/repoze/bfg/url.py index a39069642..51e1b109e 100644 --- a/repoze/bfg/url.py +++ b/repoze/bfg/url.py @@ -2,9 +2,6 @@ import os -from zope.component import getUtility -from zope.component import queryMultiAdapter - from repoze.lru import lru_cache from repoze.bfg.interfaces import IContextURL @@ -13,8 +10,9 @@ from repoze.bfg.interfaces import IRoutesMapper from repoze.bfg.encode import urlencode from repoze.bfg.path import caller_package from repoze.bfg.static import StaticRootFactory -from repoze.bfg.traversal import TraversalContextURL +from repoze.bfg.threadlocal import get_current_registry from repoze.bfg.traversal import quote_path_segment +from repoze.bfg.traversal import TraversalContextURL def route_url(route_name, request, *elements, **kw): """Generates a fully qualified URL for a named BFG route. @@ -89,7 +87,11 @@ def route_url(route_name, request, *elements, **kw): due to missing replacement names. Extra replacement names are ignored. """ - mapper = getUtility(IRoutesMapper) + try: + reg = request.registry + except AttributeError: + reg = get_current_registry() # b/c + mapper = reg.getUtility(IRoutesMapper) path = mapper.generate(route_name, kw) # raises KeyError if generate fails anchor = '' @@ -195,8 +197,12 @@ def model_url(model, request, *elements, **kw): will always follow the query element, e.g. ``http://example.com?foo=1#bar``. """ + try: + reg = request.registry + except AttributeError: + reg = get_current_registry() # b/c - context_url = queryMultiAdapter((model, request), IContextURL) + context_url = reg.queryMultiAdapter((model, request), IContextURL) if context_url is None: context_url = TraversalContextURL(model, request) model_url = context_url() @@ -263,8 +269,13 @@ def static_url(path, request, **kw): # to the package in which the caller's module is defined. package = caller_package(level=2) path = '%s:%s' % (package.__name__, path) + + try: + reg = request.registry + except AttributeError: + reg = get_current_registry() # b/c - mapper = getUtility(IRoutesMapper) + mapper = reg.getUtility(IRoutesMapper) routes = mapper.get_routes() for route in routes: -- cgit v1.2.3