dlab_core.containers
¶
Module Contents¶
-
exception
ContainerException
[source]¶ Bases:
dlab_core.domain.exceptions.DLabException
Base Container Exceptions. Raised during container execution.
-
exception
ContainerTypeException
[source]¶ Bases:
dlab_core.containers.ContainerException
Raised when try to assign wrong data type.
-
exception
ContainerFrozenServiceException
(key)[source]¶ Bases:
dlab_core.containers.ContainerException
Raised when try to access a key that is represent frozen data in a dictionary (dict).
-
exception
ContainerKeyException
[source]¶ Bases:
dlab_core.containers.ContainerException
Raised when try to access a key that isn’t in a dictionary (dict).
-
exception
ContainerExpectedCallableException
[source]¶ Bases:
dlab_core.containers.ContainerException
Raised when trying to call non callable object.
-
class
Container
(args=None)[source]¶ Instantiates the container. Objects and parameters can be passed as argument to the constructor.
Parameters: args (dict) – The parameters or objects. Raises: ContainerTypeException – Handle wrong input data type. -
__setitem__
(self, key, value)[source]¶ Sets a parameter or an object. Objects must be defined as Closures. Allowing any python callable leads to difficult to debug problems as function names (strings) are callable (creating a function with the same name as an existing parameter would break your container).
Parameters: - key (str) – The unique identifier for the parameter or object.
- value – The value or a closure of the parameter.
Raises: ContainerFrozenServiceException – Prevent override of a frozen
data.
-
__getitem__
(self, key)[source]¶ Gets a parameter or an object.
Parameters: key (string) – The unique identifier for the parameter or object. Returns: The value of the parameter or an object. Raises: ContainerKeyException – Do not allow to get out of scope element.
-
keys
(self)[source]¶ Return set-like object providing a view on container keys.
Return type: set Returns: Container keys list.
-
__len__
(self)[source]¶ Count elements of an object.
Return type: int Returns: The custom count as an integer.
-
__delitem__
(self, key)[source]¶ Unset element from container
Parameters: key (string) – The unique identifier for the parameter or object. Raises: ContainerKeyException – Do not allow to get out of scope element.
-
__iter__
(self)[source]¶ Get an iterator from an Container object.
Return type: iterator Returns: Iterator object that loops through each element in the object.
-
raw
(self, key)[source]¶ Gets a parameter or the closure defining an object.
Parameters: key (string) – The unique identifier for the parameter or object. Returns: The value of the parameter or the closure defining an object: Raises: ContainerKeyException – Do not allow to get out of scope element.
-
protect
(self, call)[source]¶ Protects a callable from being interpreted as a service. This is useful when you want to store a callable as a parameter.
Parameters: call (function) – A callable to protect from being evaluated. Return type: callable Returns: The passed callable. Raises: ContainerExpectedCallableException – Protect from call non callable object.
-
factory
(self, call)[source]¶ Marks a callable as being a factory service.
Parameters: call (function) – A service definition to be used as a factory. :rtype callable :return: The passed callable
Raises: ContainerExpectedCallableException – Protect from call non callable object.
-
extend
(self, key, call)[source]¶ Extends an object definition. Useful when you want to extend an existing object definition, without necessarily loading that object.
Parameters: - key (string) – The unique identifier for the parameter or object.
- call (callable) – The passed callable.
Return type: callable
Returns: The wrapped callable.
Raises: ContainerFrozenServiceException – Prevent extend of a frozen
data. :raise ContainerExpectedCallableException: Protect from call non callable object.
-