orionis 0.312.0__py3-none-any.whl → 0.313.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,29 @@
1
1
  from typing import Any, Callable
2
2
  from orionis.container.enums.lifetimes import Lifetime
3
+ from orionis.container.exceptions.container_exception import OrionisContainerException
3
4
  from orionis.container.exceptions.type_error_exception import OrionisContainerTypeError
4
5
  from orionis.services.introspection.abstract.reflection_abstract import ReflectionAbstract
6
+ from orionis.services.introspection.concretes.reflection_concrete import ReflectionConcrete
5
7
 
6
8
 
7
9
  class Container:
8
10
 
9
- def transient(self, abstract: Callable[..., Any], concrete: Callable[..., Any]) -> None:
11
+ def bind(self, abstract: Callable[..., Any] = None, concrete: Callable[..., Any] = None, lifetime: str = Lifetime.TRANSIENT) -> None:
12
+ """
13
+ Binds an abstract type to a concrete implementation with a specified lifetime.
14
+
15
+ Parameters
16
+ ----------
17
+ abstract : Callable[..., Any]
18
+ The abstract base type or alias to be bound.
19
+ concrete : Callable[..., Any]
20
+ The concrete implementation to associate with the abstract type.
21
+ lifetime : str, optional
22
+ The lifetime of the service (default is 'transient').
23
+ """
24
+ pass
25
+
26
+ def transient(self, abstract: Callable[..., Any], concrete: Callable[..., Any]) -> bool:
10
27
  """
11
28
  Registers a service with a transient lifetime.
12
29
 
@@ -17,8 +34,90 @@ class Container:
17
34
  concrete : Callable[..., Any]
18
35
  The concrete implementation to associate with the abstract type.
19
36
  """
37
+ # Ensure that abstract is an abstract class and concrete is a concrete class
38
+ try:
39
+ ReflectionAbstract.ensureIsAbstractClass(abstract)
40
+ ReflectionConcrete.ensureIsConcreteClass(concrete)
41
+ except Exception as e:
42
+ raise OrionisContainerTypeError(
43
+ f"Unexpected error registering transient service: {e}"
44
+ ) from e
45
+
46
+ # Ensure that concrete does NOT inherit from abstract
47
+ if issubclass(concrete, abstract):
48
+ raise OrionisContainerException(
49
+ "Cannot register a concrete class that is a subclass of the provided abstract class. "
50
+ "Please ensure that the concrete class does not inherit from the specified abstract class."
51
+ )
52
+
53
+ # Register the service with transient lifetime
54
+ self.bind(abstract, concrete, Lifetime.TRANSIENT)
55
+
56
+ # Return True to indicate successful registration
57
+ return True
58
+
59
+ def singleton(self, abstract: Callable[..., Any], concrete: Callable[..., Any]) -> bool:
60
+ """
61
+ Registers a service with a singleton lifetime.
62
+
63
+ Parameters
64
+ ----------
65
+ abstract : Callable[..., Any]
66
+ The abstract base type or alias to be bound.
67
+ concrete : Callable[..., Any]
68
+ The concrete implementation to associate with the abstract type.
69
+ """
70
+ # Ensure that abstract is an abstract class and concrete is a concrete class
71
+ try:
72
+ ReflectionAbstract.ensureIsAbstractClass(abstract)
73
+ ReflectionConcrete.ensureIsConcreteClass(concrete)
74
+ except Exception as e:
75
+ raise OrionisContainerTypeError(
76
+ f"Unexpected error registering singleton service: {e}"
77
+ ) from e
78
+
79
+ # Ensure that concrete does NOT inherit from abstract
80
+ if issubclass(concrete, abstract):
81
+ raise OrionisContainerException(
82
+ "Cannot register a concrete class that is a subclass of the provided abstract class. "
83
+ "Please ensure that the concrete class does not inherit from the specified abstract class."
84
+ )
85
+
86
+ # Register the service with singleton lifetime
87
+ self.bind(abstract, concrete, Lifetime.SINGLETON)
88
+
89
+ # Return True to indicate successful registration
90
+ return True
91
+
92
+ def scoped(self, abstract: Callable[..., Any], concrete: Callable[..., Any]) -> bool:
93
+ """
94
+ Registers a service with a scoped lifetime.
20
95
 
96
+ Parameters
97
+ ----------
98
+ abstract : Callable[..., Any]
99
+ The abstract base type or alias to be bound.
100
+ concrete : Callable[..., Any]
101
+ The concrete implementation to associate with the abstract type.
102
+ """
103
+ # Ensure that abstract is an abstract class and concrete is a concrete class
21
104
  try:
