orionis 0.304.0__py3-none-any.whl → 0.306.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.
Files changed (66) hide show
  1. orionis/metadata/framework.py +1 -1
  2. orionis/services/introspection/modules/{reflection_instance.py → reflection_module.py} +1 -1
  3. orionis/services/introspection/reflection.py +90 -0
  4. orionis/{services → support}/standard/std.py +2 -2
  5. orionis/test/{facade/test_suite.py → test_suite.py} +1 -2
  6. orionis/unittesting.py +1 -1
  7. {orionis-0.304.0.dist-info → orionis-0.306.0.dist-info}/METADATA +1 -1
  8. {orionis-0.304.0.dist-info → orionis-0.306.0.dist-info}/RECORD +28 -65
  9. tests/{services → support}/standard/test_services_std.py +3 -3
  10. tests/{services → support}/wrapper/test_services_wrapper_docdict.py +2 -2
  11. orionis/support/abstracts/entities/abstract_class_attributes.py +0 -37
  12. orionis/support/abstracts/reflect_abstract.py +0 -556
  13. orionis/support/helpers/functions.py +0 -285
  14. orionis/support/introspection/container_integrity.py +0 -292
  15. orionis/support/introspection/contracts/__init__.py +0 -0
  16. orionis/support/introspection/contracts/reflection.py +0 -187
  17. orionis/support/introspection/contracts/reflexion_abstract.py +0 -264
  18. orionis/support/introspection/helpers/__init__.py +0 -0
  19. orionis/support/introspection/helpers/functions.py +0 -281
  20. orionis/support/introspection/instances/__init__.py +0 -0
  21. orionis/support/introspection/instances/contracts/__init__.py +0 -0
  22. orionis/support/introspection/instances/contracts/reflection_instance.py +0 -649
  23. orionis/support/introspection/instances/entities/__init__.py +0 -0
  24. orionis/support/introspection/instances/reflection_instance.py +0 -758
  25. orionis/support/introspection/reflect_decorators.py +0 -335
  26. orionis/support/introspection/reflection.py +0 -216
  27. orionis/support/introspection/reflexion_concrete.py +0 -276
  28. orionis/support/introspection/reflexion_concrete_with_abstract.py +0 -185
  29. orionis/support/introspection/reflexion_instance_with_abstract.py +0 -230
  30. orionis/support/introspection/reflexion_module.py +0 -19
  31. orionis/support/introspection/reflexion_module_with_classname.py +0 -22
  32. orionis/support/reflection.py +0 -216
  33. orionis/test/facade/__init__.py +0 -0
  34. orionis/test/facade/contracts/__init__.py +0 -0
  35. orionis/test/facade/contracts/test_suite.py +0 -25
  36. tests/services/standard/__init__.py +0 -0
  37. tests/services/wrapper/__init__.py +0 -0
  38. tests/support/inspection/__init__.py +0 -0
  39. tests/support/inspection/fakes/__init__.py +0 -0
  40. tests/support/inspection/fakes/fake_reflect_abstract.py +0 -276
  41. tests/support/inspection/fakes/fake_reflection_concrete.py +0 -44
  42. tests/support/inspection/fakes/fake_reflection_concrete_with_abstract.py +0 -78
  43. tests/support/inspection/fakes/fake_reflection_instance_with_abstract.py +0 -45
  44. tests/support/inspection/test_reflect_abstract.py +0 -334
  45. tests/support/inspection/test_reflect_instance.py +0 -288
  46. tests/support/inspection/test_reflection_concrete.py +0 -142
  47. tests/support/inspection/test_reflection_concrete_with_abstract.py +0 -87
  48. tests/support/inspection/test_reflection_instance_with_abstract.py +0 -79
  49. /orionis/services/introspection/modules/contracts/{reflection_instance.py → reflection_module.py} +0 -0
  50. /orionis/{services → support}/standard/__init__.py +0 -0
  51. /orionis/{services → support}/standard/contracts/__init__.py +0 -0
  52. /orionis/{services → support}/standard/contracts/std.py +0 -0
  53. /orionis/{services → support}/standard/exceptions/__init__.py +0 -0
  54. /orionis/{services → support}/standard/exceptions/std_value_exception.py +0 -0
  55. /orionis/{services → support}/wrapper/__init__.py +0 -0
  56. /orionis/{services → support}/wrapper/dicts/__init__.py +0 -0
  57. /orionis/{services → support}/wrapper/dicts/dot_dict.py +0 -0
  58. {orionis-0.304.0.dist-info → orionis-0.306.0.dist-info}/WHEEL +0 -0
  59. {orionis-0.304.0.dist-info → orionis-0.306.0.dist-info}/licenses/LICENCE +0 -0
  60. {orionis-0.304.0.dist-info → orionis-0.306.0.dist-info}/top_level.txt +0 -0
  61. {orionis-0.304.0.dist-info → orionis-0.306.0.dist-info}/zip-safe +0 -0
  62. {orionis/support/abstracts → tests/services/inspection/reflection}/__init__.py +0 -0
  63. {orionis/support/abstracts/entities → tests/services/inspection/reflection/mock}/__init__.py +0 -0
  64. /tests/{support/inspection/fakes → services/inspection/reflection/mock}/fake_reflect_instance.py +0 -0
  65. {orionis/support/helpers → tests/support/standard}/__init__.py +0 -0
  66. {orionis/support/introspection → tests/support/wrapper}/__init__.py +0 -0
