orionis 0.436.0__py3-none-any.whl → 0.437.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/console/contracts/kernel.py +16 -3
- orionis/console/dumper/contracts/dump.py +8 -9
- orionis/console/dynamic/progress_bar.py +21 -29
- orionis/console/output/console.py +12 -0
- orionis/container/context/manager.py +27 -17
- orionis/container/context/scope.py +8 -7
- orionis/container/contracts/service_provider.py +12 -8
- orionis/container/providers/service_provider.py +9 -16
- orionis/container/resolver/resolver.py +29 -22
- orionis/foundation/contracts/application.py +437 -47
- orionis/foundation/contracts/config.py +14 -6
- orionis/foundation/providers/console_provider.py +16 -15
- orionis/foundation/providers/dumper_provider.py +20 -8
- orionis/foundation/providers/logger_provider.py +19 -14
- orionis/foundation/providers/path_resolver_provider.py +17 -14
- orionis/foundation/providers/progress_bar_provider.py +15 -14
- orionis/foundation/providers/testing_provider.py +20 -14
- orionis/foundation/providers/workers_provider.py +19 -14
- orionis/metadata/framework.py +1 -1
- orionis/services/asynchrony/contracts/coroutines.py +1 -0
- orionis/services/asynchrony/coroutines.py +2 -0
- orionis/services/asynchrony/exceptions/exception.py +2 -0
- orionis/services/environment/core/dot_env.py +9 -0
- orionis/services/environment/dynamic/caster.py +31 -2
- orionis/services/environment/key/key_generator.py +1 -0
- orionis/services/environment/validators/key_name.py +1 -0
- orionis/services/environment/validators/types.py +5 -1
- orionis/services/introspection/abstract/contracts/reflection.py +188 -221
- orionis/services/introspection/abstract/reflection.py +311 -178
- orionis/services/introspection/callables/contracts/reflection.py +64 -21
- orionis/services/introspection/callables/reflection.py +98 -23
- orionis/services/introspection/concretes/reflection.py +278 -181
- orionis/services/introspection/dependencies/contracts/reflection.py +21 -18
- orionis/services/introspection/dependencies/entities/callable_dependencies.py +15 -16
- orionis/services/introspection/dependencies/entities/class_dependencies.py +24 -16
- orionis/services/introspection/dependencies/entities/known_dependencies.py +19 -13
- orionis/services/introspection/dependencies/entities/method_dependencies.py +22 -16
- orionis/services/introspection/dependencies/reflection.py +0 -3
- orionis/services/introspection/instances/reflection.py +16 -6
- orionis/services/log/contracts/log_service.py +4 -0
- orionis/services/log/handlers/filename.py +2 -0
- orionis/services/paths/contracts/resolver.py +0 -3
- orionis/services/paths/resolver.py +0 -3
- {orionis-0.436.0.dist-info → orionis-0.437.0.dist-info}/METADATA +1 -1
- {orionis-0.436.0.dist-info → orionis-0.437.0.dist-info}/RECORD +50 -50
- /orionis/services/introspection/concretes/contracts/{concrete.py → reflection.py} +0 -0
- {orionis-0.436.0.dist-info → orionis-0.437.0.dist-info}/WHEEL +0 -0
- {orionis-0.436.0.dist-info → orionis-0.437.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.436.0.dist-info → orionis-0.437.0.dist-info}/top_level.txt +0 -0
- {orionis-0.436.0.dist-info → orionis-0.437.0.dist-info}/zip-safe +0 -0
|
@@ -2,22 +2,30 @@ from abc import ABC, abstractmethod
|
|
|
2
2
|
|
|
3
3
|
class IConfig(ABC):
|
|
4
4
|
"""
|
|
5
|
-
|
|
6
|
-
a `config` attribute.
|
|
5
|
+
Abstract base class for configuration holders.
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
a dataclass instance
|
|
7
|
+
This interface enforces the presence of a `config` attribute in subclasses,
|
|
8
|
+
which must return a dataclass instance containing configuration data.
|
|
10
9
|
|
|
11
10
|
Attributes
|
|
12
11
|
----------
|
|
13
12
|
config : object
|
|
14
|
-
|
|
13
|
+
Dataclass instance representing the configuration data.
|
|
15
14
|
"""
|
|
16
15
|
|
|
17
16
|
@property
|
|
18
17
|
@abstractmethod
|
|
19
18
|
def config(self):
|
|
20
19
|
"""
|
|
21
|
-
|
|
20
|
+
Get the configuration dataclass instance.
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
object
|
|
25
|
+
Dataclass instance containing the configuration data.
|
|
26
|
+
|
|
27
|
+
Notes
|
|
28
|
+
-----
|
|
29
|
+
Subclasses must implement this property to provide access to their configuration.
|
|
22
30
|
"""
|
|
23
31
|
pass
|
|
@@ -4,36 +4,37 @@ from orionis.container.providers.service_provider import ServiceProvider
|
|
|
4
4
|
|
|
5
5
|
class ConsoleProvider(ServiceProvider):
|
|
6
6
|
"""
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Methods
|
|
14
|
-
-------
|
|
15
|
-
register()
|
|
16
|
-
Registers the console service in the application container.
|
|
17
|
-
boot()
|
|
18
|
-
Performs post-registration initialization if needed.
|
|
7
|
+
Provides and registers the console output service within the application container.
|
|
8
|
+
|
|
9
|
+
This provider binds the console output interface to its concrete implementation,
|
|
10
|
+
enabling access to various console output features such as information, warnings,
|
|
11
|
+
errors, debug messages, tables, confirmations, and password prompts.
|
|
19
12
|
"""
|
|
20
13
|
|
|
21
14
|
def register(self) -> None:
|
|
22
15
|
"""
|
|
23
|
-
|
|
16
|
+
Register the console output service in the application container.
|
|
17
|
+
|
|
18
|
+
Binds the IConsole interface to the Console implementation as a transient service,
|
|
19
|
+
with the alias "core.orionis.console".
|
|
24
20
|
|
|
25
21
|
Returns
|
|
26
22
|
-------
|
|
27
23
|
None
|
|
28
24
|
"""
|
|
25
|
+
|
|
29
26
|
self.app.transient(IConsole, Console, alias="core.orionis.console")
|
|
30
27
|
|
|
31
28
|
def boot(self) -> None:
|
|
32
29
|
"""
|
|
33
|
-
|
|
30
|
+
Perform post-registration initialization for the console provider.
|
|
31
|
+
|
|
32
|
+
This method is a placeholder for any additional setup required after
|
|
33
|
+
registration. Currently, it does not perform any actions.
|
|
34
34
|
|
|
35
35
|
Returns
|
|
36
36
|
-------
|
|
37
37
|
None
|
|
38
38
|
"""
|
|
39
|
-
|
|
39
|
+
|
|
40
|
+
pass
|
|
@@ -4,36 +4,48 @@ from orionis.container.providers.service_provider import ServiceProvider
|
|
|
4
4
|
|
|
5
5
|
class DumperProvider(ServiceProvider):
|
|
6
6
|
"""
|
|
7
|
-
|
|
8
|
-
==============
|
|
7
|
+
Service provider for registering the debug message service.
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
This provider registers the debug service in the application container,
|
|
10
|
+
enabling debug message printing, error reporting, and console diagnostics.
|
|
11
|
+
|
|
12
|
+
Attributes
|
|
13
|
+
----------
|
|
14
|
+
app : Application
|
|
15
|
+
The application container instance where services are registered.
|
|
12
16
|
|
|
13
17
|
Methods
|
|
14
18
|
-------
|
|
15
19
|
register()
|
|
16
|
-
|
|
20
|
+
Register the debug service in the application container.
|
|
17
21
|
boot()
|
|
18
|
-
|
|
22
|
+
Perform post-registration initialization if required.
|
|
19
23
|
"""
|
|
20
24
|
|
|
21
25
|
def register(self) -> None:
|
|
22
26
|
"""
|
|
23
|
-
|
|
27
|
+
Register the debug service in the application container.
|
|
28
|
+
|
|
29
|
+
Registers the `IDebug` interface with the `Debug` implementation
|
|
30
|
+
as a transient service, using the alias "core.orionis.dumper".
|
|
24
31
|
|
|
25
32
|
Returns
|
|
26
33
|
-------
|
|
27
34
|
None
|
|
28
35
|
"""
|
|
36
|
+
|
|
29
37
|
self.app.transient(IDebug, Debug, alias="core.orionis.dumper")
|
|
30
38
|
|
|
31
39
|
def boot(self) -> None:
|
|
32
40
|
"""
|
|
33
|
-
|
|
41
|
+
Perform post-registration initialization if required.
|
|
42
|
+
|
|
43
|
+
This method is a placeholder for any initialization logic that
|
|
44
|
+
should occur after the service has been registered.
|
|
34
45
|
|
|
35
46
|
Returns
|
|
36
47
|
-------
|
|
37
48
|
None
|
|
38
49
|
"""
|
|
50
|
+
|
|
39
51
|
pass
|
|
@@ -4,36 +4,41 @@ from orionis.services.log.log_service import LoggerService
|
|
|
4
4
|
|
|
5
5
|
class LoggerProvider(ServiceProvider):
|
|
6
6
|
"""
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Registers the logging service in the application container.
|
|
17
|
-
boot()
|
|
18
|
-
Performs post-registration initialization if needed.
|
|
7
|
+
Provides and registers the logging service within the application container.
|
|
8
|
+
|
|
9
|
+
This provider binds an implementation of `ILoggerService` to the application,
|
|
10
|
+
making a `LoggerService` instance available for application-wide logging.
|
|
11
|
+
|
|
12
|
+
Attributes
|
|
13
|
+
----------
|
|
14
|
+
app : Application
|
|
15
|
+
The application container instance where services are registered.
|
|
19
16
|
"""
|
|
20
17
|
|
|
21
18
|
def register(self) -> None:
|
|
22
19
|
"""
|
|
23
|
-
|
|
20
|
+
Register the logging service in the application container.
|
|
21
|
+
|
|
22
|
+
This method binds the `LoggerService` implementation to the `ILoggerService`
|
|
23
|
+
contract in the application container, using the application's logging configuration.
|
|
24
24
|
|
|
25
25
|
Returns
|
|
26
26
|
-------
|
|
27
27
|
None
|
|
28
28
|
"""
|
|
29
|
+
|
|
29
30
|
self.app.instance(ILoggerService, LoggerService(self.app.config('logging')), alias="core.orionis.logger")
|
|
30
31
|
|
|
31
32
|
def boot(self) -> None:
|
|
32
33
|
"""
|
|
33
|
-
|
|
34
|
+
Perform post-registration initialization for the logging service.
|
|
35
|
+
|
|
36
|
+
This method is a placeholder for any additional setup required after
|
|
37
|
+
the logging service has been registered.
|
|
34
38
|
|
|
35
39
|
Returns
|
|
36
40
|
-------
|
|
37
41
|
None
|
|
38
42
|
"""
|
|
43
|
+
|
|
39
44
|
pass
|
|
@@ -4,37 +4,40 @@ from orionis.services.paths.resolver import Resolver
|
|
|
4
4
|
|
|
5
5
|
class PathResolverProvider(ServiceProvider):
|
|
6
6
|
"""
|
|
7
|
-
PathResolverProvider
|
|
8
|
-
===================
|
|
9
|
-
|
|
10
7
|
Registers the path resolution service in the application container.
|
|
11
|
-
Provides compatibility with the file system for resolving paths.
|
|
12
|
-
|
|
13
|
-
Methods
|
|
14
|
-
-------
|
|
15
|
-
register()
|
|
16
|
-
Registers the path resolver service in the application container.
|
|
17
|
-
boot()
|
|
18
|
-
Performs post-registration initialization if needed.
|
|
19
|
-
"""
|
|
20
8
|
|
|
9
|
+
This provider binds the `IResolver` interface to the `Resolver` implementation,
|
|
10
|
+
allowing the application to resolve file system paths through dependency injection.
|
|
11
|
+
|
|
12
|
+
Attributes
|
|
13
|
+
----------
|
|
14
|
+
app : Application
|
|
15
|
+
The application container instance inherited from ServiceProvider.
|
|
16
|
+
"""
|
|
21
17
|
|
|
22
18
|
def register(self) -> None:
|
|
23
19
|
"""
|
|
24
|
-
|
|
20
|
+
Register the path resolver service in the application container.
|
|
21
|
+
|
|
22
|
+
Binds the `IResolver` interface to the `Resolver` implementation as a transient
|
|
23
|
+
service, with the alias "core.orionis.path_resolver".
|
|
25
24
|
|
|
26
25
|
Returns
|
|
27
26
|
-------
|
|
28
27
|
None
|
|
29
28
|
"""
|
|
29
|
+
|
|
30
30
|
self.app.transient(IResolver, Resolver, alias="core.orionis.path_resolver")
|
|
31
31
|
|
|
32
32
|
def boot(self) -> None:
|
|
33
33
|
"""
|
|
34
|
-
|
|
34
|
+
Perform post-registration initialization if needed.
|
|
35
|
+
|
|
36
|
+
This method is a placeholder for any actions required after service registration.
|
|
35
37
|
|
|
36
38
|
Returns
|
|
37
39
|
-------
|
|
38
40
|
None
|
|
39
41
|
"""
|
|
42
|
+
|
|
40
43
|
pass
|
|
@@ -4,36 +4,37 @@ from orionis.container.providers.service_provider import ServiceProvider
|
|
|
4
4
|
|
|
5
5
|
class ProgressBarProvider(ServiceProvider):
|
|
6
6
|
"""
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Methods
|
|
14
|
-
-------
|
|
15
|
-
register()
|
|
16
|
-
Registers the progress bar service in the application container.
|
|
17
|
-
boot()
|
|
18
|
-
Performs post-registration initialization if needed.
|
|
7
|
+
Service provider for registering the dynamic progress bar.
|
|
8
|
+
|
|
9
|
+
This provider registers the `IProgressBar` interface with the `ProgressBar`
|
|
10
|
+
implementation in the application container, allowing for dependency injection
|
|
11
|
+
and usage of a console-based progress bar for visual feedback during operations.
|
|
19
12
|
"""
|
|
20
13
|
|
|
21
14
|
def register(self) -> None:
|
|
22
15
|
"""
|
|
23
|
-
|
|
16
|
+
Register the progress bar service in the application container.
|
|
17
|
+
|
|
18
|
+
Registers the `IProgressBar` interface to resolve to the `ProgressBar`
|
|
19
|
+
implementation, with the alias "core.orionis.progress_bar".
|
|
24
20
|
|
|
25
21
|
Returns
|
|
26
22
|
-------
|
|
27
23
|
None
|
|
28
24
|
"""
|
|
25
|
+
|
|
29
26
|
self.app.transient(IProgressBar, ProgressBar, alias="core.orionis.progress_bar")
|
|
30
27
|
|
|
31
28
|
def boot(self) -> None:
|
|
32
29
|
"""
|
|
33
|
-
|
|
30
|
+
Perform post-registration initialization.
|
|
31
|
+
|
|
32
|
+
This method is called after all providers have been registered. No additional
|
|
33
|
+
initialization is required for the progress bar service.
|
|
34
34
|
|
|
35
35
|
Returns
|
|
36
36
|
-------
|
|
37
37
|
None
|
|
38
38
|
"""
|
|
39
|
+
|
|
39
40
|
pass
|
|
@@ -4,36 +4,42 @@ from orionis.test.core.unit_test import UnitTest
|
|
|
4
4
|
|
|
5
5
|
class TestingProvider(ServiceProvider):
|
|
6
6
|
"""
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
boot()
|
|
18
|
-
Performs post-registration initialization if needed.
|
|
7
|
+
Provides and registers the unit testing environment service in the application container.
|
|
8
|
+
|
|
9
|
+
This provider integrates a native unit testing framework for Orionis,
|
|
10
|
+
enabling advanced testing features and registering the service as a singleton
|
|
11
|
+
within the application's dependency injection container.
|
|
12
|
+
|
|
13
|
+
Attributes
|
|
14
|
+
----------
|
|
15
|
+
app : Application
|
|
16
|
+
The application container instance where services are registered.
|
|
19
17
|
"""
|
|
20
18
|
|
|
21
19
|
def register(self) -> None:
|
|
22
20
|
"""
|
|
23
|
-
|
|
21
|
+
Register the unit testing service in the application container.
|
|
22
|
+
|
|
23
|
+
Registers the IUnitTest interface to the UnitTest implementation as a singleton,
|
|
24
|
+
with the alias "core.orionis.testing".
|
|
24
25
|
|
|
25
26
|
Returns
|
|
26
27
|
-------
|
|
27
28
|
None
|
|
28
29
|
"""
|
|
30
|
+
|
|
29
31
|
self.app.singleton(IUnitTest, UnitTest, alias="core.orionis.testing")
|
|
30
32
|
|
|
31
33
|
def boot(self) -> None:
|
|
32
34
|
"""
|
|
33
|
-
|
|
35
|
+
Perform post-registration initialization if required.
|
|
36
|
+
|
|
37
|
+
This method is intended for any setup needed after service registration.
|
|
38
|
+
Currently, no additional initialization is performed.
|
|
34
39
|
|
|
35
40
|
Returns
|
|
36
41
|
-------
|
|
37
42
|
None
|
|
38
43
|
"""
|
|
44
|
+
|
|
39
45
|
pass
|
|
@@ -4,36 +4,41 @@ from orionis.services.system.workers import Workers
|
|
|
4
4
|
|
|
5
5
|
class WorkersProvider(ServiceProvider):
|
|
6
6
|
"""
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Registers the worker service in the application container.
|
|
17
|
-
boot()
|
|
18
|
-
Performs post-registration initialization if needed.
|
|
7
|
+
Provides and registers the worker management service within the application container.
|
|
8
|
+
|
|
9
|
+
This provider determines and registers the optimal worker management implementation,
|
|
10
|
+
making it available for dependency injection throughout the application.
|
|
11
|
+
|
|
12
|
+
Attributes
|
|
13
|
+
----------
|
|
14
|
+
app : Application
|
|
15
|
+
The application container instance where services are registered.
|
|
19
16
|
"""
|
|
20
17
|
|
|
21
18
|
def register(self) -> None:
|
|
22
19
|
"""
|
|
23
|
-
|
|
20
|
+
Register the worker service in the application container.
|
|
21
|
+
|
|
22
|
+
Registers the `Workers` implementation as a transient service for the `IWorkers`
|
|
23
|
+
contract, with the alias "core.orionis.workers".
|
|
24
24
|
|
|
25
25
|
Returns
|
|
26
26
|
-------
|
|
27
27
|
None
|
|
28
28
|
"""
|
|
29
|
+
|
|
29
30
|
self.app.transient(IWorkers, Workers, alias="core.orionis.workers")
|
|
30
31
|
|
|
31
32
|
def boot(self) -> None:
|
|
32
33
|
"""
|
|
33
|
-
|
|
34
|
+
Perform post-registration initialization if required.
|
|
35
|
+
|
|
36
|
+
This method is a placeholder for any initialization logic that should occur
|
|
37
|
+
after the worker service has been registered.
|
|
34
38
|
|
|
35
39
|
Returns
|
|
36
40
|
-------
|
|
37
41
|
None
|
|
38
42
|
"""
|
|
43
|
+
|
|
39
44
|
pass
|
orionis/metadata/framework.py
CHANGED
|
@@ -23,5 +23,6 @@ class ICoroutine(ABC):
|
|
|
23
23
|
- Schedules the coroutine for asynchronous execution and returns a Future when called inside an event loop.
|
|
24
24
|
- The caller is responsible for awaiting the Future if asynchronous execution is used.
|
|
25
25
|
"""
|
|
26
|
+
|
|
26
27
|
# This method should be implemented by subclasses to handle coroutine execution.
|
|
27
28
|
pass
|
|
@@ -22,6 +22,7 @@ class Coroutine(ICoroutine):
|
|
|
22
22
|
OrionisCoroutineException
|
|
23
23
|
If the provided object is not a coroutine.
|
|
24
24
|
"""
|
|
25
|
+
|
|
25
26
|
# Validate that the provided object is a coroutine
|
|
26
27
|
if not Type(func).isCoroutine():
|
|
27
28
|
raise OrionisCoroutineException(
|
|
@@ -51,6 +52,7 @@ class Coroutine(ICoroutine):
|
|
|
51
52
|
- If called within an active event loop, the coroutine is scheduled for asynchronous execution and a Future is returned.
|
|
52
53
|
- The method automatically detects the execution context and chooses the appropriate execution strategy.
|
|
53
54
|
"""
|
|
55
|
+
|
|
54
56
|
# Attempt to get the currently running event loop
|
|
55
57
|
try:
|
|
56
58
|
loop = asyncio.get_running_loop()
|
|
@@ -9,6 +9,7 @@ class OrionisCoroutineException(Exception):
|
|
|
9
9
|
msg : str
|
|
10
10
|
A descriptive error message explaining the cause of the exception.
|
|
11
11
|
"""
|
|
12
|
+
|
|
12
13
|
# Call the base Exception constructor with the provided message
|
|
13
14
|
super().__init__(msg)
|
|
14
15
|
|
|
@@ -21,5 +22,6 @@ class OrionisCoroutineException(Exception):
|
|
|
21
22
|
str
|
|
22
23
|
The error message provided during exception initialization.
|
|
23
24
|
"""
|
|
25
|
+
|
|
24
26
|
# Return the first argument passed to the Exception, which is the error message
|
|
25
27
|
return str(self.args[0])
|
|
@@ -61,6 +61,11 @@ class DotEnv(metaclass=Singleton):
|
|
|
61
61
|
# Raise an error if the .env file cannot be created or accessed
|
|
62
62
|
raise OSError(f"Failed to create or access the .env file at {self.__resolved_path}: {e}")
|
|
63
63
|
|
|
64
|
+
except Exception as e:
|
|
65
|
+
|
|
66
|
+
# Raise a general error for any other exceptions during initialization
|
|
67
|
+
raise Exception(f"An unexpected error occurred while initializing DotEnv: {e}")
|
|
68
|
+
|
|
64
69
|
def set(
|
|
65
70
|
self,
|
|
66
71
|
key: str,
|
|
@@ -95,6 +100,8 @@ class DotEnv(metaclass=Singleton):
|
|
|
95
100
|
serializes the value (optionally using a type hint), writes the variable to the `.env` file,
|
|
96
101
|
and updates the variable in the current process environment.
|
|
97
102
|
"""
|
|
103
|
+
|
|
104
|
+
# Ensure thread-safe operation during the set process.
|
|
98
105
|
with self._lock:
|
|
99
106
|
|
|
100
107
|
# Validate the environment variable key name.
|
|
@@ -148,6 +155,8 @@ class DotEnv(metaclass=Singleton):
|
|
|
148
155
|
OrionisEnvironmentValueError
|
|
149
156
|
If `key` is not a string.
|
|
150
157
|
"""
|
|
158
|
+
|
|
159
|
+
# Ensure thread-safe operation while retrieving the environment variable.
|
|
151
160
|
with self._lock:
|
|
152
161
|
|
|
153
162
|
# Ensure the key is a string.
|
|
@@ -55,11 +55,13 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
55
55
|
|
|
56
56
|
# If the input is a string, attempt to parse type hint and value
|
|
57
57
|
if isinstance(raw, str):
|
|
58
|
+
|
|
58
59
|
# Remove leading whitespace from the input
|
|
59
60
|
self.__value_raw = raw.lstrip()
|
|
60
61
|
|
|
61
62
|
# Check if the string contains a colon, indicating a type hint
|
|
62
63
|
if ':' in self.__value_raw:
|
|
64
|
+
|
|
63
65
|
# Split at the first colon to separate type hint and value
|
|
64
66
|
type_hint, value_str = raw.split(':', 1)
|
|
65
67
|
|
|
@@ -243,6 +245,7 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
243
245
|
raise
|
|
244
246
|
|
|
245
247
|
except Exception as e:
|
|
248
|
+
|
|
246
249
|
# Catch any other unexpected errors and wrap them in an environment value error
|
|
247
250
|
raise OrionisEnvironmentValueError(
|
|
248
251
|
f"Error converting value '{self.__value_raw}' to type '{type_hint}': {str(e)}"
|
|
@@ -263,6 +266,8 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
263
266
|
OrionisEnvironmentValueError
|
|
264
267
|
If the internal value is not a string or bytes.
|
|
265
268
|
"""
|
|
269
|
+
|
|
270
|
+
# Import the base64 module for encoding
|
|
266
271
|
import base64
|
|
267
272
|
|
|
268
273
|
# Ensure the internal value is a string or bytes before encoding
|
|
@@ -294,13 +299,18 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
294
299
|
OrionisEnvironmentValueException
|
|
295
300
|
If the internal value cannot be decoded from Base64.
|
|
296
301
|
"""
|
|
302
|
+
|
|
303
|
+
# Import the base64 module for decoding
|
|
297
304
|
import base64
|
|
298
305
|
|
|
299
306
|
try:
|
|
307
|
+
|
|
300
308
|
# Decode the Base64 encoded value and return as string
|
|
301
309
|
decoded_value = base64.b64decode(self.__value_raw).decode()
|
|
302
310
|
return decoded_value
|
|
311
|
+
|
|
303
312
|
except Exception as e:
|
|
313
|
+
|
|
304
314
|
# Raise a custom exception if decoding fails
|
|
305
315
|
raise OrionisEnvironmentValueException(f"Cannot decode Base64 value '{self.__value_raw}': {str(e)}")
|
|
306
316
|
|
|
@@ -322,6 +332,8 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
322
332
|
OrionisEnvironmentValueException
|
|
323
333
|
If the value cannot be processed as a valid path.
|
|
324
334
|
"""
|
|
335
|
+
|
|
336
|
+
# Import the Path class from pathlib for path manipulation
|
|
325
337
|
from pathlib import Path
|
|
326
338
|
|
|
327
339
|
# If the value is already a Path object, return its POSIX representation
|
|
@@ -349,8 +361,9 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
349
361
|
OrionisEnvironmentValueError
|
|
350
362
|
If the internal value is not a string or a pathlib.Path object.
|
|
351
363
|
"""
|
|
364
|
+
|
|
365
|
+
# Import the Path class from pathlib for path manipulation
|
|
352
366
|
from pathlib import Path
|
|
353
|
-
import os
|
|
354
367
|
|
|
355
368
|
# Ensure the internal value is a string or Path object
|
|
356
369
|
if not isinstance(self.__value_raw, (str, Path)):
|
|
@@ -418,8 +431,10 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
418
431
|
OrionisEnvironmentValueError
|
|
419
432
|
If the internal value is not a string.
|
|
420
433
|
"""
|
|
434
|
+
|
|
421
435
|
# Ensure the internal value is a string before conversion
|
|
422
436
|
if not isinstance(self.__value_raw, str):
|
|
437
|
+
|
|
423
438
|
# Raise an error if the value is not a string
|
|
424
439
|
raise OrionisEnvironmentValueError(
|
|
425
440
|
f"Value must be a string to convert to str, got {type(self.__value_raw).__name__} instead."
|
|
@@ -445,6 +460,7 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
445
460
|
OrionisEnvironmentValueException
|
|
446
461
|
If the value cannot be converted to an integer due to invalid format or type.
|
|
447
462
|
"""
|
|
463
|
+
|
|
448
464
|
# Remove leading and trailing whitespace from the raw value
|
|
449
465
|
value = self.__value_raw.strip()
|
|
450
466
|
|
|
@@ -526,6 +542,7 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
526
542
|
OrionisEnvironmentValueError
|
|
527
543
|
If the internal value is not a float.
|
|
528
544
|
"""
|
|
545
|
+
|
|
529
546
|
# Ensure the internal value is a float before conversion
|
|
530
547
|
if not isinstance(self.__value_raw, float):
|
|
531
548
|
|
|
@@ -556,6 +573,7 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
556
573
|
OrionisEnvironmentValueException
|
|
557
574
|
If the value cannot be converted to a boolean because it does not match 'true' or 'false'.
|
|
558
575
|
"""
|
|
576
|
+
|
|
559
577
|
# Remove leading and trailing whitespace, then convert to lowercase for comparison
|
|
560
578
|
value = self.__value_raw.strip().lower()
|
|
561
579
|
|
|
@@ -618,6 +636,8 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
618
636
|
OrionisEnvironmentValueException
|
|
619
637
|
If the value cannot be converted to a list due to invalid format or type.
|
|
620
638
|
"""
|
|
639
|
+
|
|
640
|
+
# Import the ast module for safe evaluation of string literals
|
|
621
641
|
import ast
|
|
622
642
|
|
|
623
643
|
# Remove leading and trailing whitespace from the raw value to ensure clean input
|
|
@@ -666,7 +686,7 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
666
686
|
|
|
667
687
|
# Raise an error if the value is not a list
|
|
668
688
|
raise OrionisEnvironmentValueError(
|
|
669
|
-
|
|
689
|
+
f"Value must be a list to convert to list, got {type(self.__value_raw).__name__} instead."
|
|
670
690
|
)
|
|
671
691
|
|
|
672
692
|
# Return the formatted string with type hint and list value
|
|
@@ -692,11 +712,14 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
692
712
|
OrionisEnvironmentValueException
|
|
693
713
|
If the value cannot be converted to a dictionary due to invalid format or type.
|
|
694
714
|
"""
|
|
715
|
+
|
|
716
|
+
# Import the ast module for safe evaluation of string literals
|
|
695
717
|
import ast
|
|
696
718
|
|
|
697
719
|
# Remove leading and trailing whitespace from the raw value to ensure clean input
|
|
698
720
|
value = self.__value_raw.strip()
|
|
699
721
|
|
|
722
|
+
# Attempt to parse the string as a dictionary
|
|
700
723
|
try:
|
|
701
724
|
|
|
702
725
|
# Safely evaluate the string to a Python object using ast.literal_eval
|
|
@@ -729,6 +752,7 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
729
752
|
OrionisEnvironmentValueError
|
|
730
753
|
If the internal value is not a dictionary.
|
|
731
754
|
"""
|
|
755
|
+
|
|
732
756
|
# Ensure the internal value is a dictionary before conversion
|
|
733
757
|
if not isinstance(self.__value_raw, dict):
|
|
734
758
|
|
|
@@ -760,6 +784,8 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
760
784
|
OrionisEnvironmentValueException
|
|
761
785
|
If the value cannot be converted to a tuple due to invalid format or type.
|
|
762
786
|
"""
|
|
787
|
+
|
|
788
|
+
# Import the ast module for safe evaluation of string literals
|
|
763
789
|
import ast
|
|
764
790
|
|
|
765
791
|
# Remove leading and trailing whitespace from the raw value to ensure clean input
|
|
@@ -829,6 +855,8 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
829
855
|
OrionisEnvironmentValueException
|
|
830
856
|
If the value cannot be converted to a set due to invalid format or type.
|
|
831
857
|
"""
|
|
858
|
+
|
|
859
|
+
# Import the ast module for safe evaluation of string literals
|
|
832
860
|
import ast
|
|
833
861
|
|
|
834
862
|
# Remove leading and trailing whitespace from the raw value to ensure clean input
|
|
@@ -866,6 +894,7 @@ class EnvironmentCaster(IEnvironmentCaster):
|
|
|
866
894
|
OrionisEnvironmentValueError
|
|
867
895
|
If the internal value is not a set.
|
|
868
896
|
"""
|
|
897
|
+
|
|
869
898
|
# Ensure the internal value is a set before conversion
|
|
870
899
|
if not isinstance(self.__value_raw, set):
|
|
871
900
|
# Raise an error if the value is not a set
|