orionis 0.434.0__py3-none-any.whl → 0.436.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/asynchrony/contracts/coroutines.py +5 -10
- orionis/services/asynchrony/coroutines.py +8 -23
- orionis/services/asynchrony/exceptions/exception.py +3 -5
- orionis/services/environment/contracts/caster.py +8 -9
- orionis/services/environment/contracts/env.py +9 -9
- orionis/services/environment/core/dot_env.py +47 -71
- orionis/services/environment/dynamic/caster.py +191 -220
- orionis/services/environment/enums/__init__.py +5 -0
- orionis/services/environment/enums/value_type.py +22 -25
- orionis/services/environment/env.py +28 -12
- orionis/services/environment/exceptions/exception.py +6 -2
- orionis/services/environment/exceptions/value.py +6 -2
- orionis/services/environment/helpers/functions.py +5 -3
- orionis/services/environment/key/key_generator.py +8 -12
- orionis/services/environment/validators/__init__.py +7 -0
- orionis/services/environment/validators/key_name.py +5 -6
- orionis/services/environment/validators/types.py +29 -13
- orionis/test/core/unit_test.py +292 -55
- {orionis-0.434.0.dist-info → orionis-0.436.0.dist-info}/METADATA +1 -1
- {orionis-0.434.0.dist-info → orionis-0.436.0.dist-info}/RECORD +25 -25
- {orionis-0.434.0.dist-info → orionis-0.436.0.dist-info}/WHEEL +0 -0
- {orionis-0.434.0.dist-info → orionis-0.436.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.434.0.dist-info → orionis-0.436.0.dist-info}/top_level.txt +0 -0
- {orionis-0.434.0.dist-info → orionis-0.436.0.dist-info}/zip-safe +0 -0
orionis/metadata/framework.py
CHANGED
|
@@ -9,24 +9,19 @@ class ICoroutine(ABC):
|
|
|
9
9
|
@abstractmethod
|
|
10
10
|
def run(self) -> Union[T, asyncio.Future]:
|
|
11
11
|
"""
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Parameters
|
|
15
|
-
----------
|
|
16
|
-
None
|
|
12
|
+
Execute the wrapped coroutine either synchronously or asynchronously, depending on the execution context.
|
|
17
13
|
|
|
18
14
|
Returns
|
|
19
15
|
-------
|
|
20
16
|
T or asyncio.Future
|
|
21
|
-
If called outside an event loop, returns the result of the coroutine execution (type T).
|
|
17
|
+
If called outside of an event loop, returns the result of the coroutine execution (type T).
|
|
22
18
|
If called within an event loop, returns an asyncio.Future representing the scheduled coroutine.
|
|
23
19
|
|
|
24
20
|
Notes
|
|
25
21
|
-----
|
|
26
|
-
-
|
|
27
|
-
-
|
|
22
|
+
- Executes the coroutine synchronously and returns its result when called outside an event loop.
|
|
23
|
+
- Schedules the coroutine for asynchronous execution and returns a Future when called inside an event loop.
|
|
28
24
|
- The caller is responsible for awaiting the Future if asynchronous execution is used.
|
|
29
25
|
"""
|
|
30
|
-
|
|
31
26
|
# This method should be implemented by subclasses to handle coroutine execution.
|
|
32
|
-
pass
|
|
27
|
+
pass
|
|
@@ -10,27 +10,17 @@ class Coroutine(ICoroutine):
|
|
|
10
10
|
|
|
11
11
|
def __init__(self, func: TypingCoroutine[Any, Any, T]) -> None:
|
|
12
12
|
"""
|
|
13
|
-
|
|
13
|
+
Wraps a coroutine object and validates its type.
|
|
14
14
|
|
|
15
15
|
Parameters
|
|
16
16
|
----------
|
|
17
17
|
func : Coroutine
|
|
18
|
-
The coroutine object to be wrapped
|
|
18
|
+
The coroutine object to be wrapped and managed.
|
|
19
19
|
|
|
20
20
|
Raises
|
|
21
21
|
------
|
|
22
22
|
OrionisCoroutineException
|
|
23
23
|
If the provided object is not a coroutine.
|
|
24
|
-
|
|
25
|
-
Returns
|
|
26
|
-
-------
|
|
27
|
-
None
|
|
28
|
-
This method does not return a value.
|
|
29
|
-
|
|
30
|
-
Notes
|
|
31
|
-
-----
|
|
32
|
-
This constructor validates that the provided object is a coroutine using the framework's type introspection.
|
|
33
|
-
If the validation fails, an exception is raised to prevent improper usage.
|
|
34
24
|
"""
|
|
35
25
|
# Validate that the provided object is a coroutine
|
|
36
26
|
if not Type(func).isCoroutine():
|
|
@@ -43,17 +33,12 @@ class Coroutine(ICoroutine):
|
|
|
43
33
|
|
|
44
34
|
def run(self) -> Union[T, asyncio.Future]:
|
|
45
35
|
"""
|
|
46
|
-
Executes the wrapped coroutine,
|
|
47
|
-
|
|
48
|
-
Parameters
|
|
49
|
-
----------
|
|
50
|
-
None
|
|
36
|
+
Executes the wrapped coroutine, adapting to the current event loop context.
|
|
51
37
|
|
|
52
38
|
Returns
|
|
53
39
|
-------
|
|
54
40
|
T or asyncio.Future
|
|
55
|
-
|
|
56
|
-
If called within an event loop, returns an asyncio.Future representing the scheduled coroutine.
|
|
41
|
+
The result of the coroutine if executed synchronously, or an asyncio.Future if scheduled asynchronously.
|
|
57
42
|
|
|
58
43
|
Raises
|
|
59
44
|
------
|
|
@@ -62,9 +47,9 @@ class Coroutine(ICoroutine):
|
|
|
62
47
|
|
|
63
48
|
Notes
|
|
64
49
|
-----
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
50
|
+
- If called outside an active event loop, the coroutine is executed synchronously and its result is returned.
|
|
51
|
+
- If called within an active event loop, the coroutine is scheduled for asynchronous execution and a Future is returned.
|
|
52
|
+
- The method automatically detects the execution context and chooses the appropriate execution strategy.
|
|
68
53
|
"""
|
|
69
54
|
# Attempt to get the currently running event loop
|
|
70
55
|
try:
|
|
@@ -80,4 +65,4 @@ class Coroutine(ICoroutine):
|
|
|
80
65
|
|
|
81
66
|
# If no event loop is running, execute the coroutine synchronously using the loop
|
|
82
67
|
else:
|
|
83
|
-
return loop.run_until_complete(self.__func)
|
|
68
|
+
return loop.run_until_complete(self.__func)
|
|
@@ -2,26 +2,24 @@ class OrionisCoroutineException(Exception):
|
|
|
2
2
|
|
|
3
3
|
def __init__(self, msg: str):
|
|
4
4
|
"""
|
|
5
|
-
|
|
5
|
+
Initialize the OrionisCoroutineException.
|
|
6
6
|
|
|
7
7
|
Parameters
|
|
8
8
|
----------
|
|
9
9
|
msg : str
|
|
10
|
-
|
|
10
|
+
A descriptive error message explaining the cause of the exception.
|
|
11
11
|
"""
|
|
12
|
-
|
|
13
12
|
# Call the base Exception constructor with the provided message
|
|
14
13
|
super().__init__(msg)
|
|
15
14
|
|
|
16
15
|
def __str__(self) -> str:
|
|
17
16
|
"""
|
|
18
|
-
|
|
17
|
+
Return the string representation of the exception.
|
|
19
18
|
|
|
20
19
|
Returns
|
|
21
20
|
-------
|
|
22
21
|
str
|
|
23
22
|
The error message provided during exception initialization.
|
|
24
23
|
"""
|
|
25
|
-
|
|
26
24
|
# Return the first argument passed to the Exception, which is the error message
|
|
27
25
|
return str(self.args[0])
|
|
@@ -10,24 +10,23 @@ class IEnvironmentCaster(ABC):
|
|
|
10
10
|
Parameters
|
|
11
11
|
----------
|
|
12
12
|
type_hint : str
|
|
13
|
-
The type hint to
|
|
13
|
+
The type hint to assign. Must be one of the valid options defined in OPTIONS.
|
|
14
14
|
|
|
15
15
|
Raises
|
|
16
16
|
------
|
|
17
17
|
OrionisEnvironmentValueError
|
|
18
|
-
If the provided type hint is not
|
|
18
|
+
If the provided type hint is not among the valid options.
|
|
19
19
|
"""
|
|
20
20
|
pass
|
|
21
21
|
|
|
22
22
|
@abstractmethod
|
|
23
23
|
def get(self):
|
|
24
24
|
"""
|
|
25
|
-
|
|
25
|
+
Retrieve the value corresponding to the specified type hint.
|
|
26
26
|
|
|
27
|
-
Checks
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Supported type hints include: 'path:', 'str:', 'int:', 'float:', 'bool:', 'list:', 'dict:', 'tuple:', and 'set:'.
|
|
27
|
+
Checks the validity of the provided type hint and dispatches the call to the appropriate
|
|
28
|
+
handler for the type. Supported type hints include: 'path:', 'str:', 'int:', 'float:',
|
|
29
|
+
'bool:', 'list:', 'dict:', 'tuple:', and 'set:'.
|
|
31
30
|
|
|
32
31
|
Returns
|
|
33
32
|
-------
|
|
@@ -37,6 +36,6 @@ class IEnvironmentCaster(ABC):
|
|
|
37
36
|
Raises
|
|
38
37
|
------
|
|
39
38
|
OrionisEnvironmentValueError
|
|
40
|
-
If the type hint is not
|
|
39
|
+
If the type hint is not supported.
|
|
41
40
|
"""
|
|
42
|
-
pass
|
|
41
|
+
pass
|
|
@@ -7,19 +7,19 @@ class IEnv(ABC):
|
|
|
7
7
|
@abstractmethod
|
|
8
8
|
def get(key: str, default: Any = None) -> Any:
|
|
9
9
|
"""
|
|
10
|
-
|
|
10
|
+
Retrieves the value of the specified environment variable.
|
|
11
11
|
|
|
12
12
|
Parameters
|
|
13
13
|
----------
|
|
14
14
|
key : str
|
|
15
15
|
The name of the environment variable to retrieve.
|
|
16
16
|
default : Any, optional
|
|
17
|
-
The value to return if the
|
|
17
|
+
The value to return if the environment variable is not found. Defaults to None.
|
|
18
18
|
|
|
19
19
|
Returns
|
|
20
20
|
-------
|
|
21
21
|
Any
|
|
22
|
-
The value of the environment variable if
|
|
22
|
+
The value of the environment variable if it exists, otherwise the default value.
|
|
23
23
|
"""
|
|
24
24
|
pass
|
|
25
25
|
|
|
@@ -27,7 +27,7 @@ class IEnv(ABC):
|
|
|
27
27
|
@abstractmethod
|
|
28
28
|
def set(key: str, value: str, type: str = None) -> bool:
|
|
29
29
|
"""
|
|
30
|
-
|
|
30
|
+
Sets the value of an environment variable in the .env file.
|
|
31
31
|
|
|
32
32
|
Parameters
|
|
33
33
|
----------
|
|
@@ -36,12 +36,12 @@ class IEnv(ABC):
|
|
|
36
36
|
value : str
|
|
37
37
|
The value to assign to the environment variable.
|
|
38
38
|
type : str, optional
|
|
39
|
-
The type of the environment variable (e.g., 'str', 'int').
|
|
39
|
+
The type of the environment variable (e.g., 'str', 'int'). Defaults to None.
|
|
40
40
|
|
|
41
41
|
Returns
|
|
42
42
|
-------
|
|
43
43
|
bool
|
|
44
|
-
True if the variable was set successfully, False otherwise.
|
|
44
|
+
True if the environment variable was set successfully, False otherwise.
|
|
45
45
|
"""
|
|
46
46
|
pass
|
|
47
47
|
|
|
@@ -49,7 +49,7 @@ class IEnv(ABC):
|
|
|
49
49
|
@abstractmethod
|
|
50
50
|
def unset(key: str) -> bool:
|
|
51
51
|
"""
|
|
52
|
-
|
|
52
|
+
Removes the specified environment variable from the .env file.
|
|
53
53
|
|
|
54
54
|
Parameters
|
|
55
55
|
----------
|
|
@@ -59,7 +59,7 @@ class IEnv(ABC):
|
|
|
59
59
|
Returns
|
|
60
60
|
-------
|
|
61
61
|
bool
|
|
62
|
-
True if the variable was successfully
|
|
62
|
+
True if the environment variable was removed successfully, False otherwise.
|
|
63
63
|
"""
|
|
64
64
|
pass
|
|
65
65
|
|
|
@@ -67,7 +67,7 @@ class IEnv(ABC):
|
|
|
67
67
|
@abstractmethod
|
|
68
68
|
def all() -> Dict[str, Any]:
|
|
69
69
|
"""
|
|
70
|
-
|
|
70
|
+
Retrieves all environment variables as a dictionary.
|
|
71
71
|
|
|
72
72
|
Returns
|
|
73
73
|
-------
|
|
@@ -4,9 +4,8 @@ import threading
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from typing import Any, Optional, Union
|
|
6
6
|
from dotenv import dotenv_values, load_dotenv, set_key, unset_key
|
|
7
|
-
from orionis.services.environment.enums
|
|
8
|
-
from orionis.services.environment.validators
|
|
9
|
-
from orionis.services.environment.validators.types import ValidateTypes
|
|
7
|
+
from orionis.services.environment.enums import EnvironmentValueType
|
|
8
|
+
from orionis.services.environment.validators import ValidateKeyName, ValidateTypes
|
|
10
9
|
from orionis.support.patterns.singleton import Singleton
|
|
11
10
|
from orionis.services.environment.dynamic.caster import EnvironmentCaster
|
|
12
11
|
|
|
@@ -22,20 +21,10 @@ class DotEnv(metaclass=Singleton):
|
|
|
22
21
|
"""
|
|
23
22
|
Initialize the DotEnv service and prepare the `.env` file for environment variable management.
|
|
24
23
|
|
|
25
|
-
This constructor determines the location of the `.env` file, ensures its existence,
|
|
26
|
-
and loads its contents into the current process environment. If a custom path is provided,
|
|
27
|
-
it is resolved and used; otherwise, a `.env` file in the current working directory is used.
|
|
28
|
-
|
|
29
24
|
Parameters
|
|
30
25
|
----------
|
|
31
26
|
path : str, optional
|
|
32
|
-
|
|
33
|
-
in the current working directory.
|
|
34
|
-
|
|
35
|
-
Returns
|
|
36
|
-
-------
|
|
37
|
-
None
|
|
38
|
-
This method does not return any value.
|
|
27
|
+
Path to the `.env` file. If not provided, defaults to `.env` in the current working directory.
|
|
39
28
|
|
|
40
29
|
Raises
|
|
41
30
|
------
|
|
@@ -44,16 +33,16 @@ class DotEnv(metaclass=Singleton):
|
|
|
44
33
|
|
|
45
34
|
Notes
|
|
46
35
|
-----
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
- Loads environment variables from the `.env` file into the process environment.
|
|
36
|
+
Ensures thread safety during initialization. If the specified `.env` file does not exist, it is created.
|
|
37
|
+
Loads environment variables from the `.env` file into the process environment.
|
|
50
38
|
"""
|
|
39
|
+
|
|
51
40
|
try:
|
|
52
41
|
|
|
53
|
-
# Ensure thread-safe initialization
|
|
42
|
+
# Ensure thread-safe initialization to avoid race conditions
|
|
54
43
|
with self._lock:
|
|
55
44
|
|
|
56
|
-
# Set default .env file path to current working directory
|
|
45
|
+
# Set the default .env file path to the current working directory
|
|
57
46
|
self.__resolved_path = Path(os.getcwd()) / ".env"
|
|
58
47
|
|
|
59
48
|
# If a custom path is provided, resolve and use it
|
|
@@ -81,41 +70,47 @@ class DotEnv(metaclass=Singleton):
|
|
|
81
70
|
"""
|
|
82
71
|
Set an environment variable in both the `.env` file and the current process environment.
|
|
83
72
|
|
|
84
|
-
This method serializes the provided value (optionally using a type hint), validates the key,
|
|
85
|
-
and updates the corresponding entry in the `.env` file as well as the process's environment
|
|
86
|
-
variables. Thread safety is ensured during the operation.
|
|
87
|
-
|
|
88
73
|
Parameters
|
|
89
74
|
----------
|
|
90
75
|
key : str
|
|
91
76
|
The name of the environment variable to set. Must be a valid environment variable name.
|
|
92
|
-
value :
|
|
93
|
-
The value to assign to the environment variable.
|
|
94
|
-
float, boolean, list, dictionary, tuple, and set.
|
|
77
|
+
value : str, int, float, bool, list, dict, tuple, or set
|
|
78
|
+
The value to assign to the environment variable.
|
|
95
79
|
type_hint : str or EnvironmentValueType, optional
|
|
96
|
-
An explicit type hint to guide serialization
|
|
97
|
-
according to the specified type.
|
|
80
|
+
An explicit type hint to guide the serialization of the value.
|
|
98
81
|
|
|
99
82
|
Returns
|
|
100
83
|
-------
|
|
101
84
|
bool
|
|
102
|
-
|
|
103
|
-
and the current process environment.
|
|
85
|
+
True if the environment variable was successfully set.
|
|
104
86
|
|
|
105
87
|
Raises
|
|
106
88
|
------
|
|
107
89
|
OrionisEnvironmentValueError
|
|
108
90
|
If the provided key is not a valid environment variable name.
|
|
91
|
+
|
|
92
|
+
Notes
|
|
93
|
+
-----
|
|
94
|
+
This method ensures thread safety during the set operation. It validates the key name,
|
|
95
|
+
serializes the value (optionally using a type hint), writes the variable to the `.env` file,
|
|
96
|
+
and updates the variable in the current process environment.
|
|
109
97
|
"""
|
|
110
98
|
with self._lock:
|
|
99
|
+
|
|
111
100
|
# Validate the environment variable key name.
|
|
112
101
|
__key = ValidateKeyName(key)
|
|
113
102
|
|
|
114
103
|
# If a type hint is provided, validate and serialize the value accordingly.
|
|
115
104
|
if type_hint is not None:
|
|
105
|
+
|
|
106
|
+
# Validate the value against the provided type hint.
|
|
116
107
|
__type = ValidateTypes(value, type_hint)
|
|
108
|
+
|
|
109
|
+
# Serialize the value using the validated type.
|
|
117
110
|
__value = self.__serializeValue(value, __type)
|
|
111
|
+
|
|
118
112
|
else:
|
|
113
|
+
|
|
119
114
|
# Serialize the value without a type hint.
|
|
120
115
|
__value = self.__serializeValue(value)
|
|
121
116
|
|
|
@@ -134,7 +129,7 @@ class DotEnv(metaclass=Singleton):
|
|
|
134
129
|
default: Optional[Any] = None
|
|
135
130
|
) -> Any:
|
|
136
131
|
"""
|
|
137
|
-
|
|
132
|
+
Retrieve the value of an environment variable.
|
|
138
133
|
|
|
139
134
|
Parameters
|
|
140
135
|
----------
|
|
@@ -172,20 +167,15 @@ class DotEnv(metaclass=Singleton):
|
|
|
172
167
|
"""
|
|
173
168
|
Remove an environment variable from both the `.env` file and the current process environment.
|
|
174
169
|
|
|
175
|
-
This method deletes the specified environment variable from the resolved `.env` file
|
|
176
|
-
and removes it from the current process's environment variables. The operation is
|
|
177
|
-
performed in a thread-safe manner. The key is validated before removal.
|
|
178
|
-
|
|
179
170
|
Parameters
|
|
180
171
|
----------
|
|
181
172
|
key : str
|
|
182
|
-
|
|
173
|
+
Name of the environment variable to remove.
|
|
183
174
|
|
|
184
175
|
Returns
|
|
185
176
|
-------
|
|
186
177
|
bool
|
|
187
|
-
|
|
188
|
-
and the process environment. Returns True even if the variable does not exist.
|
|
178
|
+
True if the environment variable was successfully removed.
|
|
189
179
|
|
|
190
180
|
Raises
|
|
191
181
|
------
|
|
@@ -194,9 +184,10 @@ class DotEnv(metaclass=Singleton):
|
|
|
194
184
|
|
|
195
185
|
Notes
|
|
196
186
|
-----
|
|
197
|
-
|
|
198
|
-
- If the environment variable does not exist, the method has no effect and returns True.
|
|
187
|
+
If the environment variable does not exist, the method has no effect and returns True.
|
|
199
188
|
"""
|
|
189
|
+
|
|
190
|
+
# Ensure thread-safe operation during the unset process.
|
|
200
191
|
with self._lock:
|
|
201
192
|
|
|
202
193
|
# Validate the environment variable key name.
|
|
@@ -215,24 +206,19 @@ class DotEnv(metaclass=Singleton):
|
|
|
215
206
|
"""
|
|
216
207
|
Retrieve all environment variables from the resolved `.env` file as a dictionary.
|
|
217
208
|
|
|
218
|
-
This method reads all key-value pairs from the currently resolved `.env` file and
|
|
219
|
-
parses each value into its appropriate Python type using the internal `__parseValue`
|
|
220
|
-
method. The returned dictionary contains environment variable names as keys and their
|
|
221
|
-
parsed values as values.
|
|
222
|
-
|
|
223
209
|
Returns
|
|
224
210
|
-------
|
|
225
211
|
dict
|
|
226
|
-
|
|
227
|
-
is the parsed Python representation of the variable
|
|
228
|
-
If the `.env` file is empty, an empty dictionary is returned.
|
|
212
|
+
Dictionary where each key is an environment variable name (str) and each value
|
|
213
|
+
is the parsed Python representation of the variable.
|
|
229
214
|
|
|
230
215
|
Notes
|
|
231
216
|
-----
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
process environment are not included.
|
|
217
|
+
Only variables present in the `.env` file are returned; variables set only in the
|
|
218
|
+
process environment are not included.
|
|
235
219
|
"""
|
|
220
|
+
|
|
221
|
+
# Ensure thread-safe operation while reading and parsing environment variables.
|
|
236
222
|
with self._lock:
|
|
237
223
|
|
|
238
224
|
# Read all raw key-value pairs from the .env file
|
|
@@ -249,24 +235,18 @@ class DotEnv(metaclass=Singleton):
|
|
|
249
235
|
"""
|
|
250
236
|
Serialize a Python value into a string suitable for storage in a .env file.
|
|
251
237
|
|
|
252
|
-
This method converts the provided value into a string representation that can be
|
|
253
|
-
safely written to a .env file. If a type hint is provided, the value is serialized
|
|
254
|
-
according to the specified type using the EnvTypes utility. Otherwise, the method
|
|
255
|
-
infers the serialization strategy based on the value's type.
|
|
256
|
-
|
|
257
238
|
Parameters
|
|
258
239
|
----------
|
|
259
240
|
value : Any
|
|
260
|
-
|
|
241
|
+
Value to serialize. Supported types include None, str, int, float, bool,
|
|
261
242
|
list, dict, tuple, and set.
|
|
262
243
|
type_hint : str or EnvironmentValueType, optional
|
|
263
|
-
|
|
264
|
-
serialized using EnvTypes.
|
|
244
|
+
Explicit type hint to guide serialization.
|
|
265
245
|
|
|
266
246
|
Returns
|
|
267
247
|
-------
|
|
268
248
|
str
|
|
269
|
-
|
|
249
|
+
Serialized string representation of the input value, suitable for storage
|
|
270
250
|
in a .env file. Returns "null" for None values.
|
|
271
251
|
"""
|
|
272
252
|
|
|
@@ -308,28 +288,24 @@ class DotEnv(metaclass=Singleton):
|
|
|
308
288
|
"""
|
|
309
289
|
Parse a string or raw value from the .env file into its appropriate Python type.
|
|
310
290
|
|
|
311
|
-
This method attempts to convert the input value, which may be a string or already a Python object,
|
|
312
|
-
into its most suitable Python type. It handles common representations of null, booleans, and
|
|
313
|
-
attempts to parse collections and literals. If parsing fails, the original string is returned.
|
|
314
|
-
|
|
315
291
|
Parameters
|
|
316
292
|
----------
|
|
317
293
|
value : Any
|
|
318
|
-
|
|
294
|
+
Value to parse, typically a string read from the .env file, but may also be a Python object.
|
|
319
295
|
|
|
320
296
|
Returns
|
|
321
297
|
-------
|
|
322
298
|
Any
|
|
323
|
-
|
|
299
|
+
Parsed Python value. Returns `None` for recognized null representations, a boolean for
|
|
324
300
|
"true"/"false" strings, a Python literal (list, dict, int, etc.) if possible, or the original
|
|
325
301
|
string if no conversion is possible.
|
|
326
302
|
|
|
327
303
|
Notes
|
|
328
304
|
-----
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
305
|
+
Recognizes 'none', 'null', 'nan', 'nil' (case-insensitive) as null values.
|
|
306
|
+
Attempts to use `EnvironmentCaster` for advanced type parsing.
|
|
307
|
+
Falls back to `ast.literal_eval` for literal evaluation.
|
|
308
|
+
Returns the original string if all parsing attempts fail.
|
|
333
309
|
"""
|
|
334
310
|
|
|
335
311
|
# Early return for None values
|
|
@@ -365,4 +341,4 @@ class DotEnv(metaclass=Singleton):
|
|
|
365
341
|
|
|
366
342
|
# Return the original string if parsing fails
|
|
367
343
|
except (ValueError, SyntaxError):
|
|
368
|
-
return value_str
|
|
344
|
+
return value_str
|