22
105
  ReflectionAbstract.ensureIsAbstractClass(abstract)
106
+ ReflectionConcrete.ensureIsConcreteClass(concrete)
23
107
  except Exception as e:
24
- raise OrionisContainerTypeError(f"Type error while registering service: {e}")
108
+ raise OrionisContainerTypeError(
109
+ f"Unexpected error registering scoped service: {e}"
110
+ ) from e
111
+
112
+ # Ensure that concrete does NOT inherit from abstract
113
+ if issubclass(concrete, abstract):
114
+ raise OrionisContainerException(
115
+ "Cannot register a concrete class that is a subclass of the provided abstract class. "
116
+ "Please ensure that the concrete class does not inherit from the specified abstract class."
117
+ )
118
+
119
+ # Register the service with scoped lifetime
120
+ self.bind(abstract, concrete, Lifetime.SCOPED)
121
+
122
+ # Return True to indicate successful registration
123
+ return True
@@ -1,17 +1,19 @@
1
1
  class OrionisContainerException(Exception):
2
- """
3
- Excepción personalizada para errores relacionados con el contenedor de inyección de dependencias Orionis.
4
- """
5
2
 
6
- def __init__(self, message: str) -> None:
3
+ def __init__(self, msg: str):
7
4
  """
8
- Inicializa la excepción con un mensaje de error.
9
-
10
- Args:
11
- message (str): Mensaje descriptivo del error.
5
+ Parameters
6
+ ----------
7
+ msg : str
8
+ Descriptive error message explaining the cause of the exception.
12
9
  """
13
- super().__init__(message)
10
+ super().__init__(msg)
14
11
 
15
12
  def __str__(self) -> str:
16
- """Retorna una representación en cadena de la excepción."""
17
- return f"[OrionisContainerException] {self.args[0]}"
13
+ """
14
+ Returns
15
+ -------
16
+ str
17
+ Formatted string describing the exception.
18
+ """
19
+ return str(self.args[0])
@@ -14,6 +14,6 @@ class OrionisContainerTypeError(TypeError):
14
14
  Returns
15
15
  -------
16
16
  str
17
- Formatted string describing the exception, including the exception name and error message.
17
+ Formatted string describing the exception.
18
18
  """
19
- return f"{self.__class__.__name__}: {self.args[0]}"
19
+ return str(self.args[0])
@@ -1,17 +1,19 @@
1
1
  class OrionisContainerValueError(ValueError):
2
- """
3
- Excepción personalizada para errores de tipo ValueError en el contenedor Orionis.
4
- """
5
2
 
6
- def __init__(self, message: str) -> None:
3
+ def __init__(self, msg: str):
7
4
  """
8
- Inicializa la excepción con un mensaje de error.
9
-
10
- Args:
11
- message (str): Mensaje descriptivo del error.
5
+ Parameters
6
+ ----------
7
+ msg : str
8
+ Descriptive error message explaining the cause of the exception.
12
9
  """
13
- super().__init__(message)
10
+ super().__init__(msg)
14
11
 
15
12
  def __str__(self) -> str:
16
- """Retorna una representación en cadena de la excepción."""
17
- return f"[OrionisContainerValueError] {self.args[0]}"
13
+ """
14
+ Returns
15
+ -------
16
+ str
17
+ Formatted string describing the exception.
18
+ """
19
+ return str(self.args[0])
@@ -5,7 +5,7 @@
5
5
  NAME = "orionis"
6
6
 
7
7
  # Current version of the framework
8
- VERSION = "0.312.0"
8
+ VERSION = "0.313.0"
9
9
 
10
10
  # Full name of the author or maintainer of the project
11
11
  AUTHOR = "Raul Mauricio Uñate Castro"
@@ -13,7 +13,24 @@ from orionis.services.introspection.exceptions.reflection_value_error import Ref
13
13
  class ReflectionAbstract(IReflectionAbstract):
14
14
 
15
15
  @staticmethod
16
- def ensureIsAbstractClass(abstract: Type):
16
+ def isAbstractClass(abstract: Type) -> bool:
17
+ """
18
+ Checks if the provided object is an abstract base class (interface).
19
+
20
+ Parameters
21
+ ----------
22
+ abstract : Type
23
+ The class to check.
24
+
25
+ Returns
26
+ -------
27
+ bool
28
+ True if 'abstract' is an abstract base class, False otherwise.
29
+ """
30
+ return isinstance(abstract, type) and bool(getattr(abstract, '__abstractmethods__', False)) and ABC in abstract.__bases__
31
+
32
+ @staticmethod
33
+ def ensureIsAbstractClass(abstract: Type) -> bool:
17
34
  """
