Registry provide base class for a simple Registry pattern with single abstract get function.
It being use by the CacheRegistry, ConnectionRegistry and more…
Registry
core_lib.registry.Registry [source]
Core-Lib basic Registry class is used by most of Core-Lib modules
-
core_lib.registry.default_registry.DefaultRegistry[source]Base basic implementation of the
Registryclass with four basic functionsregister,unregister,get,registered -
core_lib.connection.connection_registry.ConnectionRegistry[source]
Extends the Registry and a base class for all ConnectionRegistry classes.
core_lib.cache.cache_registry.CacheRegistry[source]
Extends the DefaultRegistry and is limited to storing only CacheHandler instances using an object_type parameter
core_lib.observer.observer_registry.ObserverRegistry[source]
Extends the DefaultRegistry and is limited to storing only Observer instances using an object_type parameter
Default Registry
core_lib.registry.default_registry.DefaultRegistry [source]
DefaultRegistry is implementing the Registry abstract class and providing a boilerplate base class for CacheRegistry, ObserverRegistry, and more.
Constractor:
class DefaultRegistry(Registry):
def __init__(self, object_type: object):
...
Arguments
object_type(object): Datatype of the object that is to be stored in the registry.
Usage
from core_lib.registry.default_registry import DefaultRegistry
class Customer(object):
...
class CustomerRegistry(DefaultRegistry):
def __init__(self):
DefaultRegistry.__init__(self, Customer)
Functions:
get()
core_lib.registry.default_registry.DefaultRegistry.get() [source]
Returns an fresh entry from the registry with the specified key.
def get(self, key: str = None, *args, **kwargs):
...
Arguments
key(str): Is the key of the registry entry to be returned.
If
get()is used without any parameters, it will return the default value supplied by the user, or the first entry in the registry if the default value also isn’t provided.
If the registry is empty or the
get()is called with akeythat does not exist in the registry it will returnNone
Usage
from core_lib.registry.default_registry import DefaultRegistry
registry_factory.get('user_name')
register()
core_lib.registry.default_registry.DefaultRegistry.register() [source]
Register’s the key and value into the registry.
def register(self, key: str, object, is_default: bool = False):
...
Arguments
key(str): A unique string to identify the registered object; duplicate key’s are not allowed and will cause anValueError.object: Any value we wish to store with the attached keyis_default(bool): For multiple entries in a same registryis_defaultcan be used to set the default value to mark this object as default, default value can be fetched when callinggetwithout akeyparameter.
Usage
from core_lib.registry.default_registry import DefaultRegistry
user_name = 'Jon Doe'
registry_factory = DefaultRegistry(str)
registry_factory.register('user_name', user_name)
unregister()
core_lib.registry.default_registry.DefaultRegistry.unregister() [source]
Unregisters/removes an entry present in the registry.
def unregister(self, key: str):
...
Arguments
key(str): Is the key of the entry to be unregistered from the registry.
The first item in the registry becomes default when we unregister a default
key.
Usage
registry_factory.unregister('user_name')
registered()
core_lib.registry.default_registry.DefaultRegistry.registered() [source]
Returns all the registered entities in the registry in the type list.
def registered(self):
Usage
registry_factory.registered()