@@ -1,335 +0,0 @@
1
- import ast
2
- import inspect
3
- import re
4
- from typing import List, Type
5
- from dataclasses import dataclass
6
-
7
- @dataclass
8
- class ClassDecorators:
9
- """
10
- ClassDecorators is a dataclass that encapsulates information about class decorators.
11
-
12
- Attributes
13
- ----------
14
- user_defined : tuple[str, ...]
15
- A tuple containing the names of user-defined decorators applied to a class.
16
- native : tuple[str, ...]
17
- A tuple containing the names of native or built-in decorators applied to a class.
18
- all : tuple[str, ...]
19
- A tuple containing the names of all decorators (both user-defined and native) applied to a class.
20
- """
21
- user_defined: tuple[str, ...]
22
- native: tuple[str, ...]
23
- all: tuple[str, ...]
24
-
25
- @dataclass
26
- class MethodDecorators:
27
- """
28
- MethodDecorators is a dataclass that encapsulates information about method decorators.
29
-
30
- Attributes
31
- ----------
32
- user_defined : tuple[str, ...]
33
- A tuple containing the names of user-defined decorators applied to a method.
34
- native : tuple[str, ...]
35
- A tuple containing the names of native or built-in decorators applied to a method.
36
- all : tuple[str, ...]
37
- A tuple containing the names of all decorators (both user-defined and native) applied to a method.
38
- """
39
- user_defined: tuple[str, ...]
40
- native: tuple[str, ...]
41
- all: tuple[str, ...]
42
-
43
- class ReflectDecorators(ast.NodeVisitor):
44
- """
45
- A class to analyze and extract decorators applied to a specific class or its methods.
46
-
47
- This class uses the `ast` module to parse the source code of a given class and
48
- extract the names of decorators applied to the class or its methods.
49
-
50
- Parameters
51
- ----------
52
- cls : Type
53
- The class to analyze for decorators.
54
-
55
- Attributes
56
- ----------
57
- decorators : List[str]
58
- A list of unique decorator names applied to the class or its methods.
59
-
60
- Methods
61
- -------
62
- parse()
63
- Parses the source code of the class and extracts decorator names.
64
- visit_FunctionDef(node)
65
- Visits function definitions in the AST and extracts their decorators.
66
- visit_ClassDef(node)
67
- Visits the class definition in the AST and extracts its decorators.
68
- get_class_decorators() -> List[str]
69
- Retrieves the decorators applied to the class itself.
70
- get_method_decorators(method_name: str) -> List[str]
71
- Retrieves the decorators for a specific method in the class.
72
- """
73
-
74
- def __init__(self, cls: Type):
75
- """
76
- Initializes the ReflectiveDecorators with the class to analyze.
77
-
78
- Parameters
79
- ----------
80
- cls : Type
81
- The class to analyze for decorators.
82
- """
83
- self._decorators: List[str] = []
84
- self._method_decorators: dict = {}
85
- self._class_decorators: List[str] = []
86
- self._cls = cls
87
- self._parsed = False
88
-
89
- def visit_ParseSource(self) -> None:
90
- """
91
- Parses the source code of the class and extracts decorator names.
92
-
93
- This method retrieves the source code of the class using `inspect.getsource`,
94
- parses it into an abstract syntax tree (AST), and visits relevant nodes
95
- to extract decorator names.
96
-
97
- Returns
98
- -------
99
- dict
100
- A dictionary containing lists of decorators:
101
- - 'decorators': All unique decorators found in the class and its methods.
102
- - 'method_decorators': A dictionary mapping method names to their decorators.
103
- - 'class_decorators': A list of decorators applied to the class itself.
104
- """
105
- if not self._parsed:
106
-
107
- # Try to get the source code of the class
108
- try:
109
- source = inspect.getsource(self._cls)
110
- except (OSError, TypeError):
111
- source = ""
112
-
113
- # Parsed flag to avoid re-parsing
114
- self._parsed = True
115
-
116
- # If source code is not available, return empty lists
117
- if not source:
118
- return
119
-
120
- # Parse the source code into an AST
121
- tree = ast.parse(source)
122
-
123
- # Visit the AST to extract decorators
124
- self.visit(tree)
125
-
126
- # Remove duplicates and non-decorator entries
127
- self._decorators = list(set(self._decorators))
128
-
129
- def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
130
- """
131
- Visits function definitions in the AST and extracts their decorators.
132
-
133
- Parameters
134
- ----------
135
- node : ast.FunctionDef
136
- The function definition node in the AST.
137
-
138
- Returns
139
- -------
140
- None
141
- """
142
- method_decos = []
143
- for deco in node.decorator_list:
144
- if isinstance(deco, ast.Name):
145
- self._decorators.append(deco.id)
146
- method_decos.append(deco.id)
147
- elif isinstance(deco, ast.Call):
148
- # Handles decorators with arguments like @deco(arg)
149
- if isinstance(deco.func, ast.Name):
150
- self._decorators.append(deco.func.id)
151
- method_decos.append(deco.func.id)
152
- elif isinstance(deco, ast.Attribute):
153
- self._decorators.append(deco.attr)
154
- method_decos.append(deco.attr)
155
-
156
- # Store method-specific decorators
157
- self._method_decorators[node.name] = method_decos
158
-
159
- def visit_ClassDef(self, node: ast.ClassDef) -> None:
160
- """
161
- Visits the class definition in the AST and extracts its decorators.
162
-
163
- Parameters
164
- ----------
165
- node : ast.ClassDef
166
- The class definition node in the AST.
167
-
168
- Returns
169
- -------
170
- None
171
- """
172
- if node.name == self._cls.__name__:
173
- for deco in node.decorator_list:
174
- if isinstance(deco, ast.Name):
175
- self._decorators.append(deco.id)
176
- self._class_decorators.append(deco.id)
177
- elif isinstance(deco, ast.Call):
178
- # Handles decorators with arguments like @deco(arg)
179
- if isinstance(deco.func, ast.Name):
180
- self._decorators.append(deco.func.id)
181
- self._class_decorators.append(deco.func.id)
182
- elif isinstance(deco, ast.Attribute):
183
- self._decorators.append(deco.attr)
184
- self._class_decorators.append(deco.attr)
185
-
186
- # Visit methods within the class
187
- for child in node.body:
188
- if isinstance(child, ast.FunctionDef):
189
- self.visit_FunctionDef(child)
190
-
191
- # No need to visit deeper
192
- return
193
-
194
- def visit_NativeDecorator(self, decorator_name: str) -> bool:
195
- """
196
- Checks if a decorator name matches Python's native decorator patterns.
197
- Parameters
198
- ----------
199
- decorator_name : str
200
- The name of the decorator to check.
201
- Returns
202
- -------
203
- bool
204
- True if the decorator name matches any of the predefined native patterns,
205
- False otherwise.
206
- Notes
207
- -----
208
- The method uses a list of regular expressions to identify native Python
209
- decorators, including built-ins, standard library modules (e.g., `functools`,
210
- `dataclasses`, `contextlib`), and other commonly used patterns. It also
211
- accounts for deprecated or obsolete decorators.
212
- """
213
-
214
- native_decorator_regular_expr = [
215
- # Built-ins
216
- r"^property$",
217
- r"^\w+\.setter$",
218
- r"^\w+\.deleter$",
219
- r"^classmethod$",
220
- r"^staticmethod$",
221
-
222
- # abc module
223
- r"^abstractmethod$",
224
- r"^abstractclassmethod$",
225
- r"^abstractstaticmethod$",
226
-
227
- # functools
228
- r"^functools\.cache$",
229
- r"^functools\.lru_cache(\(.*\))?$",
230
- r"^functools\.cached_property$",
231
- r"^functools\.singledispatch$",
232
- r"^functools\.singledispatchmethod$",
233
- r"^functools\.wraps(\(.*\))?$",
234
-
235
- # dataclasses
236
- r"^dataclasses\.dataclass(\(.*\))?$",
237
-
238
- # contextlib
239
- r"^contextlib\.contextmanager$",
240
-
241
- # typing
242
- r"^typing\.final$",
243
- r"^typing\.overload$",
244
-
245
- # enum
246
- r"^enum\.unique$",
247
-
248
- # asyncio (obsoleto)
249
- r"^asyncio\.coroutine$",
250
-
251
- # unittest.mock
252
- r"^unittest\.mock\.patch(\(.*\))?$",
253
-
254
- # Añadidos adicionales
255
- r"^contextlib\.asynccontextmanager$",
256
- r"^typing\.runtime_checkable$",
257
- r"^collections\.abc\.abstractproperty$",
258
- ]
259
-
260
- return any(re.fullmatch(pattern, decorator_name) for pattern in native_decorator_regular_expr)
261
-
262
- def getClassDecorators(self) -> ClassDecorators:
263
- """
264
- Retrieves the decorators applied to the class itself.
265
-
266
- Returns
267
- -------
268
- ClassDecorators
269
- An object containing lists of decorator names for the class.
270
- """
271
-
272
- # Parse the source code to extract decorators
273
- self.visit_ParseSource()
274
-
275
- # Filter decorators into user-defined and native
276
- user_defined = []
277
- native = []
278
-
279
- # Filter decorators into user-defined and native
280
- for deco in self._class_decorators:
281
- if not self.visit_NativeDecorator(deco):
282
- user_defined.append(deco)
283
- else:
284
- native.append(deco)
285
-
286
- # Return a ClassDecorators object containing the filtered lists
287
- return ClassDecorators(
288
- user_defined=tuple(user_defined),
289
- native=tuple(native),
290
- all=tuple(self._class_decorators)
291
- )
292
-
293
- def getMethodDecorators(self, method_name: str = None) -> MethodDecorators:
294
- """
295
- Retrieves the decorators for a specific method in the class.
296
-
297
- Parameters
298
- ----------
299
- method_name : str
300
- The name of the method to retrieve decorators for.
301
-
302
- Returns
303
- -------
304
- MethodDecorators
305
- An object containing lists of decorator names for the specified method.
306
- """
307
-
308
- # Parse the source code to extract decorators
309
- self.visit_ParseSource()
310
-
311
- # Handle mangled names for private methods
312
- # Check if the method name is mangled (private)
313
- if method_name.startswith("__") and not method_name.endswith("__"):
314
- method_name = f"_{self._cls.__name__}{method_name}"
315
-
316
- # Get the decorators for the specified method
317
- decorators = self._method_decorators.get(method_name, [])
318
-
319
- # Filter decorators into user-defined and native
320
- user_defined = []
321
- native = []
322
-
323
- # Filter decorators into user-defined and native
324
- for deco in decorators:
325
- if not self.visit_NativeDecorator(deco):
326
- user_defined.append(deco)
327
- else:
328
- native.append(deco)
329
-
330
- # Return a MethodDecorators object containing the filtered lists
331
- return MethodDecorators(
332
- user_defined=tuple(user_defined),
333
- native=tuple(native),
334
- all=tuple(decorators)
335
- )
@@ -1,216 +0,0 @@
1
- import abc
2
- from typing import Any, Type, TypeVar
3
- from orionis._contracts.support.reflection import IReflection
4
- from orionis.support.introspection.helpers.functions import HelpersReflection
5
- from orionis.support.introspection.abstracts.reflect_abstract import ReflexionAbstract
6
- from orionis.support.introspection.reflexion_concrete import ReflexionConcrete
7
- from orionis.support.introspection.reflexion_concrete_with_abstract import ReflexionConcreteWithAbstract
8
- from orionis.support.introspection.instances.reflection_instance import ReflectionInstance
9
- from orionis.support.introspection.reflexion_instance_with_abstract import ReflexionInstanceWithAbstract
10
- from orionis.support.introspection.reflexion_module import ReflexionModule
11
- from orionis.support.introspection.reflexion_module_with_classname import ReflexionModuleWithClassName
12
-
13
- T = TypeVar('T')
14
- ABC = TypeVar('ABC', bound=abc.ABC)
15
-
16
- class Reflection(IReflection):
17
- """A static class providing factory methods for creating reflection objects.
18
-
19
- This class provides methods to create various types of reflection objects
20
- that encapsulate different aspects of Python's reflection capabilities.
21
- Each method validates its inputs before creating the appropriate reflection object.
22
-
23
- Methods
24
- -------
25
- instance(instance: Any) -> ReflexionInstance
26
- Creates a reflection object for a class instance
27
- instanceWithAbstract(instance: Any, abstract: Type[ABC]) -> ReflexionInstanceWithAbstract
28
- Creates a reflection object for a class instance with its abstract parent
29
- abstract(abstract: Type[ABC]) -> ReflexionAbstract
30
- Creates a reflection object for an abstract class
31
- concrete(concrete: Type[T]) -> ReflexionConcrete
32
- Creates a reflection object for a concrete class
33
- concreteWithAbstract(concrete: Type[T], abstract: Type[ABC]) -> ReflexionConcreteWithAbstract
34
- Creates a reflection object for a concrete class with its abstract parent
35
- module(module: str) -> ReflexionModule
36
- Creates a reflection object for a module
37
- moduleWithClassName(module: str, class_name: str) -> ReflexionModuleWithClassName
38
- Creates a reflection object for a module with a specific class name
39
- """
40
-
41
- @staticmethod
42
- def instance(instance: Any) -> 'ReflectionInstance':
43
- """Create a reflection object for a class instance.
44
-
45
- Parameters
46
- ----------
47
- instance : Any
48
- The instance to reflect upon
49
-
50
- Returns
51
- -------
52
- ReflectionInstance
53
- A reflection object encapsulating the instance
54
-
55
- Raises
56
- ------
57
- TypeError
58
- If the input is not an object instance
59
- ValueError
60
- If the instance is from builtins, abc, or __main__
61
- """
62
- HelpersReflection.ensureUserDefinedClassInstance(instance)
63
- return ReflectionInstance(instance)
64
-
65
- @staticmethod
66
- def instanceWithAbstract(instance: Any, abstract: Type[ABC]) -> 'ReflexionInstanceWithAbstract':
67
- """Create a reflection object for a class instance with its abstract parent.
68
-
69
- Parameters
70
- ----------
71
- instance : Any
72
- The instance to reflect upon
73
- abstract : Type[ABC]
74
- The abstract parent class
75
-
76
- Returns
77
- -------
78
- ReflexionInstanceWithAbstract
79
- A reflection object encapsulating the instance and its abstract parent
80
-
81
- Raises
82
- ------
83
- TypeError
84
- If the instance is not an object or abstract is not a class
85
- ValueError
86
- If the instance is invalid or abstract is not actually abstract
87
- """
88
- HelpersReflection.ensureUserDefinedClassInstance(instance)
89
- HelpersReflection.ensureAbstractClass(abstract)
90
- return ReflexionInstanceWithAbstract(instance, abstract)
91
-
92
- @staticmethod
93
- def abstract(abstract: Type[ABC]) -> 'ReflexionAbstract':
94
- """Create a reflection object for an abstract class.
95
-
96
- Parameters
97
- ----------
98
- abstract : Type[ABC]
99
- The abstract class to reflect upon
100
-
101
- Returns
102
- -------
103
- ReflexionAbstract
104
- A reflection object encapsulating the abstract class
105
-
106
- Raises
107
- ------
108
- TypeError
109
- If the input is not a class
110
- ValueError
111
- If the class is not abstract
112
- """
113
- HelpersReflection.ensureAbstractClass(abstract)
114
- return ReflexionAbstract(abstract)
115
-
116
- @staticmethod
117
- def concrete(concrete: Type[T]) -> 'ReflexionConcrete':
118
- """Create a reflection object for a concrete class.
119
-
120
- Parameters
121
- ----------
122
- concrete : Type[T]
123
- The concrete class to reflect upon
124
-
125
- Returns
126
- -------
127
- ReflexionConcrete
128
- A reflection object encapsulating the concrete class
129
-
130
- Raises
131
- ------
132
- TypeError
133
- If the input is not a class
134
- ValueError
135
- If the class is abstract or cannot be instantiated
136
- """
137
- HelpersReflection.ensureInstantiableClass(concrete)
138
- return ReflexionConcrete(concrete)
139
-
140
- @staticmethod
141
- def concreteWithAbstract(concrete: Type[T], abstract: Type[ABC]) -> 'ReflexionConcreteWithAbstract':
142
- """Create a reflection object for a concrete class with its abstract parent.
143
-
144
- Parameters
145
- ----------
146
- concrete : Type[T]
147
- The concrete class to reflect upon
148
- abstract : Type[ABC]
149
- The abstract parent class
150
-
151
- Returns
152
- -------
153
- ReflexionConcreteWithAbstract
154
- A reflection object encapsulating the concrete class and its abstract parent
155
-
156
- Raises
157
- ------
158
- TypeError
159
- If either input is not a class
160
- ValueError
161
- If concrete is not instantiable or abstract is not actually abstract
162
- """
163
- HelpersReflection.ensureInstantiableClass(concrete)
164
- HelpersReflection.ensureAbstractClass(abstract)
165
- return ReflexionConcreteWithAbstract(concrete, abstract)
166
-
167
- @staticmethod
168
- def module(module: str) -> 'ReflexionModule':
169
- """Create a reflection object for a module.
170
-
171
- Parameters
172
- ----------
173
- module : str
174
- The module name to reflect upon
175
-
176
- Returns
177
- -------
178
- ReflexionModule
179
- A reflection object encapsulating the module
180
-
181
- Raises
182
- ------
183
- TypeError
184
- If the input is not a string
185
- ValueError
186
- If the module cannot be imported
187
- """
188
- HelpersReflection.ensureValidModule(module)
189
- return ReflexionModule(module)
190
-
191
- @staticmethod
192
- def moduleWithClassName(module: str, class_name: str) -> 'ReflexionModuleWithClassName':
193
- """Create a reflection object for a module with a specific class name.
194
-
195
- Parameters
196
- ----------
197
- module : str
198
- The module name to reflect upon
199
- class_name : str
200
- The class name to look for in the module
201
-
202
- Returns
203
- -------
204
- ReflexionModuleWithClassName
205
- A reflection object encapsulating the module and class name
206
-
207
- Raises
208
- ------
209
- TypeError
210
- If either input is not a string
211
- ValueError
212
- If the module cannot be imported or the class doesn't exist in it
213
- """
214
- HelpersReflection.ensureValidModule(module)
215
- HelpersReflection.ensureValidClassName(class_name)
216
- return ReflexionModuleWithClassName(module, class_name)