orionis 0.657.0__py3-none-any.whl → 0.658.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/container/container.py +87 -37
- orionis/metadata/framework.py +1 -1
- {orionis-0.657.0.dist-info → orionis-0.658.0.dist-info}/METADATA +1 -1
- {orionis-0.657.0.dist-info → orionis-0.658.0.dist-info}/RECORD +7 -7
- {orionis-0.657.0.dist-info → orionis-0.658.0.dist-info}/WHEEL +0 -0
- {orionis-0.657.0.dist-info → orionis-0.658.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.657.0.dist-info → orionis-0.658.0.dist-info}/top_level.txt +0 -0
orionis/container/container.py
CHANGED
|
@@ -3,7 +3,7 @@ import asyncio
|
|
|
3
3
|
import inspect
|
|
4
4
|
import threading
|
|
5
5
|
import typing
|
|
6
|
-
from typing import Any, Callable, Optional
|
|
6
|
+
from typing import Any, Callable, Optional, Union
|
|
7
7
|
from orionis.container.context.manager import ScopeManager
|
|
8
8
|
from orionis.container.context.scope import ScopedContext
|
|
9
9
|
from orionis.container.contracts.container import IContainer
|
|
@@ -445,6 +445,7 @@ class Container(IContainer):
|
|
|
445
445
|
|
|
446
446
|
# If an alias is provided, validate and use it directly
|
|
447
447
|
if alias:
|
|
448
|
+
|
|
448
449
|
# Check for None, empty string, or whitespace-only alias
|
|
449
450
|
if alias is None or alias == "" or str(alias).isspace():
|
|
450
451
|
raise OrionisContainerTypeError(
|
|
@@ -470,6 +471,47 @@ class Container(IContainer):
|
|
|
470
471
|
# If no alias is provided, generate a default alias using module and class name
|
|
471
472
|
return f"{abstract.__module__}.{abstract.__name__}"
|
|
472
473
|
|
|
474
|
+
def __validateLifetime(self, lifetime: Union[str, Lifetime, Any]) -> Lifetime:
|
|
475
|
+
"""
|
|
476
|
+
Validates and normalizes the provided lifetime value.
|
|
477
|
+
|
|
478
|
+
Parameters
|
|
479
|
+
----------
|
|
480
|
+
lifetime : Union[str, Lifetime, Any]
|
|
481
|
+
The lifetime value to validate. Can be a Lifetime enum or a string
|
|
482
|
+
representing a valid lifetime.
|
|
483
|
+
|
|
484
|
+
Returns
|
|
485
|
+
-------
|
|
486
|
+
Lifetime
|
|
487
|
+
The validated Lifetime enum value.
|
|
488
|
+
|
|
489
|
+
Raises
|
|
490
|
+
------
|
|
491
|
+
OrionisContainerTypeError
|
|
492
|
+
If the value is not a valid Lifetime enum or string representation,
|
|
493
|
+
or if the string doesn't match any valid Lifetime value.
|
|
494
|
+
"""
|
|
495
|
+
# Already a Lifetime enum
|
|
496
|
+
if isinstance(lifetime, Lifetime):
|
|
497
|
+
return lifetime
|
|
498
|
+
|
|
499
|
+
# String that might represent a Lifetime
|
|
500
|
+
if isinstance(lifetime, str):
|
|
501
|
+
lifetime_key = lifetime.strip().upper()
|
|
502
|
+
if lifetime_key in Lifetime.__members__:
|
|
503
|
+
return Lifetime[lifetime_key]
|
|
504
|
+
|
|
505
|
+
valid_options = ', '.join(Lifetime.__members__.keys())
|
|
506
|
+
raise OrionisContainerTypeError(
|
|
507
|
+
f"Invalid lifetime '{lifetime}'. Valid options are: {valid_options}."
|
|
508
|
+
)
|
|
509
|
+
|
|
510
|
+
# Invalid type
|
|
511
|
+
raise OrionisContainerTypeError(
|
|
512
|
+
f"Lifetime must be of type str or Lifetime enum, got {type(lifetime).__name__}."
|
|
513
|
+
)
|
|
514
|
+
|
|
473
515
|
def transient(
|
|
474
516
|
self,
|
|
475
517
|
abstract: Callable[..., Any],
|
|
@@ -970,68 +1012,76 @@ class Container(IContainer):
|
|
|
970
1012
|
|
|
971
1013
|
def callable(
|
|
972
1014
|
self,
|
|
973
|
-
alias: str,
|
|
974
1015
|
fn: Callable[..., Any],
|
|
975
1016
|
*,
|
|
976
|
-
|
|
1017
|
+
alias: str
|
|
977
1018
|
) -> Optional[bool]:
|
|
978
1019
|
"""
|
|
979
|
-
Registers a function or factory under a given alias.
|
|
1020
|
+
Registers a function or factory under a given alias with transient lifetime.
|
|
1021
|
+
|
|
1022
|
+
This method registers a callable (function or factory) in the container and associates it with a unique alias.
|
|
1023
|
+
The registered function will be resolved with transient lifetime, meaning a new result is produced each time it is invoked.
|
|
1024
|
+
The alias is validated for uniqueness and correctness, and any previous registration under the same alias is removed.
|
|
980
1025
|
|
|
981
1026
|
Parameters
|
|
982
1027
|
----------
|
|
983
|
-
alias : str
|
|
984
|
-
The alias to register the function under.
|
|
985
1028
|
fn : Callable[..., Any]
|
|
986
|
-
The function or factory to register.
|
|
987
|
-
|
|
988
|
-
The
|
|
1029
|
+
The function or factory to register. Must be a valid Python callable.
|
|
1030
|
+
alias : str
|
|
1031
|
+
The alias to register the function under. Must be a non-empty, valid string.
|
|
989
1032
|
|
|
990
1033
|
Returns
|
|
991
1034
|
-------
|
|
992
|
-
bool
|
|
993
|
-
True if the function was registered successfully.
|
|
1035
|
+
bool or None
|
|
1036
|
+
Returns True if the function was registered successfully.
|
|
1037
|
+
Returns None if registration fails due to an exception.
|
|
994
1038
|
|
|
995
1039
|
Raises
|
|
996
1040
|
------
|
|
997
1041
|
OrionisContainerTypeError
|
|
998
1042
|
If the alias is invalid or the function is not callable.
|
|
999
1043
|
OrionisContainerException
|
|
1000
|
-
If
|
|
1001
|
-
"""
|
|
1044
|
+
If an unexpected error occurs during registration.
|
|
1002
1045
|
|
|
1003
|
-
|
|
1004
|
-
|
|
1046
|
+
Notes
|
|
1047
|
+
-----
|
|
1048
|
+
- The function is registered with transient lifetime, so each invocation produces a new result.
|
|
1049
|
+
- If a service is already registered under the same alias, it is removed before registering the new function.
|
|
1050
|
+
- The alias is validated for uniqueness and correctness.
|
|
1051
|
+
"""
|
|
1005
1052
|
|
|
1006
|
-
|
|
1007
|
-
|
|
1053
|
+
try:
|
|
1054
|
+
# Validate and normalize the alias using the internal alias key generator
|
|
1055
|
+
alias = self.__makeAliasKey(lambda: None, alias)
|
|
1008
1056
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1057
|
+
# Ensure the provided fn is actually callable
|
|
1058
|
+
if not callable(fn):
|
|
1059
|
+
raise OrionisContainerTypeError(
|
|
1060
|
+
f"Expected a callable type, but got {type(fn).__name__} instead."
|
|
1061
|
+
)
|
|
1011
1062
|
|
|
1012
|
-
|
|
1013
|
-
|
|
1063
|
+
# Remove any existing registration under this alias
|
|
1064
|
+
self.drop(None, alias)
|
|
1014
1065
|
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1066
|
+
# Register the function in the bindings dictionary with transient lifetime
|
|
1067
|
+
self.__bindings[alias] = Binding(
|
|
1068
|
+
function=fn,
|
|
1069
|
+
lifetime=Lifetime.TRANSIENT,
|
|
1070
|
+
alias=alias
|
|
1019
1071
|
)
|
|
1020
1072
|
|
|
1021
|
-
|
|
1022
|
-
|
|
1073
|
+
# Register the alias for lookup in the aliases dictionary
|
|
1074
|
+
self.__aliases[alias] = self.__bindings[alias]
|
|
1023
1075
|
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
function=fn,
|
|
1027
|
-
lifetime=lifetime,
|
|
1028
|
-
alias=alias
|
|
1029
|
-
)
|
|
1076
|
+
# Return True to indicate successful registration
|
|
1077
|
+
return True
|
|
1030
1078
|
|
|
1031
|
-
|
|
1032
|
-
self.__aliases[alias] = self.__bindings[alias]
|
|
1079
|
+
except Exception as e:
|
|
1033
1080
|
|
|
1034
|
-
|
|
1081
|
+
# Raise a container exception with details if registration fails
|
|
1082
|
+
raise OrionisContainerException(
|
|
1083
|
+
f"Unexpected error registering callable: {e}"
|
|
1084
|
+
) from e
|
|
1035
1085
|
|
|
1036
1086
|
def bound(
|
|
1037
1087
|
self,
|
|
@@ -2958,4 +3008,4 @@ class Container(IContainer):
|
|
|
2958
3008
|
except TypeError:
|
|
2959
3009
|
raise OrionisContainerException(
|
|
2960
3010
|
f"Failed to call method '{method.__name__}': {reflection_error}"
|
|
2961
|
-
) from reflection_error
|
|
3011
|
+
) from reflection_error
|
orionis/metadata/framework.py
CHANGED
|
@@ -67,7 +67,7 @@ orionis/console/stubs/listener.stub,sha256=DbX-ghx2-vb73kzQ6L20lyg5vSKn58jSLTwFu
|
|
|
67
67
|
orionis/console/tasks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
68
68
|
orionis/console/tasks/schedule.py,sha256=ZeeuQ9Tbu5KNowKC5oIk7yWeJXzlDQiQ278mWEgoCXc,87989
|
|
69
69
|
orionis/container/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
70
|
-
orionis/container/container.py,sha256=
|
|
70
|
+
orionis/container/container.py,sha256=I6cTRRlDW0kf_7MMKIKXdeNXRur-slMfUTtLRNFyzbA,115945
|
|
71
71
|
orionis/container/context/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
72
72
|
orionis/container/context/manager.py,sha256=I08K_jKXSKmrq18Pv33qYyMKIlAovVOwIgmfiVm-J7c,2971
|
|
73
73
|
orionis/container/context/scope.py,sha256=p_oCzR7dDz-5ZAd16ab4vfLc3gBf34CaN0f4iR9D0bQ,1155
|
|
@@ -217,7 +217,7 @@ orionis/foundation/providers/scheduler_provider.py,sha256=IrPQJwvQVLRm5Qnz0Cxon4
|
|
|
217
217
|
orionis/foundation/providers/testing_provider.py,sha256=eI1p2lUlxl25b5Z487O4nmqLE31CTDb4c3Q21xFadkE,1615
|
|
218
218
|
orionis/foundation/providers/workers_provider.py,sha256=GdHENYV_yGyqmHJHn0DCyWmWId5xWjD48e6Zq2PGCWY,1674
|
|
219
219
|
orionis/metadata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
220
|
-
orionis/metadata/framework.py,sha256
|
|
220
|
+
orionis/metadata/framework.py,sha256=KfWV8jwgxZcdeY4hlBEHan1VFrSifKQbbvgnOH4dY64,4089
|
|
221
221
|
orionis/metadata/package.py,sha256=k7Yriyp5aUcR-iR8SK2ec_lf0_Cyc-C7JczgXa-I67w,16039
|
|
222
222
|
orionis/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
223
223
|
orionis/services/asynchrony/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -404,8 +404,8 @@ orionis/test/validators/workers.py,sha256=rWcdRexINNEmGaO7mnc1MKUxkHKxrTsVuHgbnI
|
|
|
404
404
|
orionis/test/view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
405
405
|
orionis/test/view/render.py,sha256=R55ykeRs0wDKcdTf4O1YZ8GDHTFmJ0IK6VQkbJkYUvo,5571
|
|
406
406
|
orionis/test/view/report.stub,sha256=QLqqCdRoENr3ECiritRB3DO_MOjRQvgBh5jxZ3Hs1r0,28189
|
|
407
|
-
orionis-0.
|
|
408
|
-
orionis-0.
|
|
409
|
-
orionis-0.
|
|
410
|
-
orionis-0.
|
|
411
|
-
orionis-0.
|
|
407
|
+
orionis-0.658.0.dist-info/licenses/LICENCE,sha256=JhC-z_9mbpUrCfPjcl3DhDA8trNDMzb57cvRSam1avc,1463
|
|
408
|
+
orionis-0.658.0.dist-info/METADATA,sha256=pmVWTkhfAxoTOYGL1SFjGeLl-Kat1Un9nPNGZvp56rE,4772
|
|
409
|
+
orionis-0.658.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
410
|
+
orionis-0.658.0.dist-info/top_level.txt,sha256=lyXi6jArpqJ-0zzNqd_uwsH-z9TCEBVBL-pC3Ekv7hU,8
|
|
411
|
+
orionis-0.658.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|