diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-12-19 21:14:30 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-12-19 21:14:30 +0000 |
| commit | 251ce7d166fa901b33f20cf46315ec464e3eac64 (patch) | |
| tree | 2cd31c1de76f3a915dfb702cc8c18edff27e60b1 /repoze/bfg/configuration.py | |
| parent | 12daf9e069b66aef5715a14641fc269367c091dd (diff) | |
| download | pyramid-251ce7d166fa901b33f20cf46315ec464e3eac64.tar.gz pyramid-251ce7d166fa901b33f20cf46315ec464e3eac64.tar.bz2 pyramid-251ce7d166fa901b33f20cf46315ec464e3eac64.zip | |
- Add two new APIs to the ``repoze.bfg.configuration.Configurator``
class: ``add_adapter`` and ``add_utility``. These, respectively,
perform the same functions as the ``registerAdapter`` and
``registerUtility`` functions of a ZCA registry. They were added to
allow for a more consistent testing API for applications that make
use of the ZCA directly.
- Cause the ``adapter``, ``utility``, and ``subscriber`` ZCML
directives to use a ``Configurator`` instance and associated
configurator APIs rather than a ZCA registry directly.
Diffstat (limited to 'repoze/bfg/configuration.py')
| -rw-r--r-- | repoze/bfg/configuration.py | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/repoze/bfg/configuration.py b/repoze/bfg/configuration.py index 0ee08868d..7b204fec3 100644 --- a/repoze/bfg/configuration.py +++ b/repoze/bfg/configuration.py @@ -10,6 +10,7 @@ from zope.configuration import xmlconfig from zope.interface import Interface from zope.interface import implementedBy +from zope.interface import providedBy from zope.interface.interfaces import IInterface from zope.interface import implements @@ -291,7 +292,7 @@ class Configurator(object): """ return self.manager.pop() - def add_subscriber(self, subscriber, iface=None): + def add_subscriber(self, subscriber, iface=None, info=u''): """Add an event :term:`subscriber` for the event stream implied by the supplied ``iface`` interface. The ``subscriber`` argument represents a callable object; it will @@ -305,9 +306,54 @@ class Configurator(object): iface = (Interface,) if not isinstance(iface, (tuple, list)): iface = (iface,) - self.registry.registerHandler(subscriber, iface) + self.registry.registerHandler(subscriber, iface, info=info) return subscriber + def add_subscription_adapter(self, factory, required=None, provided=None, + info=u''): + """Add a Zope Component Architecture subscription adapter. + What is a subscription adapter, you ask? I have no idea + either. This is currently only here to support the + ``subscriber`` ZCML directive. This is not a published API + until I figure out why I would need a subscription adapter.""" + self.registry.registerSubscriptionAdapter(factory, required=required, + provided=provided, info=info) + + def add_adapter(self, factory, required=None, provided=None, name='', + info=u''): + """Add a :term:`Zope Component Architecture` adapter. Use of + this method is the equivalent of using an ``adapter`` + :term:`ZCML declaration` or the ``registerAdapter`` method of + a ZCA registry. + + .. note:: This method is not useful unless you use :term:`Zope + Component Architecture` APIs in your :mod:`repoze.bfg` + application directly. + """ + self.registry.registerAdapter(factory, required=required, + provided=provided, name=name, info=info) + + def add_utility(self, component=None, provided=None, name=u'', info=u'', + factory=None): + """Add a :term:`Zope Component Architecture` utility. Use of + this method is the equivalent of using a ``utility`` + :term:`ZCML declaration` or the ``registerUtility`` method of + a ZCA registry. + + .. note:: This method is not useful unless you use :term:`Zope + Component Architecture` APIs in your :mod:`repoze.bfg` + application directly. + """ + if factory: + kw = dict(factory=factory) + else: + # older component registries don't accept factory as a kwarg, + # so if we don't need it, we don't pass it + kw = {} + self.registry.registerUtility( + component=component, provided=provided, name=name, info=info, + **kw) + def make_wsgi_app(self): """ Returns a :mod:`repoze.bfg` WSGI application representing the current configuration state and sends a |
