| | |
| | | if chameleon_zpt: |
| | | DEFAULT_RENDERERS += (('.txt', chameleon_text.renderer_factory),) |
| | | |
| | | def action_method(wrapped): |
| | | """ Wrapper to provide the right conflict info report data when a method |
| | | that calls Configurator.action calls another that does the same""" |
| | | def wrapper(self, *arg, **kw): |
| | | if self._ainfo is None: |
| | | self._ainfo = [] |
| | | try: |
| | | f = traceback.extract_stack(limit=3) |
| | | info = f[-2] |
| | | except: # pragma: no cover |
| | | info = '' |
| | | self._ainfo.append(info) |
| | | try: |
| | | result = wrapped(self, *arg, **kw) |
| | | finally: |
| | | self._ainfo.pop() |
| | | return result |
| | | wrapper.__name__ = wrapped.__name__ |
| | | wrapper.__doc__ = wrapped.__doc__ |
| | | return wrapper |
| | | |
| | | class Configurator(object): |
| | | """ |
| | | A Configurator is used to configure a :app:`Pyramid` |
| | |
| | | manager = manager # for testing injection |
| | | venusian = venusian # for testing injection |
| | | _ctx = None |
| | | _ainfo = None |
| | | |
| | | def __init__(self, |
| | | registry=None, |
| | |
| | | self.registry.settings = settings |
| | | return settings |
| | | |
| | | #@action_method |
| | | @action_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 |
| | |
| | | self.registry.registerUtility(factory, IDefaultRootFactory) # b/c |
| | | self.action(IRootFactory, register) |
| | | |
| | | #@action_method |
| | | @action_method |
| | | def _set_authentication_policy(self, policy): |
| | | """ Add a :app:`Pyramid` :term:`authentication policy` to |
| | | the current configuration.""" |
| | |
| | | self.registry.registerUtility(policy, IAuthenticationPolicy) |
| | | self.action(IAuthenticationPolicy) |
| | | |
| | | #@action_method |
| | | @action_method |
| | | def _set_authorization_policy(self, policy): |
| | | """ Add a :app:`Pyramid` :term:`authorization policy` to |
| | | the current configuration state (also accepts a :term:`dotted |
| | |
| | | name=pkg_name) |
| | | override.insert(path, override_pkg_name, override_prefix) |
| | | |
| | | @action_method |
| | | def _set_security_policies(self, authentication, authorization=None): |
| | | if authorization is None: |
| | | authorization = ACLAuthorizationPolicy() # default |
| | |
| | | # to it, unless the context already has info (if it already has |
| | | # info, it's likely a context generated by a ZCML directive). |
| | | context = GroupingContextDecorator(context) |
| | | try: |
| | | f = traceback.extract_stack(limit=3) |
| | | info = f[-3] |
| | | except: # pragma: no cover |
| | | if self._ainfo: |
| | | info = self._ainfo[0] |
| | | else: |
| | | info = '' |
| | | context.info = info |
| | | context.action(discriminator, callable, args, kw, order) |
| | |
| | | renderer = {'name':renderer, 'package':self.package} |
| | | return self._derive_view(view, attr=attr, renderer=renderer) |
| | | |
| | | #@action_method |
| | | @action_method |
| | | def add_subscriber(self, subscriber, iface=None): |
| | | """Add an event :term:`subscriber` for the event stream |
| | | implied by the supplied ``iface`` interface. The |
| | |
| | | self.manager.pop() |
| | | return app |
| | | |
| | | #@action_method |
| | | def load_zcml(self, spec='configure.zcml', lock=threading.Lock()): |
| | | """ Load configuration from a :term:`ZCML` file into the |
| | | current configuration state. The ``spec`` argument is an |
| | |
| | | self.manager.pop() |
| | | return registry |
| | | |
| | | @action_method |
| | | def add_handler(self, route_name, pattern, handler, action=None, **kw): |
| | | |
| | | """ Add a Pylons-style view handler. This function adds a |
| | |
| | | |
| | | return route |
| | | |
| | | #@action_method |
| | | @action_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, |
| | |
| | | was used prior to this view registration. Pass the string |
| | | ``__no_permission_required__`` as the permission argument to |
| | | explicitly indicate that the view should always be |
| | | executable by entirely anonymous users, regardless of the |
| | | executable by entirely anonymous users, regardless of the |
| | | default permission, bypassing any :term:`authorization |
| | | policy` that may be in effect. |
| | | |
| | |
| | | discriminator = tuple(discriminator) |
| | | self.action(discriminator, register) |
| | | |
| | | #@action_method |
| | | @action_method |
| | | def add_route(self, |
| | | name, |
| | | pattern=None, |
| | |
| | | self.registry.registerUtility(mapper, IRoutesMapper) |
| | | return mapper |
| | | |
| | | #@action_method |
| | | @action_method |
| | | 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 |
| | |
| | | scanner = self.venusian.Scanner(config=self) |
| | | scanner.scan(package, categories=categories) |
| | | |
| | | #@action_method |
| | | @action_method |
| | | def add_renderer(self, name, factory): |
| | | """ |
| | | Add a :app:`Pyramid` :term:`renderer` factory to the |
| | |
| | | self.registry.registerUtility(factory, IRendererFactory, name=name) |
| | | self.action((IRendererFactory, name), None) |
| | | |
| | | #@action_method |
| | | @action_method |
| | | def override_resource(self, to_override, override_with, _override=None): |
| | | """ Add a :app:`Pyramid` resource override to the current |
| | | configuration state. |
| | |
| | | override(from_package, path, to_package, override_prefix) |
| | | self.action(None, register) |
| | | |
| | | @action_method |
| | | def set_forbidden_view(self, view=None, attr=None, renderer=None, |
| | | wrapper=None): |
| | | """ Add a default forbidden view to the current configuration |
| | |
| | | return view(context, request) |
| | | return self.add_view(bwcompat_view, context=Forbidden, wrapper=wrapper) |
| | | |
| | | @action_method |
| | | def set_notfound_view(self, view=None, attr=None, renderer=None, |
| | | wrapper=None): |
| | | """ Add a default not found view to the current configuration |
| | |
| | | return view(context, request) |
| | | return self.add_view(bwcompat_view, context=NotFound, wrapper=wrapper) |
| | | |
| | | #@action_method |
| | | @action_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 |
| | |
| | | self.registry.registerUtility(factory, IRequestFactory) |
| | | self.action(IRequestFactory, register) |
| | | |
| | | #@action_method |
| | | @action_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 |
| | |
| | | self.registry.registerUtility(factory, IRendererGlobalsFactory) |
| | | self.action(IRendererGlobalsFactory, register) |
| | | |
| | | #@action_method |
| | | @action_method |
| | | def set_locale_negotiator(self, negotiator): |
| | | """ |
| | | Set the :term:`locale negotiator` for this application. The |
| | |
| | | self.registry.registerUtility(negotiator, ILocaleNegotiator) |
| | | self.action(ILocaleNegotiator, register) |
| | | |
| | | #@action_method |
| | | @action_method |
| | | def set_default_permission(self, permission): |
| | | """ |
| | | Set the default permission to be used by all subsequent |
| | |
| | | self.registry.registerUtility(permission, IDefaultPermission) |
| | | self.action(IDefaultPermission, None) |
| | | |
| | | #@action_method |
| | | @action_method |
| | | def set_session_factory(self, session_factory): |
| | | """ |
| | | Configure the application with a :term:`session factory`. If |
| | |
| | | self.registry.registerUtility(session_factory, ISessionFactory) |
| | | self.action(ISessionFactory, register) |
| | | |
| | | #@action_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 |
| | |
| | | ctranslate = ChameleonTranslate(translator) |
| | | self.registry.registerUtility(ctranslate, IChameleonTranslate) |
| | | |
| | | @action_method |
| | | def add_static_view(self, name, path, **kw): |
| | | """ Add a view used to render static resources such as images |
| | | and CSS files. |
| | |
| | | ITraverser) |
| | | return models |
| | | |
| | | @action_method |
| | | def testing_add_subscriber(self, event_iface=None): |
| | | """Unit/integration testing helper: Registers a |
| | | :term:`subscriber` which listens for events of the type |