diff options
| -rw-r--r-- | pyramid/configuration.py | 351 | ||||
| -rw-r--r-- | pyramid/registry.py | 17 | ||||
| -rw-r--r-- | pyramid/static.py | 2 | ||||
| -rw-r--r-- | pyramid/tests/test_configuration.py | 10 | ||||
| -rw-r--r-- | pyramid/tests/test_static.py | 1 | ||||
| -rw-r--r-- | pyramid/tests/test_testing.py | 1 | ||||
| -rw-r--r-- | pyramid/tests/test_zcml.py | 152 | ||||
| -rw-r--r-- | pyramid/zcml.py | 190 |
8 files changed, 343 insertions, 381 deletions
diff --git a/pyramid/configuration.py b/pyramid/configuration.py index 29a322c7f..5122b5964 100644 --- a/pyramid/configuration.py +++ b/pyramid/configuration.py @@ -10,7 +10,6 @@ from translationstring import ChameleonTranslate from zope.configuration import xmlconfig from zope.configuration.config import ConfigurationMachine -from zope.configuration.xmlconfig import registerCommonDirectives from zope.interface import Interface from zope.interface import implementedBy @@ -100,6 +99,15 @@ if chameleon_text: if chameleon_zpt: DEFAULT_RENDERERS += (('.txt', chameleon_text.renderer_factory),) +def config_method(wrapped): + def wrapper(self, *arg, **kw): + result = wrapped(self, *arg, **kw) + if self.registry.autocommit: + self.commit() + return result + wrapper.__doc__ = wrapped.__doc__ + wrapper.__name__ = wrapped.__name__ + return wrapper class Configurator(object): """ @@ -227,6 +235,7 @@ class Configurator(object): renderer_globals_factory=None, default_permission=None, session_factory=None, + autocommit = True, ): if package is None: package = caller_package() @@ -250,6 +259,7 @@ class Configurator(object): renderer_globals_factory=renderer_globals_factory, default_permission=default_permission, session_factory=session_factory, + autocommit=autocommit, ) def _set_settings(self, mapping): @@ -257,6 +267,7 @@ class Configurator(object): self.registry.settings = settings return settings + @config_method def _set_root_factory(self, factory): """ Add a :term:`root factory` to the current configuration state. If the ``factory`` argument is ``None`` a default root @@ -264,23 +275,32 @@ class Configurator(object): factory = self.maybe_dotted(factory) if factory is None: factory = DefaultRootFactory - self.registry.registerUtility(factory, IRootFactory) - self.registry.registerUtility(factory, IDefaultRootFactory) # b/c + def register(): + self.registry.registerUtility(factory, IRootFactory) + self.registry.registerUtility(factory, IDefaultRootFactory) # b/c + self.action(IRootFactory, register) - def _set_authentication_policy(self, policy, _info=u''): + @config_method + def _set_authentication_policy(self, policy): """ Add a :app:`Pyramid` :term:`authentication policy` to the current configuration.""" policy = self.maybe_dotted(policy) + _info = self.ctx_info() self.registry.registerUtility(policy, IAuthenticationPolicy, info=_info) + self.action(IAuthenticationPolicy, None) - def _set_authorization_policy(self, policy, _info=u''): + @config_method + def _set_authorization_policy(self, policy): """ Add a :app:`Pyramid` :term:`authorization policy` to the current configuration state (also accepts a :term:`dotted Python name`.""" policy = self.maybe_dotted(policy) - self.registry.registerUtility(policy, IAuthorizationPolicy, info=_info) - + _info = self.ctx_info() + self.registry.registerUtility(policy, IAuthorizationPolicy, + info=_info) + self.action(IAuthorizationPolicy, None) + def _make_spec(self, path_or_spec): package, filename = resolve_resource_spec(path_or_spec, self.package_name) @@ -317,16 +337,17 @@ class Configurator(object): return derived_view def _override(self, package, path, override_package, override_prefix, - _info=u'', PackageOverrides=PackageOverrides): - pkg_name = package.__name__ - override_pkg_name = override_package.__name__ - override = self.registry.queryUtility( - IPackageOverrides, name=pkg_name) - if override is None: - override = PackageOverrides(package) - self.registry.registerUtility(override, IPackageOverrides, - name=pkg_name, info=_info) - override.insert(path, override_pkg_name, override_prefix) + PackageOverrides=PackageOverrides): + pkg_name = package.__name__ + override_pkg_name = override_package.__name__ + override = self.registry.queryUtility( + IPackageOverrides, name=pkg_name) + _info = self.ctx_info() + if override is None: + override = PackageOverrides(package) + self.registry.registerUtility(override, IPackageOverrides, + name=pkg_name, info=_info) + override.insert(path, override_pkg_name, override_prefix) def _set_security_policies(self, authentication, authorization=None): if authorization is None: @@ -356,6 +377,12 @@ class Configurator(object): # API + def commit(self): + """ Commit the current set of configuration actions. """ + context = self.registry.ctx + context.execute_actions() + self.registry.reset_context() + def with_package(self, package): """ Return a new Configurator instance with the same registry as this configurator using the package supplied as the @@ -392,7 +419,8 @@ class Configurator(object): locale_negotiator=None, request_factory=None, renderer_globals_factory=None, default_permission=None, - session_factory=None): + session_factory=None, + autocommit=True): """ When you pass a non-``None`` ``registry`` argument to the :term:`Configurator` constructor, no initial 'setup' is performed against the registry. This is because the registry @@ -411,13 +439,14 @@ class Configurator(object): negotiator, and various other settings using the configurator's current registry, as per the descriptions in the Configurator constructor.""" + registry = self.registry + registry.autocommit = autocommit self._fix_registry() self._set_settings(settings) self._set_root_factory(root_factory) debug_logger = self.maybe_dotted(debug_logger) if debug_logger is None: debug_logger = make_stream_logger('pyramid.debug', sys.stderr) - registry = self.registry registry.registerUtility(debug_logger, IDebugLogger) if authentication_policy or authorization_policy: self._set_security_policies(authentication_policy, @@ -562,7 +591,17 @@ class Configurator(object): renderer = {'name':renderer, 'package':self.package} return self._derive_view(view, attr=attr, renderer=renderer) - def add_subscriber(self, subscriber, iface=None, info=u''): + def action(self, discriminator, callable, args=(), kw=None, order=0): + """ Register an action which will be executed during commit. """ + if kw is None: + kw = {} + self.registry.ctx.action(discriminator, callable, args, kw, order) + + def ctx_info(self): + return getattr(self.registry.ctx, 'info', '') + + @config_method + def add_subscriber(self, subscriber, iface=None): """Add an event :term:`subscriber` for the event stream implied by the supplied ``iface`` interface. The ``subscriber`` argument represents a callable object (or a @@ -581,7 +620,10 @@ class Configurator(object): iface = (Interface,) if not isinstance(iface, (tuple, list)): iface = (iface,) - self.registry.registerHandler(subscriber, iface, info=info) + info = self.ctx_info() + def register(): + self.registry.registerHandler(subscriber, iface, info=info) + self.action(None, register) return subscriber def add_settings(self, settings=None, **kw): @@ -659,17 +701,19 @@ class Configurator(object): package = sys.modules[package_name] lock.acquire() - self.manager.push({'registry':self.registry, 'request':None}) + registry = self.registry + self.manager.push({'registry':registry, 'request':None}) + context = registry.ctx + autocommit = registry.autocommit try: - context = ConfigurationMachine() - registerCommonDirectives(context) + registry.autocommit = False context.package = package - context.registry = self.registry xmlconfig.file(filename, package, context=context, execute=True) finally: lock.release() self.manager.pop() - return self.registry + registry.autocommit = autocommit + return registry def add_handler(self, route_name, pattern, handler, action=None, **kw): @@ -784,12 +828,13 @@ class Configurator(object): return route + @config_method def add_view(self, view=None, name="", for_=None, permission=None, request_type=None, route_name=None, request_method=None, request_param=None, containment=None, attr=None, renderer=None, wrapper=None, xhr=False, accept=None, header=None, path_info=None, custom_predicates=(), - context=None, _info=u''): + context=None): """ Add a :term:`view configuration` to the current configuration state. Arguments to ``add_view`` are broken down below into *predicate* arguments and *non-predicate* @@ -1073,7 +1118,6 @@ class Configurator(object): renderer=renderer, wrapper=wrapper, xhr=xhr, accept=accept, header=header, path_info=path_info, custom_predicates=custom_predicates, context=context, - _info=u'' ) view_info = deferred_views.setdefault(route_name, []) view_info.append(info) @@ -1092,11 +1136,6 @@ class Configurator(object): if renderer is not None and not isinstance(renderer, dict): renderer = {'name':renderer, 'package':self.package} - # NO_PERMISSION_REQUIRED handled by _secure_view - derived_view = self._derive_view(view, permission, predicates, attr, - renderer, wrapper, name, accept, - order, phash) - if context is None: context = for_ @@ -1106,102 +1145,120 @@ class Configurator(object): if not IInterface.providedBy(r_context): r_context = implementedBy(r_context) - registered = self.registry.adapters.registered + _info = self.ctx_info() - # A multiviews is a set of views which are registered for - # exactly the same context type/request type/name triad. Each - # consituent view in a multiview differs only by the - # predicates which it possesses. + def register(): - # To find a previously registered view for a context - # type/request type/name triad, we need to use the - # ``registered`` method of the adapter registry rather than - # ``lookup``. ``registered`` ignores interface inheritance - # for the required and provided arguments, returning only a - # view registered previously with the *exact* triad we pass - # in. + # NO_PERMISSION_REQUIRED handled by _secure_view + derived_view = self._derive_view(view, permission, predicates, attr, + renderer, wrapper, name, accept, + order, phash) - # We need to do this three times, because we use three - # different interfaces as the ``provided`` interface while - # doing registrations, and ``registered`` performs exact - # matches on all the arguments it receives. + registered = self.registry.adapters.registered - old_view = None + # A multiviews is a set of views which are registered for + # exactly the same context type/request type/name triad. Each + # consituent view in a multiview differs only by the + # predicates which it possesses. - for view_type in (IView, ISecuredView, IMultiView): - old_view = registered((IViewClassifier, request_iface, r_context), - view_type, name) - if old_view is not None: - break + # To find a previously registered view for a context + # type/request type/name triad, we need to use the + # ``registered`` method of the adapter registry rather than + # ``lookup``. ``registered`` ignores interface inheritance + # for the required and provided arguments, returning only a + # view registered previously with the *exact* triad we pass + # in. - isexc = isexception(context) + # We need to do this three times, because we use three + # different interfaces as the ``provided`` interface while + # doing registrations, and ``registered`` performs exact + # matches on all the arguments it receives. - def regclosure(): - if hasattr(derived_view, '__call_permissive__'): - view_iface = ISecuredView - else: - view_iface = IView - self.registry.registerAdapter( - derived_view, - (IViewClassifier, request_iface, context), - view_iface, name, info=_info) - if isexc: - self.registry.registerAdapter( - derived_view, - (IExceptionViewClassifier, request_iface, context), - view_iface, name, info=_info) + old_view = None - is_multiview = IMultiView.providedBy(old_view) - old_phash = getattr(old_view, '__phash__', DEFAULT_PHASH) + for view_type in (IView, ISecuredView, IMultiView): + old_view = registered((IViewClassifier, request_iface, + r_context), view_type, name) + if old_view is not None: + break - if old_view is None: - # - No component was yet registered for any of our I*View - # interfaces exactly; this is the first view for this - # triad. - regclosure() + isexc = isexception(context) - elif (not is_multiview) and (old_phash == phash): - # - A single view component was previously registered with - # the same predicate hash as this view; this registration - # is therefore an override. - regclosure() + def regclosure(): + if hasattr(derived_view, '__call_permissive__'): + view_iface = ISecuredView + else: + view_iface = IView + self.registry.registerAdapter( + derived_view, + (IViewClassifier, request_iface, context), + view_iface, name, info=_info) + if isexc: + self.registry.registerAdapter( + derived_view, + (IExceptionViewClassifier, request_iface, context), + view_iface, name, info=_info) + + is_multiview = IMultiView.providedBy(old_view) + old_phash = getattr(old_view, '__phash__', DEFAULT_PHASH) + + if old_view is None: + # - No component was yet registered for any of our I*View + # interfaces exactly; this is the first view for this + # triad. + regclosure() + + elif (not is_multiview) and (old_phash == phash): + # - A single view component was previously registered with + # the same predicate hash as this view; this registration + # is therefore an override. + regclosure() - else: - # - A view or multiview was already registered for this - # triad, and the new view is not an override. - - # XXX we could try to be more efficient here and register - # a non-secured view for a multiview if none of the - # multiview's consituent views have a permission - # associated with them, but this code is getting pretty - # rough already - if is_multiview: - multiview = old_view else: - multiview = MultiView(name) - old_accept = getattr(old_view, '__accept__', None) - old_order = getattr(old_view, '__order__', MAX_ORDER) - multiview.add(old_view, old_order, old_accept, old_phash) - multiview.add(derived_view, order, accept, phash) - for view_type in (IView, ISecuredView): - # unregister any existing views - self.registry.adapters.unregister( - (IViewClassifier, request_iface, r_context), - view_type, name=name) - if isexc: + # - A view or multiview was already registered for this + # triad, and the new view is not an override. + + # XXX we could try to be more efficient here and register + # a non-secured view for a multiview if none of the + # multiview's consituent views have a permission + # associated with them, but this code is getting pretty + # rough already + if is_multiview: + multiview = old_view + else: + multiview = MultiView(name) + old_accept = getattr(old_view, '__accept__', None) + old_order = getattr(old_view, '__order__', MAX_ORDER) + multiview.add(old_view, old_order, old_accept, old_phash) + multiview.add(derived_view, order, accept, phash) + for view_type in (IView, ISecuredView): + # unregister any existing views self.registry.adapters.unregister( - (IExceptionViewClassifier, request_iface, r_context), + (IViewClassifier, request_iface, r_context), view_type, name=name) - self.registry.registerAdapter( - multiview, - (IViewClassifier, request_iface, context), - IMultiView, name=name, info=_info) - if isexc: + if isexc: + self.registry.adapters.unregister( + (IExceptionViewClassifier, request_iface, + r_context), view_type, name=name) self.registry.registerAdapter( multiview, - (IExceptionViewClassifier, request_iface, context), + (IViewClassifier, request_iface, context), IMultiView, name=name, info=_info) - + if isexc: + self.registry.registerAdapter( + multiview, + (IExceptionViewClassifier, request_iface, context), + IMultiView, name=name, info=_info) + + discriminator = [ + 'view', context, name, request_type, IView, containment, + request_param, request_method, route_name, attr, + xhr, accept, header, path_info] + discriminator.extend(sorted(custom_predicates)) + discriminator = tuple(discriminator) + self.action(discriminator, register) + + @config_method def add_route(self, name, pattern=None, @@ -1225,8 +1282,7 @@ class Configurator(object): view_attr=None, use_global_views=False, path=None, - pregenerator=None, - _info=u''): + pregenerator=None): """ Add a :term:`route configuration` to the current configuration state, as well as possibly a :term:`view configuration` to be used to specify a :term:`view callable` @@ -1534,7 +1590,6 @@ class Configurator(object): route_name=name, renderer=view_renderer, attr=view_attr, - _info=_info, ) mapper = self.get_routes_mapper() @@ -1545,6 +1600,13 @@ class Configurator(object): if pattern is None: raise ConfigurationError('"pattern" argument may not be None') + discriminator = ['route', name, xhr, request_method, path_info, + request_param, header, accept] + discriminator.extend(sorted(custom_predicates)) + discriminator = tuple(discriminator) + + self.action(discriminator, None) + return mapper.connect(name, pattern, factory, predicates=predicates, pregenerator=pregenerator) @@ -1557,7 +1619,7 @@ class Configurator(object): self.registry.registerUtility(mapper, IRoutesMapper) return mapper - def scan(self, package=None, categories=None, _info=u''): + def scan(self, package=None, categories=None): """ Scan a Python package and any of its subpackages for objects marked with :term:`configuration decoration` such as :class:`pyramid.view.view_config`. Any decorated object found @@ -1590,9 +1652,16 @@ class Configurator(object): package = caller_package() scanner = self.venusian.Scanner(config=self) - scanner.scan(package, categories=categories) + autocommit = self.registry.autocommit + try: + self.registry.autocommit = False + scanner.scan(package, categories=categories) + finally: + self.registry.autocommit = autocommit + self.commit() - def add_renderer(self, name, factory, _info=u''): + @config_method + def add_renderer(self, name, factory): """ Add a :app:`Pyramid` :term:`renderer` factory to the current configuration state. @@ -1619,10 +1688,12 @@ class Configurator(object): if not name: name = '' self.registry.registerUtility( - factory, IRendererFactory, name=name, info=_info) + factory, IRendererFactory, name=name, info=self.ctx_info()) + self.action(('renderer', name), None) + @config_method def override_resource(self, to_override, override_with, - _info=u'', _override=None,): + _override=None,): """ Add a :app:`Pyramid` resource override to the current configuration state. @@ -1666,11 +1737,12 @@ class Configurator(object): override_package = sys.modules[override_package] override = _override or self._override # test jig - override(package, path, override_package, override_prefix, - _info=_info) + def register(): + override(package, path, override_package, override_prefix) + self.action(None, register) def set_forbidden_view(self, view=None, attr=None, renderer=None, - wrapper=None, _info=u''): + wrapper=None): """ Add a default forbidden view to the current configuration state. @@ -1703,11 +1775,10 @@ class Configurator(object): def bwcompat_view(context, request): context = getattr(request, 'context', None) return view(context, request) - return self.add_view(bwcompat_view, context=Forbidden, - wrapper=wrapper, _info=_info) + return self.add_view(bwcompat_view, context=Forbidden, wrapper=wrapper) def set_notfound_view(self, view=None, attr=None, renderer=None, - wrapper=None, _info=u''): + wrapper=None): """ Add a default not found view to the current configuration state. @@ -1742,9 +1813,9 @@ class Configurator(object): def bwcompat_view(context, request): context = getattr(request, 'context', None) return view(context, request) - return self.add_view(bwcompat_view, context=NotFound, - wrapper=wrapper, _info=_info) + return self.add_view(bwcompat_view, context=NotFound, wrapper=wrapper) + @config_method def set_request_factory(self, factory): """ The object passed as ``factory`` should be an object (or a :term:`dotted Python name` which refers to an object) which @@ -1759,8 +1830,11 @@ class Configurator(object): can be used to achieve the same purpose. """ factory = self.maybe_dotted(factory) - self.registry.registerUtility(factory, IRequestFactory) + def register(): + self.registry.registerUtility(factory, IRequestFactory) + self.action(IRequestFactory, register) + @config_method def set_renderer_globals_factory(self, factory): """ The object passed as ``factory`` should be an callable (or a :term:`dotted Python name` which refers to an callable) that @@ -1780,8 +1854,11 @@ class Configurator(object): can be used to achieve the same purpose. """ factory = self.maybe_dotted(factory) - self.registry.registerUtility(factory, IRendererGlobalsFactory) + def register(): + self.registry.registerUtility(factory, IRendererGlobalsFactory) + self.action(IRendererGlobalsFactory, register) + @config_method def set_locale_negotiator(self, negotiator): """ Set the :term:`locale negotiator` for this application. The @@ -1801,8 +1878,11 @@ class Configurator(object): can be used to achieve the same purpose. """ negotiator = self.maybe_dotted(negotiator) - self.registry.registerUtility(negotiator, ILocaleNegotiator) + def register(): + self.registry.registerUtility(negotiator, ILocaleNegotiator) + self.action(ILocaleNegotiator, register) + @config_method def set_default_permission(self, permission): """ Set the default permission to be used by all subsequent @@ -1829,16 +1909,22 @@ class Configurator(object): :class:`pyramid.configuration.Configurator` constructor can be used to achieve the same purpose. """ + # default permission used during view registration self.registry.registerUtility(permission, IDefaultPermission) + self.action(IDefaultPermission, None) + @config_method def set_session_factory(self, session_factory): """ Configure the application with a :term:`session factory`. If this method is called, the ``session_factory`` argument must be a session factory callable. """ - self.registry.registerUtility(session_factory, ISessionFactory) + def register(): + self.registry.registerUtility(session_factory, ISessionFactory) + self.action(ISessionFactory, register) + @config_method def add_translation_dirs(self, *specs): """ Add one or more :term:`translation directory` paths to the current configuration state. The ``specs`` argument is a @@ -1873,6 +1959,7 @@ class Configurator(object): self.registry.registerUtility(tdirs, ITranslationDirectories) tdirs.insert(0, directory) + self.action(('tdir', directory), None) if specs: diff --git a/pyramid/registry.py b/pyramid/registry.py index c772636aa..bad7eb603 100644 --- a/pyramid/registry.py +++ b/pyramid/registry.py @@ -1,5 +1,9 @@ from zope.component.registry import Components +from zope.configuration.config import ConfigurationMachine +from zope.configuration.xmlconfig import registerCommonDirectives + from pyramid.interfaces import ISettings +from pyramid.decorator import reify class Registry(Components, dict): """ A registry object is an :term:`application registry`. The existence @@ -21,6 +25,8 @@ class Registry(Components, dict): # to notify them has_listeners = False _settings = None + autocommit = False + _ctx = None def registerSubscriptionAdapter(self, *arg, **kw): result = Components.registerSubscriptionAdapter(self, *arg, **kw) @@ -48,4 +54,15 @@ class Registry(Components, dict): settings = property(_get_settings, _set_settings) + def reset_context(self): + context = ConfigurationMachine() + registerCommonDirectives(context) + context.registry = self # circdep + self.ctx = context + return context + + @reify + def ctx(self): + return self.reset_context() + global_registry = Registry('global') diff --git a/pyramid/static.py b/pyramid/static.py index 5b7c4b199..710ab4407 100644 --- a/pyramid/static.py +++ b/pyramid/static.py @@ -136,7 +136,6 @@ class StaticURLInfo(object): self.registrations.append((name, spec, True)) else: # it's a view name - _info = extra.pop('_info', None) cache_max_age = extra.pop('cache_max_age', None) view = static_view(spec, cache_max_age=cache_max_age) # register a route using this view @@ -148,7 +147,6 @@ class StaticURLInfo(object): view_for=self.__class__, view_permission=permission, factory=lambda *x: self, - _info=_info ) self.registrations.append((name, spec, False)) diff --git a/pyramid/tests/test_configuration.py b/pyramid/tests/test_configuration.py index 938db3c31..3fce18591 100644 --- a/pyramid/tests/test_configuration.py +++ b/pyramid/tests/test_configuration.py @@ -245,10 +245,14 @@ class ConfiguratorTests(unittest.TestCase): self.assertEqual(result, 'pyramid.tests:templates') def test_setup_registry_fixed(self): + from zope.configuration.config import ConfigurationMachine class DummyRegistry(object): + ctx = ConfigurationMachine() def subscribers(self, events, name): self.events = events return events + def reset_context(self): + self.context_reset = True def registerUtility(self, *arg, **kw): pass reg = DummyRegistry() @@ -258,13 +262,18 @@ class ConfiguratorTests(unittest.TestCase): self.assertEqual(reg.has_listeners, True) self.assertEqual(reg.notify(1), None) self.assertEqual(reg.events, (1,)) + self.assertEqual(reg.context_reset, True) def test_setup_registry_registers_default_exceptionresponse_view(self): from pyramid.interfaces import IExceptionResponse from pyramid.view import default_exceptionresponse_view + from zope.configuration.config import ConfigurationMachine class DummyRegistry(object): + ctx = ConfigurationMachine() def registerUtility(self, *arg, **kw): pass + def reset_context(self): + self.context_reset = True reg = DummyRegistry() config = self._makeOne(reg) views = [] @@ -272,6 +281,7 @@ class ConfiguratorTests(unittest.TestCase): config.setup_registry() self.assertEqual(views[0], ((default_exceptionresponse_view,), {'context':IExceptionResponse})) + self.assertEqual(reg.context_reset, True) def test_setup_registry_explicit_notfound_trumps_iexceptionresponse(self): from zope.interface import implementedBy diff --git a/pyramid/tests/test_static.py b/pyramid/tests/test_static.py index 81350504c..d92e5ddac 100644 --- a/pyramid/tests/test_static.py +++ b/pyramid/tests/test_static.py @@ -312,7 +312,6 @@ class TestStaticURLInfo(unittest.TestCase): expected = [('view/', 'anotherpackage:path/', False)] self.assertEqual(inst.registrations, expected) self.assertEqual(config.arg, ('view/', 'view/*subpath')) - self.assertEqual(config.kw['_info'], None) self.assertEqual(config.kw['view_for'], self._getTargetClass()) self.assertEqual(config.kw['factory'](), inst) self.assertEqual(config.kw['view_permission'], diff --git a/pyramid/tests/test_testing.py b/pyramid/tests/test_testing.py index f05e7fc01..adbbcb555 100644 --- a/pyramid/tests/test_testing.py +++ b/pyramid/tests/test_testing.py @@ -7,6 +7,7 @@ class TestBase(unittest.TestCase): from pyramid.registry import Registry manager.clear() registry = Registry('testing') + registry.autocommit = True self.registry = registry manager.push({'registry':registry, 'request':None}) from zope.deprecation import __show__ diff --git a/pyramid/tests/test_zcml.py b/pyramid/tests/test_zcml.py index 905a53287..39b342ffe 100644 --- a/pyramid/tests/test_zcml.py +++ b/pyramid/tests/test_zcml.py @@ -11,7 +11,7 @@ from zope.interface import implements class TestViewDirective(unittest.TestCase): def setUp(self): - testing.setUp() + self.config = testing.setUp() def tearDown(self): testing.tearDown() @@ -21,14 +21,12 @@ class TestViewDirective(unittest.TestCase): return view(*arg, **kw) def test_with_dotted_renderer(self): - from pyramid.threadlocal import get_current_registry from pyramid.interfaces import IView from pyramid.interfaces import IViewClassifier from pyramid.interfaces import IRendererFactory from pyramid.interfaces import IRequest - context = DummyContext() - reg = get_current_registry() - context.registry = reg + reg = self.config.registry + context = reg.ctx def factory(path): def foo(*arg): return 'OK' @@ -49,13 +47,11 @@ class TestViewDirective(unittest.TestCase): self.assertEqual(regview(None, None).body, 'OK') def test_with_custom_predicates(self): - from pyramid.threadlocal import get_current_registry from pyramid.interfaces import IView from pyramid.interfaces import IViewClassifier from pyramid.interfaces import IRequest - context = DummyContext() - reg = get_current_registry() - context.registry = reg + reg = self.config.registry + context = reg.ctx view = lambda *arg: 'OK' def pred1(context, request): return True @@ -77,13 +73,11 @@ class TestViewDirective(unittest.TestCase): self.assertEqual(regview(None, None), 'OK') def test_context_trumps_for(self): - from pyramid.threadlocal import get_current_registry from pyramid.interfaces import IView from pyramid.interfaces import IViewClassifier from pyramid.interfaces import IRequest - context = DummyContext() - reg = get_current_registry() - context.registry = reg + reg = self.config.registry + context = reg.ctx view = lambda *arg: 'OK' class Foo: pass @@ -101,13 +95,11 @@ class TestViewDirective(unittest.TestCase): self.assertEqual(regview(None, None), 'OK') def test_with_for(self): - from pyramid.threadlocal import get_current_registry from pyramid.interfaces import IView from pyramid.interfaces import IViewClassifier from pyramid.interfaces import IRequest - context = DummyContext() - reg = get_current_registry() - context.registry = reg + reg = self.config.registry + context = reg.ctx view = lambda *arg: 'OK' class Foo: pass @@ -129,7 +121,6 @@ class TestNotFoundDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, context, view, **kw): from pyramid.zcml import notfound @@ -143,8 +134,7 @@ class TestNotFoundDirective(unittest.TestCase): from pyramid.exceptions import NotFound reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx def view(request): return 'OK' self._callFUT(context, view) @@ -173,8 +163,7 @@ class TestNotFoundDirective(unittest.TestCase): from pyramid.exceptions import NotFound from pyramid.configuration import Configurator reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx config = Configurator(reg) def dummy_renderer_factory(*arg, **kw): return lambda *arg, **kw: 'OK' @@ -199,7 +188,6 @@ class TestForbiddenDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, context, view, **kw): from pyramid.zcml import forbidden @@ -212,8 +200,7 @@ class TestForbiddenDirective(unittest.TestCase): from pyramid.interfaces import IViewClassifier from pyramid.exceptions import Forbidden reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx def view(request): return 'OK' self._callFUT(context, view) @@ -242,9 +229,8 @@ class TestForbiddenDirective(unittest.TestCase): from pyramid.interfaces import IViewClassifier from pyramid.exceptions import Forbidden from pyramid.configuration import Configurator - context = DummyContext() reg = self.config.registry - context.registry = reg + context = reg.ctx config = Configurator(reg) def dummy_renderer_factory(*arg, **kw): return lambda *arg, **kw: 'OK' @@ -269,7 +255,6 @@ class TestRepozeWho1AuthenticationPolicyDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, context, **kw): from pyramid.zcml import repozewho1authenticationpolicy @@ -278,8 +263,7 @@ class TestRepozeWho1AuthenticationPolicyDirective(unittest.TestCase): def test_it_defaults(self): reg = self.config.registry from pyramid.interfaces import IAuthenticationPolicy - context = DummyContext() - context.registry = reg + context = self.config.registry.ctx self._callFUT(context) actions = context.actions self.assertEqual(len(actions), 1) @@ -294,8 +278,7 @@ class TestRepozeWho1AuthenticationPolicyDirective(unittest.TestCase): def test_it(self): reg = self.config.registry from pyramid.interfaces import IAuthenticationPolicy - context = DummyContext() - context.registry = reg + context = self.config.registry.ctx def callback(identity, request): """ """ self._callFUT(context, identifier_name='something', callback=callback) @@ -315,7 +298,6 @@ class TestRemoteUserAuthenticationPolicyDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, context, **kw): from pyramid.zcml import remoteuserauthenticationpolicy @@ -324,8 +306,7 @@ class TestRemoteUserAuthenticationPolicyDirective(unittest.TestCase): def test_defaults(self): from pyramid.interfaces import IAuthenticationPolicy reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx def callback(identity, request): """ """ self._callFUT(context) @@ -342,8 +323,7 @@ class TestRemoteUserAuthenticationPolicyDirective(unittest.TestCase): def test_it(self): from pyramid.interfaces import IAuthenticationPolicy reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx def callback(identity, request): """ """ self._callFUT(context, environ_key='BLAH', callback=callback) @@ -363,7 +343,6 @@ class TestAuthTktAuthenticationPolicyDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, context, secret, **kw): from pyramid.zcml import authtktauthenticationpolicy @@ -372,8 +351,7 @@ class TestAuthTktAuthenticationPolicyDirective(unittest.TestCase): def test_it_defaults(self): from pyramid.interfaces import IAuthenticationPolicy reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx self._callFUT(context, 'sosecret') actions = context.actions self.assertEqual(len(actions), 1) @@ -388,8 +366,7 @@ class TestAuthTktAuthenticationPolicyDirective(unittest.TestCase): def test_it_noconfigerror(self): from pyramid.interfaces import IAuthenticationPolicy reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx def callback(identity, request): """ """ self._callFUT(context, 'sosecret', callback=callback, @@ -410,7 +387,7 @@ class TestAuthTktAuthenticationPolicyDirective(unittest.TestCase): def test_it_configerror(self): from pyramid.exceptions import ConfigurationError - context = DummyContext() + context = self.config.registry.ctx def callback(identity, request): """ """ self.assertRaises(ConfigurationError, @@ -427,7 +404,6 @@ class TestACLAuthorizationPolicyDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, context, **kw): from pyramid.zcml import aclauthorizationpolicy @@ -437,8 +413,7 @@ class TestACLAuthorizationPolicyDirective(unittest.TestCase): from pyramid.authorization import ACLAuthorizationPolicy from pyramid.interfaces import IAuthorizationPolicy reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx def callback(identity, request): """ """ self._callFUT(context) @@ -457,7 +432,6 @@ class TestRouteDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, *arg, **kw): from pyramid.zcml import route @@ -480,9 +454,8 @@ class TestRouteDirective(unittest.TestCase): from pyramid.interfaces import IView from pyramid.interfaces import IViewClassifier from pyramid.interfaces import IRouteRequest - context = DummyContext() reg = self.config.registry - context.registry = reg + context = reg.ctx view = lambda *arg: 'OK' self._callFUT(context, 'name', 'pattern', view=view) actions = context.actions @@ -508,9 +481,8 @@ class TestRouteDirective(unittest.TestCase): from pyramid.interfaces import IView from pyramid.interfaces import IViewClassifier from pyramid.interfaces import IRouteRequest - context = DummyContext() reg = self.config.registry - context.registry = reg + context = reg.ctx view = lambda *arg: 'OK' self._callFUT(context, 'name', 'pattern', view=view, view_context=IDummy) @@ -538,8 +510,7 @@ class TestRouteDirective(unittest.TestCase): from pyramid.interfaces import IViewClassifier from pyramid.interfaces import IRouteRequest reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx view = lambda *arg: 'OK' class Foo: pass @@ -574,9 +545,8 @@ class TestRouteDirective(unittest.TestCase): def renderer(path): return lambda *arg: 'OK' reg.registerUtility(renderer, IRendererFactory, name='.pt') + context = reg.ctx - context = DummyContext() - context.registry = reg view = lambda *arg: 'OK' self._callFUT(context, 'name', 'pattern', view=view, renderer='fixtureapp/templates/foo.pt') @@ -607,8 +577,8 @@ class TestRouteDirective(unittest.TestCase): def pred2(context, request): pass preds = tuple(sorted([pred1, pred2])) - context = DummyContext() - context.registry = self.config.registry + context = self.config.registry.ctx + self._callFUT(context, 'name', 'pattern', custom_predicates=(pred1, pred2)) actions = context.actions @@ -623,8 +593,7 @@ class TestRouteDirective(unittest.TestCase): self._assertRoute('name', 'pattern', 2) def test_with_path_argument_no_pattern(self): - context = DummyContext() - context.registry = self.config.registry + context = self.config.registry.ctx self._callFUT(context, 'name', path='pattern') actions = context.actions self.assertEqual(len(actions), 1) @@ -637,8 +606,7 @@ class TestRouteDirective(unittest.TestCase): self._assertRoute('name', 'pattern') def test_with_path_argument_and_pattern(self): - context = DummyContext() - context.registry = self.config.registry + context = self.config.registry.ctx self._callFUT(context, 'name', pattern='pattern', path='path') actions = context.actions self.assertEqual(len(actions), 1) @@ -653,8 +621,7 @@ class TestRouteDirective(unittest.TestCase): def test_with_neither_path_nor_pattern(self): from pyramid.exceptions import ConfigurationError - context = DummyContext() - context.registry = self.config.registry + context = self.config.registry.ctx self.assertRaises(ConfigurationError, self._callFUT, context, 'name') class TestStaticDirective(unittest.TestCase): @@ -663,7 +630,6 @@ class TestStaticDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, *arg, **kw): from pyramid.zcml import static @@ -680,8 +646,7 @@ class TestStaticDirective(unittest.TestCase): from pyramid.interfaces import IRouteRequest from pyramid.interfaces import IRoutesMapper reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx self._callFUT(context, 'name', 'fixtures/static') actions = context.actions self.assertEqual(len(actions), 2) @@ -718,8 +683,7 @@ class TestStaticDirective(unittest.TestCase): from pyramid.interfaces import IRouteRequest from pyramid.interfaces import IRoutesMapper reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx self._callFUT(context, 'name', 'fixtures/static', permission='aperm') actions = context.actions self.assertEqual(len(actions), 2) @@ -751,7 +715,6 @@ class TestResourceDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, *arg, **kw): from pyramid.zcml import resource @@ -759,8 +722,7 @@ class TestResourceDirective(unittest.TestCase): def test_it(self): from pyramid.configuration import Configurator - context = DummyContext() - context.registry = self.config.registry + context = self.config.registry.ctx self._callFUT(context, 'a', 'b') actions = context.actions self.assertEqual(len(actions), 1) @@ -777,7 +739,6 @@ class TestRendererDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, *arg, **kw): from pyramid.zcml import renderer @@ -786,8 +747,7 @@ class TestRendererDirective(unittest.TestCase): def test_it(self): from pyramid.interfaces import IRendererFactory reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx renderer = lambda *arg, **kw: None self._callFUT(context, renderer, 'r') actions = context.actions @@ -852,7 +812,6 @@ class TestZCMLScanDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, context, package): from pyramid.zcml import scan @@ -861,8 +820,7 @@ class TestZCMLScanDirective(unittest.TestCase): def test_it(self): from pyramid.configuration import Configurator dummy_module = DummyModule() - context = DummyContext() - context.registry = self.config.registry + context = self.config.registry.ctx self._callFUT(context, dummy_module) actions = context.actions self.assertEqual(len(actions), 1) @@ -877,7 +835,6 @@ class TestAdapterDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, *arg, **kw): from pyramid.zcml import adapter @@ -968,39 +925,38 @@ class TestSubscriberDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, *arg, **kw): from pyramid.zcml import subscriber return subscriber(*arg, **kw) def test_no_factory_no_handler(self): - context = DummyContext() + context = self.config.registry.ctx self.assertRaises(TypeError, self._callFUT, context, for_=None, factory=None, handler=None, provides=None) def test_handler_with_provides(self): - context = DummyContext() + context = self.config.registry.ctx self.assertRaises(TypeError, self._callFUT, context, for_=None, factory=None, handler=1, provides=1) def test_handler_and_factory(self): - context = DummyContext() + context = self.config.registry.ctx self.assertRaises(TypeError, self._callFUT, context, for_=None, factory=1, handler=1, provides=None) def test_no_provides_with_factory(self): - context = DummyContext() + context = self.config.registry.ctx self.assertRaises(TypeError, self._callFUT, context, for_=None, factory=1, handler=None, provides=None) def test_adapted_by_as_for_is_None(self): - context = DummyContext() + context = self.config.registry.ctx factory = DummyFactory() factory.__component_adapts__ = None self.assertRaises(TypeError, self._callFUT, context, for_=None, @@ -1008,8 +964,7 @@ class TestSubscriberDirective(unittest.TestCase): def test_register_with_factory(self): from pyramid.registry import Registry - context = DummyContext() - context.registry = self.config.registry + context = self.config.registry.ctx factory = DummyFactory() self._callFUT(context, for_=(IDummy,), factory=factory, handler=None, provides=IFactory) @@ -1023,8 +978,7 @@ class TestSubscriberDirective(unittest.TestCase): def test_register_with_handler(self): from pyramid.configuration import Configurator - context = DummyContext() - context.registry = self.config.registry + context = self.config.registry.ctx factory = DummyFactory() self._callFUT(context, for_=(IDummy,), factory=None, handler=factory) @@ -1041,25 +995,23 @@ class TestUtilityDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, *arg, **kw): from pyramid.zcml import utility return utility(*arg, **kw) def test_factory_and_component(self): - context = DummyContext() + context = self.config.registry.ctx self.assertRaises(TypeError, self._callFUT, context, factory=1, component=1) def test_missing_provides(self): - context = DummyContext() + context = self.config.registry.ctx self.assertRaises(TypeError, self._callFUT, context, provides=None) def test_provides_from_factory_implements(self): from pyramid.registry import Registry - context = DummyContext() - context.registry = self.config.registry + context = self.config.registry.ctx self._callFUT(context, factory=DummyFactory) self.assertEqual(len(context.actions), 1) utility = context.actions[0] @@ -1071,8 +1023,7 @@ class TestUtilityDirective(unittest.TestCase): def test_provides_from_component_provides(self): from pyramid.registry import Registry - context = DummyContext() - context.registry = self.config.registry + context = self.config.registry.ctx component = DummyFactory() self._callFUT(context, component=component) self.assertEqual(len(context.actions), 1) @@ -1089,7 +1040,6 @@ class TestTranslationDirDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, *arg, **kw): from pyramid.zcml import translationdir @@ -1097,8 +1047,7 @@ class TestTranslationDirDirective(unittest.TestCase): def test_it(self): from pyramid.configuration import Configurator - context = DummyContext() - context.registry = self.config.registry + context = self.config.registry.ctx tdir = 'pyramid.tests.localeapp:locale' self._callFUT(context, tdir) actions = context.actions @@ -1116,7 +1065,6 @@ class TestLocaleNegotiatorDirective(unittest.TestCase): def tearDown(self): testing.tearDown() - self.config = None def _callFUT(self, *arg, **kw): from pyramid.zcml import localenegotiator @@ -1124,8 +1072,7 @@ class TestLocaleNegotiatorDirective(unittest.TestCase): def test_it(self): from pyramid.configuration import Configurator - context = DummyContext() - context.registry = self.config.registry + context = self.config.registry.ctx dummy_negotiator = object() self._callFUT(context, dummy_negotiator) actions = context.actions @@ -1151,8 +1098,7 @@ class TestDefaultPermissionDirective(unittest.TestCase): def test_it(self): from pyramid.interfaces import IDefaultPermission reg = self.config.registry - context = DummyContext() - context.registry = reg + context = reg.ctx self._callFUT(context, 'view') actions = context.actions self.assertEqual(len(actions), 1) diff --git a/pyramid/zcml.py b/pyramid/zcml.py index 3104ebac0..dd693b42e 100644 --- a/pyramid/zcml.py +++ b/pyramid/zcml.py @@ -17,11 +17,6 @@ from zope.schema import Bool from zope.schema import Int from zope.schema import TextLine -from pyramid.interfaces import IAuthenticationPolicy -from pyramid.interfaces import IAuthorizationPolicy -from pyramid.interfaces import IDefaultPermission -from pyramid.interfaces import IRendererFactory -from pyramid.interfaces import IRouteRequest from pyramid.interfaces import IView from pyramid.authentication import AuthTktAuthenticationPolicy @@ -31,10 +26,7 @@ from pyramid.authorization import ACLAuthorizationPolicy from pyramid.configuration import Configurator from pyramid.exceptions import ConfigurationError from pyramid.exceptions import NotFound -from pyramid.exceptions import Forbidden -from pyramid.request import route_request_iface from pyramid.resource import resource_spec_from_abspath -from pyramid.static import StaticURLInfo from pyramid.threadlocal import get_current_registry ###################### directives ########################## @@ -185,28 +177,14 @@ def view( context = context or for_ - def register(): - config = Configurator(reg, package=_context.package) - config.add_view( - permission=permission, context=context, view=view, name=name, - request_type=request_type, route_name=route_name, - request_method=request_method, request_param=request_param, - containment=containment, attr=attr, renderer=renderer, - wrapper=wrapper, xhr=xhr, accept=accept, header=header, - path_info=path_info, custom_predicates=custom_predicates, - _info=_context.info) - - discriminator = ['view', context, name, request_type, IView, containment, - request_param, request_method, route_name, attr, - xhr, accept, header, path_info] - - discriminator.extend(sorted(custom_predicates)) - discriminator = tuple(discriminator) - - _context.action( - discriminator = discriminator, - callable = register, - ) + config = Configurator(reg, package=_context.package) + config.add_view( + permission=permission, context=context, view=view, name=name, + request_type=request_type, route_name=route_name, + request_method=request_method, request_param=request_param, + containment=containment, attr=attr, renderer=renderer, + wrapper=wrapper, xhr=xhr, accept=accept, header=header, + path_info=path_info, custom_predicates=custom_predicates) _view = view # for directives that take a view arg @@ -303,49 +281,27 @@ def route(_context, if pattern is None: raise ConfigurationError('route directive must include a "pattern"') - def register(): - config = Configurator(reg, package=_context.package) - config.add_route( - name, - pattern, - factory=factory, - header=header, - xhr=xhr, - accept=accept, - path_info=path_info, - request_method=request_method, - request_param=request_param, - custom_predicates=custom_predicates, - view=view, - view_context=view_context, - view_permission=view_permission, - view_renderer=view_renderer, - view_attr=view_attr, - use_global_views=use_global_views, - traverse=traverse, - _info=_context.info - ) - - discriminator = ['route', name, xhr, request_method, path_info, - request_param, header, accept] - discriminator.extend(sorted(custom_predicates)) - discriminator = tuple(discriminator) - - _context.action( - discriminator=discriminator, - callable = register, + config = Configurator(reg, package=_context.package) + config.add_route( + name, + pattern, + factory=factory, + header=header, + xhr=xhr, + accept=accept, + path_info=path_info, + request_method=request_method, + request_param=request_param, + custom_predicates=custom_predicates, + view=view, + view_context=view_context, + view_permission=view_permission, + view_renderer=view_renderer, + view_attr=view_attr, + use_global_views=use_global_views, + traverse=traverse, ) - if view: - request_iface = reg.queryUtility(IRouteRequest, name=name) - if request_iface is None: - request_iface = route_request_iface(name) - reg.registerUtility(request_iface, IRouteRequest, name=name) - _context.action( - discriminator = ( - 'view', view_context, '', None, IView, name, view_attr), - ) - class ISystemViewDirective(Interface): view = GlobalObject( title=u"", @@ -381,7 +337,7 @@ def notfound(_context, reg = get_current_registry() config = Configurator(reg, package=_context.package) config.set_notfound_view(view=view, attr=attr, renderer=renderer, - wrapper=wrapper, _info=_context.info) + wrapper=wrapper) discriminator = ('view', NotFound, '', None, IView, None, None, None, None, attr, False, None, None, None) @@ -397,22 +353,14 @@ def forbidden(_context, renderer=None, wrapper=None): - def register(): - try: - reg = _context.registry - except AttributeError: # pragma: no cover (b/c) - reg = get_current_registry() - config = Configurator(reg, package=_context.package) - config.set_forbidden_view(view=view, attr=attr, renderer=renderer, - wrapper=wrapper, _info=_context.info) - - discriminator = ('view', Forbidden, '', None, IView, None, None, None, - None, attr, False, None, None, None) + try: + reg = _context.registry + except AttributeError: # pragma: no cover (b/c) + reg = get_current_registry() + config = Configurator(reg, package=_context.package) + config.set_forbidden_view(view=view, attr=attr, renderer=renderer, + wrapper=wrapper) - _context.action( - discriminator = discriminator, - callable = register, - ) class IResourceDirective(Interface): """ @@ -435,12 +383,7 @@ def resource(_context, to_override, override_with): reg = get_current_registry() config = Configurator(reg, package=_context.package) - - _context.action( - discriminator = None, - callable = config.override_resource, - args = (to_override, override_with, _context.info), - ) + config.override_resource(to_override, override_with) class IRepozeWho1AuthenticationPolicyDirective(Interface): identifier_name = TextLine(title=u'identitfier_name', required=False, @@ -458,8 +401,7 @@ def repozewho1authenticationpolicy(_context, identifier_name='auth_tkt', except AttributeError: # pragma: no cover (b/c) reg = get_current_registry() config = Configurator(reg, package=_context.package) - config._set_authentication_policy(policy, _info=_context.info) - _context.action(discriminator=IAuthenticationPolicy) + config._set_authentication_policy(policy) class IRemoteUserAuthenticationPolicyDirective(Interface): environ_key = TextLine(title=u'environ_key', required=False, @@ -477,8 +419,7 @@ def remoteuserauthenticationpolicy(_context, environ_key='REMOTE_USER', except AttributeError: # pragma: no cover (b/c) reg = get_current_registry() config = Configurator(reg, package=_context.package) - config._set_authentication_policy(policy, _info=_context.info) - _context.action(discriminator=IAuthenticationPolicy) + config._set_authentication_policy(policy) class IAuthTktAuthenticationPolicyDirective(Interface): secret = TextLine(title=u'secret', required=True) @@ -524,8 +465,7 @@ def authtktauthenticationpolicy(_context, except AttributeError: # pragma: no cover (b/c) reg = get_current_registry() config = Configurator(reg, package=_context.package) - config._set_authentication_policy(policy, _info=_context.info) - _context.action(discriminator=IAuthenticationPolicy) + config._set_authentication_policy(policy) class IACLAuthorizationPolicyDirective(Interface): pass @@ -539,8 +479,7 @@ def aclauthorizationpolicy(_context): except AttributeError: # pragma: no cover (b/c) reg = get_current_registry() config = Configurator(reg, package=_context.package) - config._set_authorization_policy(policy, _info=_context.info) - _context.action(discriminator=IAuthorizationPolicy) + config._set_authorization_policy(policy) class IRendererDirective(Interface): factory = GlobalObject( @@ -559,8 +498,7 @@ def renderer(_context, factory, name=''): except AttributeError: # pragma: no cover (b/c) reg = get_current_registry() config = Configurator(reg, package=_context.package) - config.add_renderer(name, factory, _info=_context.info) - _context.action(discriminator=(IRendererFactory, name)) + config.add_renderer(name, factory) class IStaticDirective(Interface): name = TextLine( @@ -595,23 +533,8 @@ def static(_context, name, path, cache_max_age=3600, except AttributeError: # pragma: no cover (b/c) reg = get_current_registry() config = Configurator(reg, package=_context.package) - - _context.action( - discriminator=('static', name), - callable=config.add_static_view, - args = (name, path), - kw = {'cache_max_age':cache_max_age, - 'permission':permission, - '_info':_context.info}, - ) - - if not '/' in name: - _context.action( - discriminator = ( - 'view', StaticURLInfo, '', None, IView, None, None, None, - name, None, None, None, None, None, - ) - ) + config.add_static_view(name, path, cache_max_age=cache_max_age, + permission=permission) class IScanDirective(Interface): package = GlobalObject( @@ -625,11 +548,7 @@ def scan(_context, package): except AttributeError: # pragma: no cover (b/c) reg = get_current_registry() config = Configurator(reg, package=_context.package) - _context.action( - discriminator=None, - callable=config.scan, - args=(package, None, _context.info) - ) + config.scan(package) class ITranslationDirDirective(Interface): dir = TextLine( @@ -646,12 +565,7 @@ def translationdir(_context, dir): reg = get_current_registry() config = Configurator(reg, package=_context.package) - - _context.action( - discriminator = ('tdir', path), - callable=config.add_translation_dirs, - args = (dir,), - ) + config.add_translation_dirs(path) class ILocaleNegotiatorDirective(Interface): negotiator = GlobalObject( @@ -666,12 +580,7 @@ def localenegotiator(_context, negotiator): except AttributeError: # pragma: no cover (b/c) reg = get_current_registry() config = Configurator(reg, package=_context.package) - - _context.action( - discriminator = 'lnegotiator', - callable=config.set_locale_negotiator, - args = (negotiator,) - ) + config.set_locale_negotiator(negotiator) class IAdapterDirective(Interface): """ @@ -817,11 +726,7 @@ def subscriber(_context, for_=None, factory=None, handler=None, provides=None): config = Configurator(registry=registry, package=_context.package) if handler is not None: - _context.action( - discriminator = None, - callable = config.add_subscriber, - args = (handler, for_, _context.info), - ) + config.add_subscriber(handler, for_) else: _context.action( discriminator = None, @@ -910,7 +815,6 @@ def default_permission(_context, name): reg = get_current_registry() config = Configurator(reg, package=_context.package) config.set_default_permission(name) - _context.action(discriminator=IDefaultPermission) def path_spec(context, path): # we prefer registering resource specifications over absolute |
