Module registry
source code
This module provides bases for predicates dispatching (the pattern in use
here is similar to what's refered as multi-dispatch or predicate-dispatch in the
literature, though a bit different since the idea is to select across different
implementation 'e.g. classes), not to dispatch a message to a function or
method. It contains the following classes:
* :class:`RegistryStore`, the top level object which loads implementation
objects and stores them into registries. You'll usually use it to access
registries and their contained objects;
* :class:`Registry`, the base class which contains objects semantically grouped
(for instance, sharing a same API, hence the 'implementation' name). You'll
use it to select the proper implementation according to a context. Notice you
may use registries on their own without using the store.
.. Note::
implementation objects are usually designed to be accessed through the
registry and not by direct instantiation, besides to use it as base classe.
The selection procedure is delegated to a selector, which is responsible for
scoring the object according to some context. At the end of the selection, if an
implementation has been found, an instance of this class is returned. A selector
is built from one or more predicates combined together using AND, OR, NOT
operators (actually `&`, `|` and `~`). You'll thus find some base classes to
build predicates:
* :class:`Predicate`, the abstract base predicate class
* :class:`AndPredicate`, :class:`OrPredicate`, :class:`NotPredicate`, which you
shouldn't have to use directly. You'll use `&`, `|` and '~' operators between
predicates directly
* :func:`objectify_predicate`
You'll eventually find one concrete predicate: :class:`yes`
.. autoclass:: RegistryStore
.. autoclass:: Registry
Predicates
----------
.. autoclass:: Predicate
.. autofunction:: objectify_predicate
.. autoclass:: yes
.. autoclass:: AndPredicate
.. autoclass:: OrPredicate
.. autoclass:: NotPredicate
Debugging
---------
.. autoclass:: traced_selection
Exceptions
----------
.. autoclass:: RegistryException
.. autoclass:: RegistryNotFound
.. autoclass:: ObjectNotFound
.. autoclass:: NoSelectableObject
|
RegistryException
Base class for registry exception.
|
|
RegistryNotFound
Raised when an unknown registry is requested.
|
|
ObjectNotFound
Raised when an unregistered object is requested.
|
|
NoSelectableObject
Raised when no object is selectable for a given context.
|
|
SelectAmbiguity
Raised when several objects compete at selection time with an equal
score.
|
|
RegistrableObject
This is the base class for registrable objects which are selected
according to a context.
|
|
RegistrableInstance
Inherit this class if you want instances of the classes to be
automatically registered.
|
|
Registry
The registry store a set of implementations associated to identifier:
|
|
RegistryStore
This class is responsible for loading objects and storing them
in their registry which is created on the fly as needed.
|
|
traced_selection
Typical usage is :
|
|
PredicateMetaClass
|
|
Predicate
base class for selector classes providing implementation
for operators ``&``, ``|`` and ``~``
|
|
MultiPredicate
base class for compound selector classes
|
|
AndPredicate
and-chained selectors
|
|
OrPredicate
or-chained selectors
|
|
NotPredicate
negation selector
|
|
yes
Return the score given as parameter, with a default score of 0.5 so any
other selector take precedence.
|
|
obj_registries(cls,
registryname=None)
return a tuple of registry names (see __registries__) |
source code
|
|
|
|
|
|
|
|
|
|
|
TRACED_OIDS = None
hash(x)
|
Most of the time, a simple score function is enough to build a selector.
The :func:`objectify_predicate` decorator turn it into a proper selector
class::
@objectify_predicate
def one(cls, req, rset=None, **kwargs):
return 1
class MyView(View):
__select__ = View.__select__ & one()
|
- Decorators:
@deprecated('[lgc 0.59] use Registry.objid class method instead')
|
- Decorators:
@deprecated('[lgc 0.59] use obj_registries function instead')
|