From 1c02105e4fce880bca80e58be3191d2e1368596a Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 19 Nov 2009 18:21:09 +0000 Subject: - Each of the ``repoze.bfg.view.render_view``, ``repoze.bfg.view.render_view_to_iterable``, ``repoze.bfg.view.render_view_to_response``, ``repoze.bfg.view.append_slash_notfound_view``, ``repoze.bfg.view.default_notfound_view``, ``repoze.bfg.view.default_forbidden_view``, and the ``repoze.bfg.configuration.rendered_response`` functions now expects to be called with a request object that has a ``registry`` attribute which represents the current ZCA registry. This should only be a problem when passing a custom request object to code which ends up calling these functions in a unit test. To retrofit tests that end up calling these functions which expect to be able to use a non-registry-aware request object, use the ``repoze.bfg.threadlocal.get_current_request`` API in the test to create the request; this will return a ``repoze.bfg.testing.DummyRequest`` that has the current registry as its ``registry`` attribute. Alternatively, use the ``repoze.bfg.threadlocal.get_current_registry`` API: call this function and add an attribute to your unit test request object named ``registry`` with the result. - The ``repoze.bfg.view.derive_view`` callable has been removed. Use ``repoze.bfg.configuration.Configurator.derive_view`` instead (still not an API, however). --- repoze/bfg/zcml.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'repoze/bfg/zcml.py') diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py index 6cbea96df..7d6e2a14b 100644 --- a/repoze/bfg/zcml.py +++ b/repoze/bfg/zcml.py @@ -24,7 +24,6 @@ from repoze.bfg.authentication import RepozeWho1AuthenticationPolicy from repoze.bfg.authentication import RemoteUserAuthenticationPolicy from repoze.bfg.authentication import AuthTktAuthenticationPolicy from repoze.bfg.authorization import ACLAuthorizationPolicy -from repoze.bfg.configuration import Configurator from repoze.bfg.path import package_name from repoze.bfg.request import route_request_iface from repoze.bfg.resource import resource_spec @@ -168,7 +167,7 @@ def view( renderer = resource_spec(renderer, zcml_package) def register(): - config = Configurator(reg) + config = get_configurator(reg) config.view( permission=permission, for_=for_, view=view, name=name, request_type=request_type, route_name=route_name, @@ -248,7 +247,7 @@ def route(_context, name, path, view=None, view_for=None, view_renderer = resource_spec(view_renderer, zcml_package) def register(): - config = Configurator(reg) + config = get_configurator(reg) config.route( name, path, @@ -327,7 +326,7 @@ class SystemViewHandler(object): def register(iface=self.iface): reg = get_current_registry() - config = Configurator(reg) + config = get_configurator(reg) config.system_view(iface, view=view, attr=attr, renderer=renderer, wrapper=wrapper, _info=_context.info) @@ -380,7 +379,7 @@ def resource(_context, to_override, override_with): 'at the end of to_override if necessary)') reg = get_current_registry() - config = Configurator(reg) + config = get_configurator(reg) _context.action( discriminator = None, @@ -400,7 +399,7 @@ def repozewho1authenticationpolicy(_context, identifier_name='auth_tkt', # authentication policies must be registered eagerly so they can # be found by the view registration machinery reg = get_current_registry() - config = Configurator(reg) + config = get_configurator(reg) config.authentication_policy(policy, _info=_context.info) _context.action(discriminator=IAuthenticationPolicy) @@ -416,7 +415,7 @@ def remoteuserauthenticationpolicy(_context, environ_key='REMOTE_USER', # authentication policies must be registered eagerly so they can # be found by the view registration machinery reg = get_current_registry() - config = Configurator(reg) + config = get_configurator(reg) config.authentication_policy(policy, _info=_context.info) _context.action(discriminator=IAuthenticationPolicy) @@ -454,7 +453,7 @@ def authtktauthenticationpolicy(_context, # authentication policies must be registered eagerly so they can # be found by the view registration machinery reg = get_current_registry() - config = Configurator(reg) + config = get_configurator(reg) config.authentication_policy(policy, _info=_context.info) _context.action(discriminator=IAuthenticationPolicy) @@ -466,7 +465,7 @@ def aclauthorizationpolicy(_context): # authorization policies must be registered eagerly so they can be # found by the view registration machinery reg = get_current_registry() - config = Configurator(reg) + config = get_configurator(reg) config.authorization_policy(policy, _info=_context.info) _context.action(discriminator=IAuthorizationPolicy) @@ -483,7 +482,7 @@ def renderer(_context, factory, name=''): # renderer factories must be registered eagerly so they can be # found by the view machinery reg = get_current_registry() - config = Configurator(reg) + config = get_configurator(reg) config.renderer(factory, name, _info=_context.info) _context.action(discriminator=(IRendererFactory, name)) @@ -524,7 +523,7 @@ def scan(_context, package, martian=martian): # martian overrideable only for unit tests def register(): reg = get_current_registry() - config = Configurator(reg) + config = get_configurator(reg) config.scan(package, _info=_context.info, martian=martian) _context.action(discriminator=None, callable=register) @@ -548,3 +547,13 @@ def zcml_configure(name, package): file_configure = zcml_configure # backwards compat (>0.8.1) +def get_configurator(reg): + # dont create a new configurator instance unless necessary, as + # frames will point to each configurator instance via closures + # when some configuration methods (such as config.view) are + # called. + from repoze.bfg.configuration import Configurator + config = reg.get('bfg_configurator') + if config is None: + config = Configurator(reg) + return config -- cgit v1.2.3