Home | Trees | Indices | Help |
|
---|
|
object --+ | dict --+ | RegistryStore
This class is responsible for loading objects and storing them in their registry which is created on the fly as needed. It handles dynamic registration of objects and provides a convenient api to access them. To be recognized as an object that should be stored into one of the store's registry (:class:`Registry`), an object must provide the following attributes, used control how they interact with the registry: :attr:`__registries__` list of registry names (string like 'views', 'templates'...) into which the object should be registered :attr:`__regid__` object identifier in the registry (string like 'main', 'primary', 'folder_box') :attr:`__select__` the object predicate selectors Moreover, the :attr:`__abstract__` attribute may be set to `True` to indicate that an object is abstract and should not be registered (such inherited attributes not considered). .. Note:: When using the store to load objects dynamically, you *always* have to use **super()** to get the methods and attributes of the superclasses, and not use the class identifier. If not, you'll get into trouble at reload time. For example, instead of writing:: class Thing(Parent): __regid__ = 'athing' __select__ = yes() def f(self, arg1): Parent.f(self, arg1) You must write:: class Thing(Parent): __regid__ = 'athing' __select__ = yes() def f(self, arg1): super(Thing, self).f(arg1) Controlling object registration ------------------------------- Dynamic loading is triggered by calling the :meth:`register_objects` method, given a list of directories to inspect for python modules. .. automethod: register_objects For each module, by default, all compatible objects are registered automatically. However if some objects come as replacement of other objects, or have to be included only if some condition is met, you'll have to define a `registration_callback(vreg)` function in the module and explicitly register **all objects** in this module, using the api defined below. .. automethod:: RegistryStore.register_all .. automethod:: RegistryStore.register_and_replace .. automethod:: RegistryStore.register .. automethod:: RegistryStore.unregister .. Note:: Once the function `registration_callback(vreg)` is implemented in a module, all the objects from this module have to be explicitly registered as it disables the automatic object registration. Examples: .. sourcecode:: python def registration_callback(store): # register everything in the module except BabarClass store.register_all(globals().values(), __name__, (BabarClass,)) # conditionally register BabarClass if 'babar_relation' in store.schema: store.register(BabarClass) In this example, we register all application object classes defined in the module except `BabarClass`. This class is then registered only if the 'babar_relation' relation type is defined in the instance schema. .. sourcecode:: python def registration_callback(store): store.register(Elephant) # replace Babar by Celeste store.register_and_replace(Celeste, Babar) In this example, we explicitly register classes one by one: * the `Elephant` class * the `Celeste` to replace `Babar` If at some point we register a new appobject class in this module, it won't be registered at all without modification to the `registration_callback` implementation. The first example will register it though, thanks to the call to the `register_all` method. Controlling registry instantiation ---------------------------------- The `REGISTRY_FACTORY` class dictionary allows to specify which class should be instantiated for a given registry name. The class associated to `None` key will be the class used when there is no specific class for a name.
Instance Methods | |||
new empty dictionary |
|
||
|
|||
|
|||
|
|||
D.get(k,d), also set D[k]=d if k not in D |
|
||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from Inherited from |
Class Methods | |||
|
Properties | |
Inherited from |
Method Details |
x.__init__(...) initializes x; see help(type(x)) for signature
|
return the registry (dictionary of class objects) associated to this name
|
return existing registry named regid or use factory to create one and return it |
|
register registrable objects into `objects`. Registrable objects are properly configured subclasses of :class:`RegistrableObject`. Objects which are not defined in the module `modname` or which are in `butclasses` won't be registered. Typical usage is: .. sourcecode:: python store.register_all(globals().values(), __name__, (ClassIWantToRegisterExplicitly,)) So you get partially automatic registration, keeping manual registration for some object (to use :meth:`~logilab.common.registry.RegistryStore.register_and_replace` for instance). |
register `obj` implementation into `registryname` or `obj.__registries__` if not specified, with identifier `oid` or `obj.__regid__` if not specified. If `clear` is true, all objects with the same identifier will be previously unregistered. |
register `obj` object into `registryname` or `obj.__registries__` if not specified. If found, the `replaced` object will be unregistered first (else a warning will be issued as it is generally unexpected). |
reset registry and walk down path to return list of (path, name) file modules to be loaded |
return True if something module changed and the registry should be reloaded |
Automatically handle module objects registration. Instances are registered as soon as they are hashable and have the following attributes: * __regid__ (a string) * __select__ (a callable) * __registries__ (a tuple/list of string) For classes this is a bit more complicated : - first ensure parent classes are already registered - class with __abstract__ == True in their local dictionary are skipped - object class needs to have registries and identifier properly set to a non empty string to be registered. |
ensure `obj` should be registered as arbitrary stuff may be registered, do a lot of check and warn about weird cases (think to dumb proxy objects) |
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Fri Jul 5 13:28:49 2013 | http://epydoc.sourceforge.net |