18
35
  Ensures that the provided object is an abstract base class (interface) and directly inherits from ABC.
19
36
 
@@ -27,7 +44,6 @@ class ReflectionAbstract(IReflectionAbstract):
27
44
  ReflectionTypeError
28
45
  If 'abstract' is not a class type, not an abstract base class, or does not directly inherit from ABC.
29
46
  """
30
-
31
47
  if not isinstance(abstract, type):
32
48
  raise ReflectionTypeError(f"Expected a class type for 'abstract', got {type(abstract).__name__!r}")
33
49
  if not bool(getattr(abstract, '__abstractmethods__', False)):
@@ -14,14 +14,35 @@ from orionis.services.introspection.instances.reflection_instance import Reflect
14
14
 
15
15
  class ReflectionConcrete(IReflectionConcrete):
16
16
 
17
- def __init__(self, concrete: Type) -> None:
17
+ @staticmethod
18
+ def isConcreteClass(concrete: Type) -> bool:
18
19
  """
19
- Initialize the ReflectionConcrete with the provided class type.
20
+ Checks if the provided concrete type is a valid ReflectionConcrete type.
20
21
 
21
22
  Parameters
22
23
  ----------
23
24
  concrete : Type
24
- The class type to be reflected upon.
25
+ The class type to be validated.
26
+
27
+ Returns
28
+ -------
29
+ bool
30
+ True if the class is a valid ReflectionConcrete type, False otherwise.
31
+ """
32
+ try:
33
+ return ReflectionConcrete.ensureIsConcreteClass(concrete)
34
+ except (ReflectionTypeError, ReflectionValueError):
35
+ return False
36
+
37
+ @staticmethod
38
+ def ensureIsConcreteClass(concrete: Type) -> bool:
39
+ """
40
+ Ensures that the provided concrete type is a valid ReflectionConcrete type.
41
+
42
+ Parameters
43
+ ----------
44
+ concrete : Type
45
+ The class type to be validated.
25
46
 
26
47
  Raises
27
48
  ------
@@ -29,35 +50,57 @@ class ReflectionConcrete(IReflectionConcrete):
29
50
  If the provided argument is not a class type or is already an instance.
30
51
  ReflectionValueError
31
52
  If the provided class is a built-in/primitive type, abstract class, or interface.
