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.
- orionis/metadata/framework.py +1 -1
- orionis/services/introspection/modules/{reflection_instance.py → reflection_module.py} +1 -1
- orionis/services/introspection/reflection.py +90 -0
- orionis/{services → support}/standard/std.py +2 -2
- orionis/test/{facade/test_suite.py → test_suite.py} +1 -2
- orionis/unittesting.py +1 -1
- {orionis-0.304.0.dist-info → orionis-0.306.0.dist-info}/METADATA +1 -1
- {orionis-0.304.0.dist-info → orionis-0.306.0.dist-info}/RECORD +28 -65
- tests/{services → support}/standard/test_services_std.py +3 -3
- tests/{services → support}/wrapper/test_services_wrapper_docdict.py +2 -2
- orionis/support/abstracts/entities/abstract_class_attributes.py +0 -37
- orionis/support/abstracts/reflect_abstract.py +0 -556
- orionis/support/helpers/functions.py +0 -285
- orionis/support/introspection/container_integrity.py +0 -292
- orionis/support/introspection/contracts/__init__.py +0 -0
- orionis/support/introspection/contracts/reflection.py +0 -187
- orionis/support/introspection/contracts/reflexion_abstract.py +0 -264
- orionis/support/introspection/helpers/__init__.py +0 -0
- orionis/support/introspection/helpers/functions.py +0 -281
- orionis/support/introspection/instances/__init__.py +0 -0
- orionis/support/introspection/instances/contracts/__init__.py +0 -0
- orionis/support/introspection/instances/contracts/reflection_instance.py +0 -649
- orionis/support/introspection/instances/entities/__init__.py +0 -0
- orionis/support/introspection/instances/reflection_instance.py +0 -758
- orionis/support/introspection/reflect_decorators.py +0 -335
- orionis/support/introspection/reflection.py +0 -216
- orionis/support/introspection/reflexion_concrete.py +0 -276
- orionis/support/introspection/reflexion_concrete_with_abstract.py +0 -185
- orionis/support/introspection/reflexion_instance_with_abstract.py +0 -230
- orionis/support/introspection/reflexion_module.py +0 -19
- orionis/support/introspection/reflexion_module_with_classname.py +0 -22
- orionis/support/reflection.py +0 -216
- orionis/test/facade/__init__.py +0 -0
- orionis/test/facade/contracts/__init__.py +0 -0
- orionis/test/facade/contracts/test_suite.py +0 -25
- tests/services/standard/__init__.py +0 -0
- tests/services/wrapper/__init__.py +0 -0
- tests/support/inspection/__init__.py +0 -0
- tests/support/inspection/fakes/__init__.py +0 -0
- tests/support/inspection/fakes/fake_reflect_abstract.py +0 -276
- tests/support/inspection/fakes/fake_reflection_concrete.py +0 -44
- tests/support/inspection/fakes/fake_reflection_concrete_with_abstract.py +0 -78
- tests/support/inspection/fakes/fake_reflection_instance_with_abstract.py +0 -45
- tests/support/inspection/test_reflect_abstract.py +0 -334
- tests/support/inspection/test_reflect_instance.py +0 -288
- tests/support/inspection/test_reflection_concrete.py +0 -142
- tests/support/inspection/test_reflection_concrete_with_abstract.py +0 -87
- tests/support/inspection/test_reflection_instance_with_abstract.py +0 -79
- /orionis/services/introspection/modules/contracts/{reflection_instance.py → reflection_module.py} +0 -0
- /orionis/{services → support}/standard/__init__.py +0 -0
- /orionis/{services → support}/standard/contracts/__init__.py +0 -0
- /orionis/{services → support}/standard/contracts/std.py +0 -0
- /orionis/{services → support}/standard/exceptions/__init__.py +0 -0
- /orionis/{services → support}/standard/exceptions/std_value_exception.py +0 -0
- /orionis/{services → support}/wrapper/__init__.py +0 -0
- /orionis/{services → support}/wrapper/dicts/__init__.py +0 -0
- /orionis/{services → support}/wrapper/dicts/dot_dict.py +0 -0
- {orionis-0.304.0.dist-info → orionis-0.306.0.dist-info}/WHEEL +0 -0
- {orionis-0.304.0.dist-info → orionis-0.306.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.304.0.dist-info → orionis-0.306.0.dist-info}/top_level.txt +0 -0
- {orionis-0.304.0.dist-info → orionis-0.306.0.dist-info}/zip-safe +0 -0
- {orionis/support/abstracts → tests/services/inspection/reflection}/__init__.py +0 -0
- {orionis/support/abstracts/entities → tests/services/inspection/reflection/mock}/__init__.py +0 -0
- /tests/{support/inspection/fakes → services/inspection/reflection/mock}/fake_reflect_instance.py +0 -0
- {orionis/support/helpers → tests/support/standard}/__init__.py +0 -0
- {orionis/support/introspection → tests/support/wrapper}/__init__.py +0 -0
@@ -1,285 +0,0 @@
|
|
1
|
-
import importlib
|
2
|
-
import inspect
|
3
|
-
from typing import Any, Type
|
4
|
-
|
5
|
-
class HelpersReflection:
|
6
|
-
"""
|
7
|
-
A collection of helper functions for reflection and inspection.
|
8
|
-
"""
|
9
|
-
|
10
|
-
@staticmethod
|
11
|
-
def isValidModule(module_name: str) -> bool:
|
12
|
-
"""Check if a module name is valid and can be imported.
|
13
|
-
|
14
|
-
Parameters
|
15
|
-
----------
|
16
|
-
module_name : str
|
17
|
-
The name of the module to check
|
18
|
-
|
19
|
-
Returns
|
20
|
-
-------
|
21
|
-
bool
|
22
|
-
True if the module is valid and can be imported, False otherwise
|
23
|
-
"""
|
24
|
-
try:
|
25
|
-
importlib.import_module(module_name)
|
26
|
-
return True
|
27
|
-
except ImportError:
|
28
|
-
return False
|
29
|
-
|
30
|
-
@staticmethod
|
31
|
-
def ensureValidModule(module_name: str) -> None:
|
32
|
-
"""Ensure a module name is valid and can be imported.
|
33
|
-
|
34
|
-
Parameters
|
35
|
-
----------
|
36
|
-
module_name : str
|
37
|
-
The name of the module to check
|
38
|
-
|
39
|
-
Raises
|
40
|
-
------
|
41
|
-
ValueError
|
42
|
-
If the module cannot be imported or is invalid
|
43
|
-
"""
|
44
|
-
if not isinstance(module_name, str):
|
45
|
-
raise TypeError(f"Module name must be a string, got {type(module_name)}")
|
46
|
-
if not HelpersReflection.isValidModule(module_name):
|
47
|
-
raise ValueError(f"Invalid or non-importable module: {module_name}")
|
48
|
-
|
49
|
-
@staticmethod
|
50
|
-
def isInstantiableClass(cls: Type) -> bool:
|
51
|
-
"""Check if a class is concrete and can be instantiated.
|
52
|
-
|
53
|
-
Parameters
|
54
|
-
----------
|
55
|
-
cls : Type
|
56
|
-
The class to check
|
57
|
-
|
58
|
-
Returns
|
59
|
-
--
|
60
|
-
bool
|
61
|
-
True if the class is concrete and can be instantiated, False otherwise
|
62
|
-
"""
|
63
|
-
if not isinstance(cls, type):
|
64
|
-
return False
|
65
|
-
if HelpersReflection.isAbstractClass(cls):
|
66
|
-
return False
|
67
|
-
|
68
|
-
# Try to create an instance to verify it's truly concrete
|
69
|
-
try:
|
70
|
-
cls()
|
71
|
-
return True
|
72
|
-
except TypeError:
|
73
|
-
return False
|
74
|
-
|
75
|
-
@staticmethod
|
76
|
-
def ensureNotBuiltinType(cls: Type) -> None:
|
77
|
-
"""Ensure a class is not a built-in or primitive type.
|
78
|
-
|
79
|
-
Parameters
|
80
|
-
----------
|
81
|
-
cls : Type
|
82
|
-
The class to check
|
83
|
-
|
84
|
-
Raises
|
85
|
-
------
|
86
|
-
TypeError
|
87
|
-
If the input is not a class
|
88
|
-
ValueError
|
89
|
-
If the class is a built-in or primitive type
|
90
|
-
"""
|
91
|
-
if not isinstance(cls, type):
|
92
|
-
raise TypeError(f"Expected a class, got {type(cls)}")
|
93
|
-
|
94
|
-
builtin_types = {
|
95
|
-
int, float, str, bool, bytes, type(None), complex,
|
96
|
-
list, tuple, dict, set, frozenset
|
97
|
-
}
|
98
|
-
|
99
|
-
if cls in builtin_types:
|
100
|
-
raise ValueError(f"Class '{cls.__name__}' is a built-in or primitive type and cannot be used.")
|
101
|
-
|
102
|
-
@staticmethod
|
103
|
-
def ensureInstantiableClass(cls: Type) -> None:
|
104
|
-
"""Ensure a class is concrete and can be instantiated.
|
105
|
-
|
106
|
-
Parameters
|
107
|
-
----------
|
108
|
-
cls : Type
|
109
|
-
The class to check
|
110
|
-
|
111
|
-
Raises
|
112
|
-
------
|
113
|
-
TypeError
|
114
|
-
If the input is not a class
|
115
|
-
ValueError
|
116
|
-
If the class is abstract or cannot be instantiated
|
117
|
-
"""
|
118
|
-
if HelpersReflection.ensureNotBuiltinType(cls):
|
119
|
-
raise TypeError(f"Invalid class: {cls!r}")
|
120
|
-
|
121
|
-
if not isinstance(cls, type):
|
122
|
-
raise TypeError(f"Expected a class, got {type(cls)}")
|
123
|
-
|
124
|
-
if HelpersReflection.isAbstractClass(cls):
|
125
|
-
raise ValueError(f"Class '{cls.__name__}' is abstract")
|
126
|
-
|
127
|
-
try:
|
128
|
-
cls()
|
129
|
-
except TypeError as e:
|
130
|
-
raise ValueError(f"Class '{cls.__name__}' cannot be instantiated: {str(e)}")
|
131
|
-
|
132
|
-
@staticmethod
|
133
|
-
def isValidClassName(module_name: str, class_name: str) -> bool:
|
134
|
-
"""Check if a class exists in a given module.
|
135
|
-
|
136
|
-
Parameters
|
137
|
-
----------
|
138
|
-
module_name : str
|
139
|
-
The name of the module to check
|
140
|
-
class_name : str
|
141
|
-
The name of the class to look for
|
142
|
-
|
143
|
-
Returns
|
144
|
-
-------
|
145
|
-
bool
|
146
|
-
True if the class exists in the module, False otherwise
|
147
|
-
"""
|
148
|
-
try:
|
149
|
-
module = importlib.import_module(module_name)
|
150
|
-
return hasattr(module, class_name) and inspect.isclass(getattr(module, class_name))
|
151
|
-
except ImportError:
|
152
|
-
return False
|
153
|
-
|
154
|
-
@staticmethod
|
155
|
-
def ensureValidClassName(module_name: str, class_name: str) -> None:
|
156
|
-
"""Ensure a class exists in a given module.
|
157
|
-
|
158
|
-
Parameters
|
159
|
-
----------
|
160
|
-
module_name : str
|
161
|
-
The name of the module to check
|
162
|
-
class_name : str
|
163
|
-
The name of the class to look for
|
164
|
-
|
165
|
-
Raises
|
166
|
-
------
|
167
|
-
ValueError
|
168
|
-
If the class doesn't exist in the module
|
169
|
-
"""
|
170
|
-
if not HelpersReflection.isValidClassName(module_name, class_name):
|
171
|
-
raise ValueError(f"Class '{class_name}' not found in module '{module_name}'")
|
172
|
-
|
173
|
-
@staticmethod
|
174
|
-
def isUserDefinedClassInstance(instance: Any) -> bool:
|
175
|
-
"""Check if an object is an instance of a user-defined class.
|
176
|
-
|
177
|
-
Parameters
|
178
|
-
----------
|
179
|
-
instance : Any
|
180
|
-
The object to check
|
181
|
-
|
182
|
-
Returns
|
183
|
-
-------
|
184
|
-
bool
|
185
|
-
True if the object is an instance of a user-defined class, False otherwise
|
186
|
-
"""
|
187
|
-
return isinstance(instance, object) and type(instance).__module__ not in {'builtins', 'abc', '__main__'}
|
188
|
-
|
189
|
-
@staticmethod
|
190
|
-
def ensureUserDefinedClassInstance(instance: Any) -> None:
|
191
|
-
"""Ensure an object is an instance of a user-defined class.
|
192
|
-
|
193
|
-
Parameters
|
194
|
-
----------
|
195
|
-
instance : Any
|
196
|
-
The object to check
|
197
|
-
|
198
|
-
Raises
|
199
|
-
------
|
200
|
-
TypeError
|
201
|
-
If the input is not an object instance
|
202
|
-
ValueError
|
203
|
-
If the instance is from builtins, abc, or __main__
|
204
|
-
"""
|
205
|
-
if not isinstance(instance, object):
|
206
|
-
raise TypeError(f"Invalid object: {instance!r}")
|
207
|
-
module = type(instance).__module__
|
208
|
-
if module in {'builtins', 'abc'}:
|
209
|
-
raise ValueError(f"'{instance!r}' is not a user-defined class instance, belongs to '{module}'.")
|
210
|
-
if module == '__main__':
|
211
|
-
raise ValueError("Instance originates from '__main__', origin indeterminate.")
|
212
|
-
|
213
|
-
@staticmethod
|
214
|
-
def isAbstractClass(cls: Type) -> bool:
|
215
|
-
"""Check if a class is abstract.
|
216
|
-
|
217
|
-
Parameters
|
218
|
-
----------
|
219
|
-
cls : Type
|
220
|
-
The class to check
|
221
|
-
|
222
|
-
Returns
|
223
|
-
-------
|
224
|
-
bool
|
225
|
-
True if the class is abstract, False otherwise
|
226
|
-
"""
|
227
|
-
return isinstance(cls, type) and bool(getattr(cls, '__abstractmethods__', False))
|
228
|
-
|
229
|
-
@staticmethod
|
230
|
-
def ensureAbstractClass(cls: Type) -> None:
|
231
|
-
"""Ensure a class is abstract.
|
232
|
-
|
233
|
-
Parameters
|
234
|
-
----------
|
235
|
-
cls : Type
|
236
|
-
The class to check
|
237
|
-
|
238
|
-
Raises
|
239
|
-
------
|
240
|
-
TypeError
|
241
|
-
If the input is not a class
|
242
|
-
ValueError
|
243
|
-
If the class is not abstract
|
244
|
-
"""
|
245
|
-
if not isinstance(cls, type):
|
246
|
-
raise TypeError(f"Invalid class: {cls!r}")
|
247
|
-
if not HelpersReflection.isAbstractClass(cls):
|
248
|
-
raise ValueError(f"Class '{cls.__name__}' is not abstract.")
|
249
|
-
|
250
|
-
@staticmethod
|
251
|
-
def isConcreteClass(cls: Type) -> bool:
|
252
|
-
"""Check if a class is concrete.
|
253
|
-
|
254
|
-
Parameters
|
255
|
-
----------
|
256
|
-
cls : Type
|
257
|
-
The class to check
|
258
|
-
|
259
|
-
Returns
|
260
|
-
-------
|
261
|
-
bool
|
262
|
-
True if the class is concrete, False otherwise
|
263
|
-
"""
|
264
|
-
return isinstance(cls, type) and not HelpersReflection.isAbstractClass(cls)
|
265
|
-
|
266
|
-
@staticmethod
|
267
|
-
def ensureConcreteClass(cls: Type) -> None:
|
268
|
-
"""Ensure a class is concrete.
|
269
|
-
|
270
|
-
Parameters
|
271
|
-
----------
|
272
|
-
cls : Type
|
273
|
-
The class to check
|
274
|
-
|
275
|
-
Raises
|
276
|
-
------
|
277
|
-
TypeError
|
278
|
-
If the input is not a class
|
279
|
-
ValueError
|
280
|
-
If the class is not concrete
|
281
|
-
"""
|
282
|
-
if not isinstance(cls, type):
|
283
|
-
raise TypeError(f"Invalid class: {cls!r}")
|
284
|
-
if not HelpersReflection.isConcreteClass(cls):
|
285
|
-
raise ValueError(f"Class '{cls.__name__}' is not concrete.")
|
@@ -1,292 +0,0 @@
|
|
1
|
-
import re
|
2
|
-
import inspect
|
3
|
-
from abc import ABC
|
4
|
-
from typing import Any, Callable, Set, Type
|
5
|
-
from orionis._container.exception import OrionisContainerValueError, OrionisContainerTypeError
|
6
|
-
from orionis._contracts.container.container_integrity import IContainerIntegrity
|
7
|
-
|
8
|
-
class ContainerIntegrity(IContainerIntegrity):
|
9
|
-
|
10
|
-
@staticmethod
|
11
|
-
def ensureImplementation(abstract: Type, concrete: Type, raise_exception: bool = True) -> bool:
|
12
|
-
"""
|
13
|
-
Strictly verify that 'concrete' implements all abstract methods of 'abstract'.
|
14
|
-
|
15
|
-
Args:
|
16
|
-
abstract: Abstract class or interface to verify against
|
17
|
-
concrete: Concrete class that should implement the abstract class
|
18
|
-
|
19
|
-
Raises:
|
20
|
-
OrionisContainerTypeError: If concrete doesn't properly implement abstract
|
21
|
-
"""
|
22
|
-
|
23
|
-
# Check if abstract is a class
|
24
|
-
if not inspect.isclass(abstract):
|
25
|
-
if raise_exception:
|
26
|
-
raise OrionisContainerTypeError(
|
27
|
-
f"Abstract must be a class, got {type(abstract).__name__}"
|
28
|
-
)
|
29
|
-
return False
|
30
|
-
|
31
|
-
# Check if concrete is a class
|
32
|
-
if not inspect.isclass(concrete):
|
33
|
-
if raise_exception:
|
34
|
-
raise OrionisContainerTypeError(
|
35
|
-
f"Concrete must be a class, got {type(concrete).__name__}"
|
36
|
-
)
|
37
|
-
return False
|
38
|
-
|
39
|
-
# Check if concrete inherits from abstract
|
40
|
-
if not issubclass(concrete, abstract):
|
41
|
-
if raise_exception:
|
42
|
-
raise OrionisContainerTypeError(
|
43
|
-
f"{concrete.__name__} must inherit from {abstract.__name__}"
|
44
|
-
)
|
45
|
-
return False
|
46
|
-
|
47
|
-
abstract_methods: Set[str] = set()
|
48
|
-
for base in abstract.__mro__:
|
49
|
-
if hasattr(base, '__abstractmethods__'):
|
50
|
-
abstract_methods.update(base.__abstractmethods__)
|
51
|
-
|
52
|
-
if not abstract_methods:
|
53
|
-
return # No abstract methods to implement
|
54
|
-
|
55
|
-
class_methods = {
|
56
|
-
name for name, member in inspect.getmembers(concrete)
|
57
|
-
if not name.startswith("_") and inspect.isfunction(member)
|
58
|
-
}
|
59
|
-
|
60
|
-
missing_methods = abstract_methods - class_methods
|
61
|
-
if missing_methods:
|
62
|
-
raise OrionisContainerTypeError(
|
63
|
-
f"{concrete.__name__} must implement: {sorted(missing_methods)}"
|
64
|
-
)
|
65
|
-
|
66
|
-
def ensureImplementation(abstract: Type, concrete: Type) -> None:
|
67
|
-
"""
|
68
|
-
Verify at runtime if `concrete` implements all methods of `abstract`.
|
69
|
-
|
70
|
-
:param abstract: Abstract class or interface.
|
71
|
-
:param concrete: Concrete class that should implement the abstract class.
|
72
|
-
:raises TypeError: If `concrete` does not implement all methods of `abstract`.
|
73
|
-
"""
|
74
|
-
# Get public methods of the interface (excluding magic methods)
|
75
|
-
interface_methods = {
|
76
|
-
name for name, func in inspect.getmembers(abstract, predicate=inspect.isfunction)
|
77
|
-
if not name.startswith("_")
|
78
|
-
}
|
79
|
-
|
80
|
-
# Get public methods of the concrete class
|
81
|
-
class_methods = {
|
82
|
-
name for name, func in inspect.getmembers(concrete, predicate=inspect.isfunction)
|
83
|
-
if not name.startswith("_")
|
84
|
-
}
|
85
|
-
|
86
|
-
# Verify that all interface methods are in the concrete class
|
87
|
-
if not interface_methods.issubset(class_methods):
|
88
|
-
missing_methods = interface_methods - class_methods
|
89
|
-
raise OrionisContainerTypeError(f"{concrete.__name__} does not implement the required methods of {abstract.__name__}: {missing_methods}")
|
90
|
-
|
91
|
-
|
92
|
-
@staticmethod
|
93
|
-
def ensureIsAbstract(abstract: Callable[..., Any]) -> None:
|
94
|
-
"""
|
95
|
-
Ensure that the given abstract is a valid abstract class.
|
96
|
-
|
97
|
-
:param abstract: Class to check
|
98
|
-
:raises OrionisContainerValueError: If the class is not a valid abstract interface
|
99
|
-
"""
|
100
|
-
if not isinstance(abstract, type) or not issubclass(abstract, ABC) or abstract is ABC:
|
101
|
-
raise OrionisContainerValueError("The provided class must inherit from ABC and not be ABC itself.")
|
102
|
-
|
103
|
-
if not any(getattr(attr, "__isabstractmethod__", False) for attr in abstract.__dict__.values()):
|
104
|
-
raise OrionisContainerValueError("The provided class must define at least one abstract method.")
|
105
|
-
|
106
|
-
@staticmethod
|
107
|
-
def ensureIsCallable(concrete: Callable[..., Any]) -> None:
|
108
|
-
"""
|
109
|
-
Ensure that the given implementation is callable or instantiable.
|
110
|
-
|
111
|
-
Parameters
|
112
|
-
----------
|
113
|
-
concrete : Callable[..., Any]
|
114
|
-
The implementation to check.
|
115
|
-
|
116
|
-
Raises
|
117
|
-
------
|
118
|
-
OrionisContainerTypeError
|
119
|
-
If the implementation is not callable.
|
120
|
-
"""
|
121
|
-
if not callable(concrete):
|
122
|
-
raise OrionisContainerTypeError(f"The implementation '{str(concrete)}' must be callable or an instantiable class.")
|
123
|
-
|
124
|
-
@staticmethod
|
125
|
-
def ensureIsInstance(instance: Any) -> None:
|
126
|
-
"""
|
127
|
-
Ensure that the given instance is a valid object.
|
128
|
-
|
129
|
-
Parameters
|
130
|
-
----------
|
131
|
-
instance : Any
|
132
|
-
The instance to check.
|
133
|
-
|
134
|
-
Raises
|
135
|
-
------
|
136
|
-
OrionisContainerValueError
|
137
|
-
If the instance is not a valid object.
|
138
|
-
"""
|
139
|
-
if not isinstance(instance, object):
|
140
|
-
raise OrionisContainerValueError(f"The instance '{str(instance)}' must be a valid object.")
|
141
|
-
|
142
|
-
module = type(instance).__module__
|
143
|
-
if module in ['builtins', 'abc']:
|
144
|
-
raise OrionisContainerValueError(f"The instance '{str(instance)}' is not a valid user-defined object. It belongs to the '{module}' module.")
|
145
|
-
|
146
|
-
@staticmethod
|
147
|
-
def ensureNotMain(concrete: Callable[..., Any]) -> str:
|
148
|
-
"""
|
149
|
-
Ensure that a class is not defined in the main script.
|
150
|
-
|
151
|
-
Parameters
|
152
|
-
----------
|
153
|
-
concrete : Callable[..., Any]
|
154
|
-
The class or function to check.
|
155
|
-
|
156
|
-
Returns
|
157
|
-
-------
|
158
|
-
str
|
159
|
-
The fully qualified name of the class.
|
160
|
-
|
161
|
-
Raises
|
162
|
-
------
|
163
|
-
OrionisContainerValueError
|
164
|
-
If the class is defined in the main module.
|
165
|
-
"""
|
166
|
-
if concrete.__module__ == "__main__":
|
167
|
-
raise OrionisContainerValueError("Cannot register a class from the (__main__) module in the container.")
|
168
|
-
|
169
|
-
@staticmethod
|
170
|
-
def ensureIsAlias(name: str) -> bool:
|
171
|
-
"""
|
172
|
-
Ensure that the given alias name is a valid string, with no special characters or spaces,
|
173
|
-
and it is not a primitive type.
|
174
|
-
|
175
|
-
Parameters
|
176
|
-
----------
|
177
|
-
name : str
|
178
|
-
The alias name to check.
|
179
|
-
|
180
|
-
Raises
|
181
|
-
------
|
182
|
-
OrionisContainerValueError
|
183
|
-
If the alias is invalid.
|
184
|
-
"""
|
185
|
-
if not isinstance(name, str):
|
186
|
-
raise OrionisContainerValueError(f"The alias '{name}' must be a string.")
|
187
|
-
|
188
|
-
if not re.match(r'^[a-zA-Z0-9_:]+$', name):
|
189
|
-
raise OrionisContainerValueError(
|
190
|
-
f"The alias '{name}' can only contain letters, numbers, underscores, and colons, without spaces or other special characters."
|
191
|
-
)
|
192
|
-
|
193
|
-
if name in {
|
194
|
-
int, "int",
|
195
|
-
float, "float",
|
196
|
-
str, "str",
|
197
|
-
bool, "bool",
|
198
|
-
bytes, "bytes",
|
199
|
-
type(None), "None",
|
200
|
-
complex, "complex",
|
201
|
-
list, "list",
|
202
|
-
tuple, "tuple",
|
203
|
-
dict, "dict",
|
204
|
-
set, "set",
|
205
|
-
frozenset, "frozenset"
|
206
|
-
}:
|
207
|
-
raise OrionisContainerValueError(f"The alias '{name}' cannot be a primitive type.")
|
208
|
-
|
209
|
-
@staticmethod
|
210
|
-
def isAlias(name: str) -> bool:
|
211
|
-
"""
|
212
|
-
Check if the given alias name is a valid string, with no special characters or spaces,
|
213
|
-
and it is not a primitive type.
|
214
|
-
|
215
|
-
Parameters
|
216
|
-
----------
|
217
|
-
name : str
|
218
|
-
The alias name to check.
|
219
|
-
|
220
|
-
Returns
|
221
|
-
-------
|
222
|
-
bool
|
223
|
-
True if the alias is valid, False otherwise.
|
224
|
-
"""
|
225
|
-
try:
|
226
|
-
ContainerIntegrity.ensureIsAlias(name)
|
227
|
-
return True
|
228
|
-
except OrionisContainerValueError:
|
229
|
-
return False
|
230
|
-
|
231
|
-
@staticmethod
|
232
|
-
def isCallable(concrete: Callable[..., Any]) -> bool:
|
233
|
-
"""
|
234
|
-
Check if the given implementation is callable or instantiable.
|
235
|
-
|
236
|
-
Parameters
|
237
|
-
----------
|
238
|
-
concrete : Callable[..., Any]
|
239
|
-
The implementation to check.
|
240
|
-
|
241
|
-
Returns
|
242
|
-
-------
|
243
|
-
bool
|
244
|
-
True if the implementation is callable, False otherwise.
|
245
|
-
"""
|
246
|
-
try:
|
247
|
-
ContainerIntegrity.ensureIsCallable(concrete)
|
248
|
-
return True
|
249
|
-
except OrionisContainerTypeError:
|
250
|
-
return False
|
251
|
-
|
252
|
-
@staticmethod
|
253
|
-
def isInstance(instance: Any) -> bool:
|
254
|
-
"""
|
255
|
-
Check if the given instance is a valid object.
|
256
|
-
|
257
|
-
Parameters
|
258
|
-
----------
|
259
|
-
instance : Any
|
260
|
-
The instance to check.
|
261
|
-
|
262
|
-
Returns
|
263
|
-
-------
|
264
|
-
bool
|
265
|
-
True if the instance is valid, False otherwise.
|
266
|
-
"""
|
267
|
-
try:
|
268
|
-
ContainerIntegrity.ensureIsInstance(instance)
|
269
|
-
return True
|
270
|
-
except OrionisContainerValueError:
|
271
|
-
return False
|
272
|
-
|
273
|
-
@staticmethod
|
274
|
-
def isAbstract(abstract: Callable[..., Any]) -> bool:
|
275
|
-
"""
|
276
|
-
Check if the given abstract is a valid abstract class.
|
277
|
-
|
278
|
-
Parameters
|
279
|
-
----------
|
280
|
-
abstract : Callable[..., Any]
|
281
|
-
The class to check.
|
282
|
-
|
283
|
-
Returns
|
284
|
-
-------
|
285
|
-
bool
|
286
|
-
True if the class is a valid abstract interface, False otherwise.
|
287
|
-
"""
|
288
|
-
try:
|
289
|
-
ContainerIntegrity.ensureIsAbstract(abstract)
|
290
|
-
return True
|
291
|
-
except OrionisContainerValueError:
|
292
|
-
return False
|
File without changes
|