orionis 0.213.0__py3-none-any.whl → 0.216.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.
- orionis/framework.py +1 -1
- orionis/luminate/console/output/console.py +2 -2
- orionis/luminate/support/inspection/contracts/__init__.py +0 -0
- orionis/luminate/support/inspection/contracts/reflection.py +187 -0
- orionis/luminate/support/inspection/contracts/reflexion_abstract.py +265 -0
- orionis/luminate/support/inspection/reflection.py +2 -1
- orionis/luminate/support/inspection/reflexion_abstract.py +2 -1
- orionis/luminate/support/parsers/__init__.py +0 -0
- orionis/luminate/support/parsers/contracts/__init__.py +0 -0
- orionis/luminate/support/parsers/contracts/exception_parser.py +38 -0
- orionis/luminate/support/parsers/exception_parser.py +107 -0
- orionis/luminate/support/standard/__init__.py +0 -0
- orionis/luminate/support/standard/contracts/__init__.py +0 -0
- orionis/luminate/support/standard/contracts/std.py +127 -0
- orionis/luminate/support/standard/std.py +137 -0
- {orionis-0.213.0.dist-info → orionis-0.216.0.dist-info}/METADATA +1 -1
- {orionis-0.213.0.dist-info → orionis-0.216.0.dist-info}/RECORD +28 -15
- tests/support/inspection/test_reflection_concrete.py +4 -1
- tests/support/parsers/__init__.py +0 -0
- tests/support/parsers/fakes/__init__.py +0 -0
- tests/support/parsers/fakes/fake_custom_error.py +27 -0
- tests/support/parsers/test_exception_parser.py +59 -0
- tests/support/standard/__init__.py +0 -0
- tests/support/standard/test_std.py +58 -0
- orionis/luminate/contracts/support/std.py +0 -43
- orionis/luminate/support/exception_parse.py +0 -47
- orionis/luminate/support/reflection.py +0 -390
- orionis/luminate/support/std.py +0 -53
- {orionis-0.213.0.dist-info → orionis-0.216.0.dist-info}/LICENCE +0 -0
- {orionis-0.213.0.dist-info → orionis-0.216.0.dist-info}/WHEEL +0 -0
- {orionis-0.213.0.dist-info → orionis-0.216.0.dist-info}/entry_points.txt +0 -0
- {orionis-0.213.0.dist-info → orionis-0.216.0.dist-info}/top_level.txt +0 -0
@@ -1,390 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import inspect
|
3
|
-
import importlib
|
4
|
-
from enum import Enum
|
5
|
-
from typing import Any, List, Optional
|
6
|
-
from orionis.luminate.contracts.support.reflection import IReflection
|
7
|
-
|
8
|
-
class Reflection(IReflection):
|
9
|
-
"""
|
10
|
-
The Reflection class dynamically loads a class from a module and inspects its attributes,
|
11
|
-
methods, properties, and other properties at runtime. It supports checking the existence of
|
12
|
-
classes, methods, properties, constants, and can instantiate classes if they are not abstract.
|
13
|
-
|
14
|
-
Attributes
|
15
|
-
----------
|
16
|
-
classname : str, optional
|
17
|
-
The name of the class to reflect upon. Default is None.
|
18
|
-
module_name : str, optional
|
19
|
-
The name of the module where the class is defined. Default is None.
|
20
|
-
cls : type, optional
|
21
|
-
The class object after it has been imported and assigned. Default is None.
|
22
|
-
"""
|
23
|
-
|
24
|
-
def __init__(self, target: Optional[Any] = None, module: Optional[str] = None):
|
25
|
-
"""
|
26
|
-
Initializes the Reflection instance with an optional class name, module name, or instance.
|
27
|
-
|
28
|
-
Parameters
|
29
|
-
----------
|
30
|
-
target : Any, optional
|
31
|
-
The class name as a string, the class type, or an instance of the class. Default is None.
|
32
|
-
module : str, optional
|
33
|
-
The name of the module where the class is defined. Default is None.
|
34
|
-
"""
|
35
|
-
self.classname = None
|
36
|
-
self.module_name = module
|
37
|
-
self.cls = None
|
38
|
-
|
39
|
-
if isinstance(target, str):
|
40
|
-
self.classname = target
|
41
|
-
elif isinstance(target, type):
|
42
|
-
self.cls = target
|
43
|
-
self.classname = target.__name__
|
44
|
-
elif target is not None:
|
45
|
-
self.cls = target.__class__
|
46
|
-
self.classname = self.cls.__name__
|
47
|
-
|
48
|
-
if self.module_name and not self.cls:
|
49
|
-
self.safeImport()
|
50
|
-
|
51
|
-
def safeImport(self):
|
52
|
-
"""
|
53
|
-
Safely imports the specified module and assigns the class object if a classname is provided.
|
54
|
-
|
55
|
-
This method raises a ValueError if the module cannot be imported or if the class does not exist
|
56
|
-
within the module.
|
57
|
-
|
58
|
-
Raises
|
59
|
-
------
|
60
|
-
ValueError
|
61
|
-
If the module cannot be imported or the class does not exist in the module.
|
62
|
-
"""
|
63
|
-
try:
|
64
|
-
module = importlib.import_module(self.module_name)
|
65
|
-
if self.classname:
|
66
|
-
self.cls = getattr(module, self.classname, None)
|
67
|
-
if self.cls is None:
|
68
|
-
raise ValueError(f"Class '{self.classname}' not found in module '{self.module_name}'.")
|
69
|
-
except ImportError as e:
|
70
|
-
raise ValueError(f"Error importing module '{self.module_name}': {e}")
|
71
|
-
|
72
|
-
def getFile(self) -> str:
|
73
|
-
"""
|
74
|
-
Retrieves the file path where the class is defined.
|
75
|
-
|
76
|
-
Returns
|
77
|
-
-------
|
78
|
-
str
|
79
|
-
The file path if the class is found, otherwise raises an error.
|
80
|
-
|
81
|
-
Raises
|
82
|
-
------
|
83
|
-
ValueError
|
84
|
-
If the class has not been loaded yet.
|
85
|
-
"""
|
86
|
-
if not self.cls:
|
87
|
-
raise ValueError("Class not loaded. Use 'safeImport()' first.")
|
88
|
-
return inspect.getfile(self.cls)
|
89
|
-
|
90
|
-
def hasClass(self) -> bool:
|
91
|
-
"""
|
92
|
-
Checks whether the class object is available.
|
93
|
-
|
94
|
-
Returns
|
95
|
-
-------
|
96
|
-
bool
|
97
|
-
True if the class is loaded, False otherwise.
|
98
|
-
"""
|
99
|
-
return self.cls is not None
|
100
|
-
|
101
|
-
def hasMethod(self, method_name: str) -> bool:
|
102
|
-
"""
|
103
|
-
Checks whether the specified method exists in the class.
|
104
|
-
|
105
|
-
Parameters
|
106
|
-
----------
|
107
|
-
method_name : str
|
108
|
-
The name of the method to check.
|
109
|
-
|
110
|
-
Returns
|
111
|
-
-------
|
112
|
-
bool
|
113
|
-
True if the method exists, False otherwise.
|
114
|
-
"""
|
115
|
-
return hasattr(self.cls, method_name) if self.cls else False
|
116
|
-
|
117
|
-
def hasProperty(self, prop: str) -> bool:
|
118
|
-
"""
|
119
|
-
Checks whether the specified property exists in the class.
|
120
|
-
|
121
|
-
Parameters
|
122
|
-
----------
|
123
|
-
prop : str
|
124
|
-
The name of the property to check.
|
125
|
-
|
126
|
-
Returns
|
127
|
-
-------
|
128
|
-
bool
|
129
|
-
True if the property exists, False otherwise.
|
130
|
-
"""
|
131
|
-
return hasattr(self.cls, prop) if self.cls else False
|
132
|
-
|
133
|
-
def hasConstant(self, constant: str) -> bool:
|
134
|
-
"""
|
135
|
-
Checks whether the specified constant exists in the class.
|
136
|
-
|
137
|
-
Parameters
|
138
|
-
----------
|
139
|
-
constant : str
|
140
|
-
The name of the constant to check.
|
141
|
-
|
142
|
-
Returns
|
143
|
-
-------
|
144
|
-
bool
|
145
|
-
True if the constant exists, False otherwise.
|
146
|
-
"""
|
147
|
-
return hasattr(self.cls, constant) if self.cls else False
|
148
|
-
|
149
|
-
def getAttributes(self) -> List[str]:
|
150
|
-
"""
|
151
|
-
Retrieves a list of all attributes (including methods and properties) of the class.
|
152
|
-
|
153
|
-
Returns
|
154
|
-
-------
|
155
|
-
list
|
156
|
-
A list of attribute names in the class.
|
157
|
-
"""
|
158
|
-
return dir(self.cls) if self.cls else []
|
159
|
-
|
160
|
-
def getConstructor(self):
|
161
|
-
"""
|
162
|
-
Retrieves the constructor (__init__) of the class.
|
163
|
-
|
164
|
-
Returns
|
165
|
-
-------
|
166
|
-
function or None
|
167
|
-
The constructor method if available, otherwise None.
|
168
|
-
"""
|
169
|
-
return self.cls.__init__ if self.cls else None
|
170
|
-
|
171
|
-
def getDocComment(self) -> Optional[str]:
|
172
|
-
"""
|
173
|
-
Retrieves the docstring of the class.
|
174
|
-
|
175
|
-
Returns
|
176
|
-
-------
|
177
|
-
str or None
|
178
|
-
The docstring of the class if available, otherwise None.
|
179
|
-
"""
|
180
|
-
if not self.cls:
|
181
|
-
raise ValueError("Class not loaded. Use 'safeImport()' first.")
|
182
|
-
return self.cls.__doc__
|
183
|
-
|
184
|
-
def getFileName(self, remove_extension: bool = False) -> str:
|
185
|
-
"""
|
186
|
-
Retrieves the file name where the class is defined, the same as `get_file()`.
|
187
|
-
|
188
|
-
Parameters
|
189
|
-
----------
|
190
|
-
remove_extension : bool, optional
|
191
|
-
If True, the file extension will be removed from the filename. Default is False.
|
192
|
-
|
193
|
-
Returns
|
194
|
-
-------
|
195
|
-
str
|
196
|
-
The file name of the class definition.
|
197
|
-
"""
|
198
|
-
file_name = os.path.basename(self.getFile())
|
199
|
-
if remove_extension:
|
200
|
-
file_name = os.path.splitext(file_name)[0]
|
201
|
-
return file_name
|
202
|
-
|
203
|
-
def getMethod(self, method_name: str):
|
204
|
-
"""
|
205
|
-
Retrieves the specified method from the class.
|
206
|
-
|
207
|
-
Parameters
|
208
|
-
----------
|
209
|
-
method_name : str
|
210
|
-
The name of the method to retrieve.
|
211
|
-
|
212
|
-
Returns
|
213
|
-
-------
|
214
|
-
function or None
|
215
|
-
The method if it exists, otherwise None.
|
216
|
-
"""
|
217
|
-
return getattr(self.cls, method_name, None) if self.cls else None
|
218
|
-
|
219
|
-
def getMethods(self) -> List[str]:
|
220
|
-
"""
|
221
|
-
Retrieves a list of all methods in the class.
|
222
|
-
|
223
|
-
Returns
|
224
|
-
-------
|
225
|
-
list
|
226
|
-
A list of method names in the class.
|
227
|
-
"""
|
228
|
-
return [method for method, _ in inspect.getmembers(self.cls, predicate=inspect.isfunction)] if self.cls else []
|
229
|
-
|
230
|
-
def getName(self) -> str:
|
231
|
-
"""
|
232
|
-
Retrieves the name of the class.
|
233
|
-
|
234
|
-
Returns
|
235
|
-
-------
|
236
|
-
str or None
|
237
|
-
The name of the class if available, otherwise None.
|
238
|
-
"""
|
239
|
-
return self.cls.__name__ if self.cls else None
|
240
|
-
|
241
|
-
def getParentClass(self) -> Optional[tuple]:
|
242
|
-
"""
|
243
|
-
Retrieves the parent classes (base classes) of the class.
|
244
|
-
|
245
|
-
Returns
|
246
|
-
-------
|
247
|
-
tuple or None
|
248
|
-
A tuple of base classes if available, otherwise None.
|
249
|
-
"""
|
250
|
-
return self.cls.__bases__ if self.cls else None
|
251
|
-
|
252
|
-
def getProperties(self) -> List[str]:
|
253
|
-
"""
|
254
|
-
Retrieves a list of all properties of the class.
|
255
|
-
|
256
|
-
Returns
|
257
|
-
-------
|
258
|
-
list
|
259
|
-
A list of property names in the class.
|
260
|
-
"""
|
261
|
-
return [name for name, value in inspect.getmembers(self.cls, lambda x: isinstance(x, property))] if self.cls else []
|
262
|
-
|
263
|
-
def getProperty(self, prop: str):
|
264
|
-
"""
|
265
|
-
Retrieves the specified property from the class.
|
266
|
-
|
267
|
-
Parameters
|
268
|
-
----------
|
269
|
-
prop : str
|
270
|
-
The name of the property to retrieve.
|
271
|
-
|
272
|
-
Returns
|
273
|
-
-------
|
274
|
-
property or None
|
275
|
-
The property if it exists, otherwise None.
|
276
|
-
"""
|
277
|
-
return getattr(self.cls, prop, None) if self.cls else None
|
278
|
-
|
279
|
-
def isAbstract(self) -> bool:
|
280
|
-
"""
|
281
|
-
Checks whether the class is abstract.
|
282
|
-
|
283
|
-
Returns
|
284
|
-
-------
|
285
|
-
bool
|
286
|
-
True if the class is abstract, False otherwise.
|
287
|
-
"""
|
288
|
-
return hasattr(self.cls, '__abstractmethods__') and bool(self.cls.__abstractmethods__) if self.cls else False
|
289
|
-
|
290
|
-
def isEnum(self) -> bool:
|
291
|
-
"""
|
292
|
-
Checks whether the class is an enumeration.
|
293
|
-
|
294
|
-
Returns
|
295
|
-
-------
|
296
|
-
bool
|
297
|
-
True if the class is a subclass of Enum, False otherwise.
|
298
|
-
"""
|
299
|
-
return self.cls is not None and isinstance(self.cls, type) and issubclass(self.cls, Enum)
|
300
|
-
|
301
|
-
def isSubclassOf(self, parent: type) -> bool:
|
302
|
-
"""
|
303
|
-
Checks whether the class is a subclass of the specified parent class.
|
304
|
-
|
305
|
-
Parameters
|
306
|
-
----------
|
307
|
-
parent : type
|
308
|
-
The parent class to check against.
|
309
|
-
|
310
|
-
Returns
|
311
|
-
-------
|
312
|
-
bool
|
313
|
-
True if the class is a subclass of the parent, False otherwise.
|
314
|
-
"""
|
315
|
-
return self.cls is not None and issubclass(self.cls, parent)
|
316
|
-
|
317
|
-
def isInstanceOf(self, instance: Any) -> bool:
|
318
|
-
"""
|
319
|
-
Checks whether the class is an instance of the specified class.
|
320
|
-
|
321
|
-
Parameters
|
322
|
-
----------
|
323
|
-
parent : type
|
324
|
-
The class to check against.
|
325
|
-
|
326
|
-
Returns
|
327
|
-
-------
|
328
|
-
bool
|
329
|
-
True if the class is a subclass of the parent, False otherwise.
|
330
|
-
"""
|
331
|
-
return self.cls is not None and isinstance(instance, self.cls)
|
332
|
-
|
333
|
-
def isIterable(self) -> bool:
|
334
|
-
"""
|
335
|
-
Checks whether the class is iterable.
|
336
|
-
|
337
|
-
Returns
|
338
|
-
-------
|
339
|
-
bool
|
340
|
-
True if the class is iterable, False otherwise.
|
341
|
-
"""
|
342
|
-
return hasattr(self.cls, '__iter__') if self.cls else False
|
343
|
-
|
344
|
-
def isInstantiable(self) -> bool:
|
345
|
-
"""
|
346
|
-
Checks whether the class can be instantiated.
|
347
|
-
|
348
|
-
Returns
|
349
|
-
-------
|
350
|
-
bool
|
351
|
-
True if the class is callable and not abstract, False otherwise.
|
352
|
-
"""
|
353
|
-
return self.cls is not None and callable(self.cls) and not self.isAbstract()
|
354
|
-
|
355
|
-
def newInstance(self, *args, **kwargs):
|
356
|
-
"""
|
357
|
-
Creates a new instance of the class if it is instantiable.
|
358
|
-
|
359
|
-
Parameters
|
360
|
-
----------
|
361
|
-
args : tuple
|
362
|
-
Arguments to pass to the class constructor.
|
363
|
-
kwargs : dict
|
364
|
-
Keyword arguments to pass to the class constructor.
|
365
|
-
|
366
|
-
Returns
|
367
|
-
-------
|
368
|
-
object
|
369
|
-
A new instance of the class.
|
370
|
-
|
371
|
-
Raises
|
372
|
-
------
|
373
|
-
TypeError
|
374
|
-
If the class is not instantiable.
|
375
|
-
"""
|
376
|
-
if self.isInstantiable():
|
377
|
-
return self.cls(*args, **kwargs)
|
378
|
-
raise TypeError(f"Cannot instantiate class '{self.classname}'. It may be abstract or not callable.")
|
379
|
-
|
380
|
-
def __str__(self) -> str:
|
381
|
-
"""
|
382
|
-
Returns a string representation of the Reflection instance.
|
383
|
-
|
384
|
-
Returns
|
385
|
-
-------
|
386
|
-
str
|
387
|
-
A string describing the class and module.
|
388
|
-
"""
|
389
|
-
status = "loaded" if self.cls else "not loaded"
|
390
|
-
return f"<Orionis Reflection class '{self.classname}' in module '{self.module_name}' ({status})>"
|
orionis/luminate/support/std.py
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
from orionis.luminate.contracts.support.std import IStdClass
|
2
|
-
|
3
|
-
class StdClass(IStdClass):
|
4
|
-
"""
|
5
|
-
A dynamic class that allows setting arbitrary attributes,
|
6
|
-
similar to PHP's stdClass.
|
7
|
-
"""
|
8
|
-
|
9
|
-
def __init__(self, **kwargs):
|
10
|
-
"""
|
11
|
-
Initializes the StdClass with optional keyword arguments.
|
12
|
-
|
13
|
-
Parameters
|
14
|
-
----------
|
15
|
-
kwargs : dict
|
16
|
-
Key-value pairs to set as attributes.
|
17
|
-
"""
|
18
|
-
for key, value in kwargs.items():
|
19
|
-
setattr(self, key, value)
|
20
|
-
|
21
|
-
def __repr__(self):
|
22
|
-
"""
|
23
|
-
Returns a string representation of the object.
|
24
|
-
|
25
|
-
Returns
|
26
|
-
-------
|
27
|
-
str
|
28
|
-
A formatted string showing the object's attributes.
|
29
|
-
"""
|
30
|
-
return f"{self.__class__.__name__}({self.__dict__})"
|
31
|
-
|
32
|
-
def toDict(self):
|
33
|
-
"""
|
34
|
-
Converts the object's attributes to a dictionary.
|
35
|
-
|
36
|
-
Returns
|
37
|
-
-------
|
38
|
-
dict
|
39
|
-
A dictionary representation of the object's attributes.
|
40
|
-
"""
|
41
|
-
return self.__dict__
|
42
|
-
|
43
|
-
def update(self, **kwargs):
|
44
|
-
"""
|
45
|
-
Updates the object's attributes dynamically.
|
46
|
-
|
47
|
-
Parameters
|
48
|
-
----------
|
49
|
-
kwargs : dict
|
50
|
-
Key-value pairs to update attributes.
|
51
|
-
"""
|
52
|
-
for key, value in kwargs.items():
|
53
|
-
setattr(self, key, value)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|