32
-
33
- Notes
34
- -----
35
- - Built-in and primitive types (e.g., int, str, list) are not allowed.
36
- - Abstract classes and interfaces (classes with abstract methods) are not allowed.
37
53
  """
54
+ # Check if the concrete is a class type
38
55
  if not isinstance(concrete, type):
39
56
  raise ReflectionTypeError(f"Expected a class, got {type(concrete)}")
40
57
 
58
+ # Define a set of built-in and primitive types
41
59
  builtin_types = {
42
60
  int, float, str, bool, bytes, type(None), complex,
43
61
  list, tuple, dict, set, frozenset
44
62
  }
45
63
 
64
+ # Check if the concrete class is a built-in or primitive type
46
65
  if concrete in builtin_types:
47
66
  raise ReflectionValueError(f"Class '{concrete.__name__}' is a built-in or primitive type and cannot be used.")
48
67
 
49
- # Check for abstract classes (including interfaces)
50
- if hasattr(concrete, '__abstractmethods__') and len(concrete.__abstractmethods__) > 0:
51
- raise ReflectionValueError(f"Class '{concrete.__name__}' is abstract or an interface and cannot be used.")
52
-
53
68
  # Prevent instantiating if it's already an instance
54
69
  if not isinstance(concrete, type):
55
70
  raise ReflectionTypeError(f"Expected a class type, got instance of '{type(concrete).__name__}'.")
56
71
 
57
72
  # Optionally, check for ABCMeta to catch interfaces
58
- if isinstance(concrete, abc.ABCMeta) and getattr(concrete, '__abstractmethods__', False):
73
+ if abc.ABC in concrete.__bases__:
59
74
  raise ReflectionValueError(f"Class '{concrete.__name__}' is an interface and cannot be used.")
60
75
 
76
+ return True
77
+
78
+ def __init__(self, concrete: Type) -> None:
79
+ """
80
+ Initialize the ReflectionConcrete with the provided class type.
81
+
82
+ Parameters
83
+ ----------
84
+ concrete : Type
85
+ The class type to be reflected upon.
86
+
87
+ Raises
88
+ ------
89
+ ReflectionTypeError
90
+ If the provided argument is not a class type or is already an instance.
91
+ ReflectionValueError
92
+ If the provided class is a built-in/primitive type, abstract class, or interface.
93
+
94
+ Notes
95
+ -----
96
+ - Built-in and primitive types (e.g., int, str, list) are not allowed.
97
+ - Abstract classes and interfaces (classes with abstract methods) are not allowed.
98
+ """
99
+
100
+ # Ensure the provided concrete type is a valid ReflectionConcrete class
101
+ ReflectionConcrete.ensureIsConcreteClass(concrete)
102
+
103
+ # Set the concrete class in the instance
61
104
  self._concrete = concrete
62
105
  self.__instance = None
63
106
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orionis
3
- Version: 0.312.0
3
+ Version: 0.313.0
4
4
  Summary: Orionis Framework – Elegant, Fast, and Powerful.
5
5
  Home-page: https://github.com/orionis-framework/framework
6
6
  Author: Raul Mauricio Uñate Castro
@@ -135,11 +135,11 @@ orionis/console/output/console.py,sha256=TE_Hl720ADd82dbERFSWhkoQRukDQZmETSw4nkw
135
135
  orionis/console/output/executor.py,sha256=bdvkzW2-buy0BPpy2r5qUGrRFW2Ay6k-5rSeHb0gQ3o,3352
136
136
  orionis/console/output/progress_bar.py,sha256=vFy582z6VJS46LV6tuyrmr9qvdVeTEtw3hyNcEHezeg,3088
137
137
  orionis/console/output/styles.py,sha256=6a4oQCOBOKMh2ARdeq5GlIskJ3wjiylYmh66tUKKmpQ,4053
138
- orionis/container/container.py,sha256=eP2YEf2UdllDFbfPPB4ILcdVQBd5kgHyWZkdttfsp1s,928
138
+ orionis/container/container.py,sha256=3hqFY--3QFqrvI4M7WhA64qjjmKb4O58Sn6CEZIf0Oc,5331
139
139
  orionis/container/enums/lifetimes.py,sha256=RqQmugMIB1Ev_j_vFLcWorndm-to7xg4stQ7yKFDdDw,190
140
- orionis/container/exceptions/container_exception.py,sha256=cmoiDR2LvQ4AnxxZL-F3JdeI18ux7CzKmsCki98DAEk,585
141
- orionis/container/exceptions/type_error_exception.py,sha256=M7I64T5wBtHzLRyvrdP4dEzF2N3UzbOAnQmpyKy9aWo,547
142
- orionis/container/exceptions/value_exception.py,sha256=FSFsoG_piErEs-OOCtDrdDY02bPIOdNy4-rbJ8qPNHg,565
140
+ orionis/container/exceptions/container_exception.py,sha256=goTDEwC70xTMD2qppN8KV-xyR0Nps218OD4D1LZ2-3s,470
141
+ orionis/container/exceptions/type_error_exception.py,sha256=cYuvoXVOgRYj3tZPfK341aUERkf33-buOiI2eXxcrAw,470
142
+ orionis/container/exceptions/value_exception.py,sha256=hjY0YEusoL3DurME1ornxvIv1wyGaf6tBggLFlGHblo,472
143
143
  orionis/foundation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
144
144
  orionis/foundation/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
145
145
  orionis/foundation/config/startup.py,sha256=JKAH2ZRhlAZgkD2w11LR1-TVktfjSH9cHo3PsZXOLrg,8275
@@ -231,7 +231,7 @@ orionis/foundation/contracts/config.py,sha256=Rpz6U6t8OXHO9JJKSTnCimytXE-tfCB-1i
231
231
  orionis/foundation/exceptions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
232
232
  orionis/foundation/exceptions/integrity.py,sha256=mc4pL1UMoYRHEmphnpW2oGk5URhu7DJRREyzHaV-cs8,472
233
233
  orionis/metadata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
234
- orionis/metadata/framework.py,sha256=OY1y-roZUBYR9Du8KyC-jHXB-GPu8Sjj9j-gB99J0hQ,4960
234
+ orionis/metadata/framework.py,sha256=4RVjxtYl_4p4lR7ykv4FV8Vzv54BgGrbes_DHokj2C8,4960
235
235
  orionis/metadata/package.py,sha256=tqLfBRo-w1j_GN4xvzUNFyweWYFS-qhSgAEc-AmCH1M,5452
236
236
  orionis/patterns/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
237
237
  orionis/patterns/singleton/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -256,9 +256,9 @@ orionis/services/environment/exceptions/environment_value_exception.py,sha256=Nn
256
256
  orionis/services/introspection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
257
257
  orionis/services/introspection/reflection.py,sha256=AI5ZMv9kHCLOQe9lL_G7wAeY3cPLKZ1FMYqIhU0yS-M,2972
258
258
  orionis/services/introspection/abstract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
259
- orionis/services/introspection/abstract/reflection_abstract.py,sha256=O8fK2a7X82VOK4Pt2Zv6Mt0wsxezLFTyb1JVu9ApCVc,43327
259
+ orionis/services/introspection/abstract/reflection_abstract.py,sha256=SPK2X11VvGORxxPOYloaD6hPAvky--obRU4CO1DE4zM,43865
260
260
  orionis/services/introspection/concretes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
261
- orionis/services/introspection/concretes/reflection_concrete.py,sha256=dhZHzMcGNXzxinWOf8gdeD1h2bUgqrLgw00qdAcor2U,49755
261
+ orionis/services/introspection/concretes/reflection_concrete.py,sha256=1GxD-y8LPGL6kI4Y3XbeLcFjR5Y8cOqbVEPCtPnsuYA,50982
262
262
  orionis/services/introspection/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
263
263
  orionis/services/introspection/contracts/reflect_dependencies.py,sha256=5fdImZarC1ixoFM-1JSBx28RvYbY3GGZhDGjar7cvHc,1771
264
264
  orionis/services/introspection/contracts/reflection_abstract.py,sha256=-ugpFcAkGTlk0Md5ft8NrvupnlfVji8QZjGYqWBxqeY,22370
@@ -338,7 +338,7 @@ orionis/test/suite/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
338
338
  orionis/test/suite/test_unit.py,sha256=5UTdCYmD_Yz8asaBF54RHOx0kjwjLjEhkyPDoDIxk-k,57049
339
339
  orionis/test/view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
340
340
  orionis/test/view/render.py,sha256=jXZkbITBknbUwm_mD8bcTiwLDvsFkrO9qrf0ZgPwqxc,4903
341
- orionis-0.312.0.dist-info/licenses/LICENCE,sha256=-_4cF2EBKuYVS_SQpy1uapq0oJPUU1vl_RUWSy2jJTo,1111
341
+ orionis-0.313.0.dist-info/licenses/LICENCE,sha256=-_4cF2EBKuYVS_SQpy1uapq0oJPUU1vl_RUWSy2jJTo,1111
342
342
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
343
343
  tests/example/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
344
344
  tests/example/test_example.py,sha256=kvWgiW3ADEZf718dGsMPtDh_rmOSx1ypEInKm7_6ZPQ,601
@@ -437,8 +437,8 @@ tests/support/wrapper/test_services_wrapper_docdict.py,sha256=yeVwl-VcwkWSQYyxZu
437
437
  tests/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
438
438
  tests/testing/test_testing_result.py,sha256=MrGK3ZimedL0b5Ydu69Dg8Iul017AzLTm7VPxpXlpfU,4315
439
439
  tests/testing/test_testing_unit.py,sha256=A6QkiOkP7GPC1Szh_GqsrV7GxjWjK8cIwFez6YfrzmM,7683
440
- orionis-0.312.0.dist-info/METADATA,sha256=9Js6d3O7wPFOdIXfLXomApm1mBjD6r556KQQEejCwZM,4772
441
- orionis-0.312.0.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
442
- orionis-0.312.0.dist-info/top_level.txt,sha256=2bdoHgyGZhOtLAXS6Om8OCTmL24dUMC_L1quMe_ETbk,14
443
- orionis-0.312.0.dist-info/zip-safe,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
444
- orionis-0.312.0.dist-info/RECORD,,
440
+ orionis-0.313.0.dist-info/METADATA,sha256=CbEMrV-XG3fZ9FB_7ZXl1Mw1xhwQcNeGfcWZ_buHyjI,4772
441
+ orionis-0.313.0.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
442
+ orionis-0.313.0.dist-info/top_level.txt,sha256=2bdoHgyGZhOtLAXS6Om8OCTmL24dUMC_L1quMe_ETbk,14
443
+ orionis-0.313.0.dist-info/zip-safe,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
444
+ orionis-0.313.0.dist-info/RECORD,,