orionis 0.421.0__py3-none-any.whl → 0.422.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.
@@ -1,577 +0,0 @@
1
- from orionis.services.environment.contracts.types import IEnvTypes
2
- from orionis.services.environment.exceptions import OrionisEnvironmentValueError, OrionisEnvironmentValueException
3
-
4
- class EnvTypes(IEnvTypes):
5
-
6
- # Type class to handle different types of environment variables
7
- OPTIONS = {
8
- 'path',
9
- 'str',
10
- 'int',
11
- 'float',
12
- 'bool',
13
- 'list',
14
- 'dict',
15
- 'tuple',
16
- 'set'
17
- }
18
-
19
- @staticmethod
20
- def options() -> set:
21
- """
22
- Returns the set of valid type hints that can be used with this Type class.
23
-
24
- Returns
25
- -------
26
- set
27
- A set containing the valid type hints.
28
- """
29
- return EnvTypes.OPTIONS
30
-
31
- def __init__(self, raw):
32
- """
33
- Parse a raw string input into a type hint and value string.
34
-
35
- Parameters
36
- ----------
37
- raw : str, optional
38
- String that may contain a type hint and value separated by a colon (e.g., "int: 42").
39
- If a colon is present, the part before the colon is treated as the type hint and the part after as the value.
40
- If no colon is present, the entire string is treated as the value with no type hint.
41
-
42
- Attributes
43
- ----------
44
- __type_hint : str or None
45
- The extracted type hint in lowercase, or None if not provided.
46
- __value_str : str or None
47
- The extracted value string, or None if not provided.
48
- """
49
-
50
- # Default values for type hint and value string
51
- self.__type_hint = None
52
- self.__value_raw = None
53
-
54
- # If raw is a string, parse it to extract type hint and value
55
- if isinstance(raw, str):
56
-
57
- # Strip whitespace and check for a colon to separate type hint and value
58
- self.__value_raw = raw.strip()
59
-
60
- # If a colon is present, split the string into type hint and value
61
- if ':' in self.__value_raw:
62
-
63
- # Split the string at the first colon
64
- type_hint, value_str = raw.split(':', 1)
65
-
66
- # If the type hint is valid, set it and the value
67
- if type_hint.strip().lower() in self.OPTIONS:
68
- self.__type_hint = type_hint.strip().lower()
69
- self.__value_raw = value_str.strip() if value_str else None
70
- else:
71
-
72
- # If raw is not a string, treat it as a value with no type hint
73
- self.__value_raw = raw
74
-
75
- def get(self):
76
- """
77
- Returns the value corresponding to the specified type hint.
78
-
79
- Checks if the provided type hint is valid and then dispatches the call to the appropriate
80
- method for handling the type.
81
-
82
- Supported type hints include: 'path:', 'str:', 'int:', 'float:', 'bool:', 'list:', 'dict:', 'tuple:', and 'set:'.
83
-
84
- Returns
85
- -------
86
- Any
87
- The value converted or processed according to the specified type hint.
88
-
89
- Raises
90
- ------
91
- OrionisEnvironmentValueError
92
- If the type hint is not one of the supported options.
93
- """
94
- if not self.__type_hint in self.OPTIONS:
95
- raise OrionisEnvironmentValueError(f"Invalid type hint: {self.__type_hint}. Must be one of {self.OPTIONS}.")
96
-
97
- if self.__type_hint == 'path':
98
- return self.__parsePath()
99
-
100
- if self.__type_hint == 'str':
101
- return self.__parseStr()
102
-
103
- if self.__type_hint == 'int':
104
- return self.__parseInt()
105
-
106
- if self.__type_hint == 'float':
107
- return self.__parseFloat()
108
-
109
- if self.__type_hint == 'bool':
110
- return self.__parseBool()
111
-
112
- if self.__type_hint == 'list':
113
- return self.__parseList()
114
-
115
- if self.__type_hint == 'dict':
116
- return self.__parseDict()
117
-
118
- if self.__type_hint == 'tuple':
119
- return self.__parseTuple()
120
-
121
- if self.__type_hint == 'set':
122
- return self.__parseSet()
123
-
124
- def to(self, type_hint: str):
125
- """
126
- Set the type hint for the Type instance.
127
-
128
- Parameters
129
- ----------
130
- type_hint : str
131
- The type hint to set, which must be one of the valid options defined in OPTIONS.
132
-
133
- Raises
134
- ------
135
- OrionisEnvironmentValueError
136
- If the provided type hint is not one of the valid options.
137
- """
138
-
139
- # Validate and set the type hint
140
- type_hint = type_hint.strip().lower()
141
- if type_hint not in self.OPTIONS:
142
- raise OrionisEnvironmentValueError(f"Invalid type hint: {type_hint}. Must be one of {self.OPTIONS}.")
143
- self.__type_hint = type_hint
144
-
145
- # Parse the value to the specified type hint
146
- if self.__type_hint == 'path':
147
- return self.__toPath()
148
-
149
- if self.__type_hint == 'str':
150
- return self.__toStr()
151
-
152
- if self.__type_hint == 'int':
153
- return self.__toInt()
154
-
155
- if self.__type_hint == 'float':
156
- return self.__toFloat()
157
-
158
- if self.__type_hint == 'bool':
159
- return self.__toBool()
160
-
161
- if self.__type_hint == 'list':
162
- return self.__toList()
163
-
164
- if self.__type_hint == 'dict':
165
- return self.__toDict()
166
-
167
- if self.__type_hint == 'tuple':
168
- return self.__toTuple()
169
-
170
- if self.__type_hint == 'set':
171
- return self.__toSet()
172
-
173
- def hasValidTypeHint(self) -> bool:
174
- """
175
- Check if the type hint is valid.
176
-
177
- Returns
178
- -------
179
- bool
180
- True if the type hint is valid (exists in the OPTIONS set), False otherwise.
181
- """
182
- return self.__type_hint in self.OPTIONS
183
-
184
- def explode(self) -> tuple:
185
- """
186
- Returns a tuple containing the type hint and value string.
187
-
188
- Returns
189
- -------
190
- tuple
191
- A tuple (type_hint, value_str) where:
192
- type_hint : str or None
193
- The extracted type hint in lowercase, or None if not provided.
194
- value_str : str or None
195
- The extracted value string, or None if not provided.
196
- """
197
- return self.__type_hint, self.__value_raw
198
-
199
- def __parsePath(self):
200
- """
201
- Returns the value as a string, assuming the type hint is 'path:'.
202
-
203
- Parameters
204
- ----------
205
- None
206
-
207
- Returns
208
- -------
209
- str
210
- The value string with backslashes replaced by forward slashes, if the type hint is 'path:'.
211
-
212
- Raises
213
- ------
214
- OrionisEnvironmentValueException
215
- If the value cannot be processed as a path.
216
- """
217
- return self.__value_raw.replace('\\', '/').strip()
218
-
219
- def __toPath(self):
220
- """
221
- Converts the internal string value to a formatted path string.
222
-
223
- Returns
224
- -------
225
- str
226
- A string representing the type hint and the value, with backslashes replaced by forward slashes.
227
-
228
- Raises
229
- ------
230
- OrionisEnvironmentValueError
231
- If the internal value is not a string.
232
- """
233
- if not isinstance(self.__value_raw, str):
234
- raise OrionisEnvironmentValueError(f"Value must be a string to convert to path, got {type(self.__value_raw).__name__} instead.")
235
- value = self.__value_raw.replace('\\', '/').strip()
236
- return f"{self.__type_hint}:{value}"
237
-
238
- def __parseStr(self):
239
- """
240
- Returns the value as a string, assuming the type hint is 'str:'.
241
-
242
- Returns
243
- -------
244
- str
245
- The value string if the type hint is 'str:', otherwise raises an error.
246
- """
247
- return self.__value_raw.strip()
248
-
249
- def __toStr(self):
250
- """
251
- Converts the internal value to a string representation.
252
-
253
- Returns
254
- -------
255
- str
256
- A string representing the type hint and the value.
257
-
258
- Raises
259
- ------
260
- OrionisEnvironmentValueError
261
- If the internal value is not a string.
262
- """
263
- if not isinstance(self.__value_raw, str):
264
- raise OrionisEnvironmentValueError(f"Value must be a string to convert to str, got {type(self.__value_raw).__name__} instead.")
265
- return f"{self.__type_hint}:{self.__value_raw}"
266
-
267
- def __parseInt(self):
268
- """
269
- Returns the value as an integer, assuming the type hint is 'int:'.
270
-
271
- Parameters
272
- ----------
273
- None
274
-
275
- Returns
276
- -------
277
- int
278
- The value converted to an integer if the type hint is 'int:'.
279
-
280
- Raises
281
- ------
282
- OrionisEnvironmentValueException
283
- If the value cannot be converted to an integer.
284
- """
285
- value = self.__value_raw.strip()
286
- try:
287
- return int(value)
288
- except ValueError as e:
289
- raise OrionisEnvironmentValueException(f"Cannot convert '{value}' to int: {str(e)}")
290
-
291
- def __toInt(self):
292
- """
293
- Converts the internal value to an integer representation.
294
-
295
- Returns
296
- -------
297
- str
298
- A string representing the type hint and the value as an integer.
299
-
300
- Raises
301
- ------
302
- OrionisEnvironmentValueError
303
- If the internal value is not a string or cannot be converted to an integer.
304
- """
305
- if not isinstance(self.__value_raw, int):
306
- raise OrionisEnvironmentValueError(f"Value must be an integer to convert to int, got {type(self.__value_raw).__name__} instead.")
307
- return f"{self.__type_hint}:{str(self.__value_raw)}"
308
-
309
- def __parseFloat(self):
310
- """
311
- Returns the value as a float, assuming the type hint is 'float:'.
312
-
313
- Parameters
314
- ----------
315
- None
316
-
317
- Returns
318
- -------
319
- float
320
- The value converted to a float if the type hint is 'float:'.
321
-
322
- Raises
323
- ------
324
- OrionisEnvironmentValueException
325
- If the value cannot be converted to a float.
326
- """
327
- value = self.__value_raw.strip()
328
- try:
329
- return float(value)
330
- except ValueError as e:
331
- raise OrionisEnvironmentValueException(f"Cannot convert '{value}' to float: {str(e)}")
332
-
333
- def __toFloat(self):
334
- """
335
- Converts the internal value to a float representation.
336
-
337
- Returns
338
- -------
339
- str
340
- A string representing the type hint and the value as a float.
341
-
342
- Raises
343
- ------
344
- OrionisEnvironmentValueError
345
- If the internal value is not a string or cannot be converted to a float.
346
- """
347
- if not isinstance(self.__value_raw, float):
348
- raise OrionisEnvironmentValueError(f"Value must be a float to convert to float, got {type(self.__value_raw).__name__} instead.")
349
- return f"{self.__type_hint}:{str(self.__value_raw)}"
350
-
351
- def __parseBool(self):
352
- """
353
- Returns the value as a boolean, assuming the type hint is 'bool:'.
354
-
355
- Parameters
356
- ----------
357
- None
358
-
359
- Returns
360
- -------
361
- bool
362
- The value converted to a boolean if the type hint is 'bool:'.
363
-
364
- Raises
365
- ------
366
- OrionisEnvironmentValueException
367
- If the value cannot be converted to a boolean.
368
- """
369
- value = self.__value_raw.strip().lower()
370
- if value in {'true', '1', 'yes', 'on'}:
371
- return True
372
- elif value in {'false', '0', 'no', 'off'}:
373
- return False
374
- else:
375
- raise OrionisEnvironmentValueException(f"Cannot convert '{value}' to bool.")
376
-
377
- def __toBool(self):
378
- """
379
- Converts the internal value to a boolean representation.
380
-
381
- Returns
382
- -------
383
- str
384
- A string representing the type hint and the value as a boolean.
385
-
386
- Raises
387
- ------
388
- OrionisEnvironmentValueError
389
- If the internal value is not a boolean.
390
- """
391
- if not isinstance(self.__value_raw, bool):
392
- raise OrionisEnvironmentValueError(f"Value must be a boolean to convert to bool, got {type(self.__value_raw).__name__} instead.")
393
- return f"{self.__type_hint}:{str(self.__value_raw).lower()}"
394
-
395
- def __parseList(self):
396
- """
397
- Returns the value as a list, assuming the type hint is 'list:'.
398
-
399
- Returns
400
- -------
401
- list
402
- The value converted to a list if the type hint is 'list:'.
403
-
404
- Raises
405
- ------
406
- OrionisEnvironmentValueException
407
- If the value cannot be converted to a list.
408
- """
409
- import ast
410
-
411
- value = self.__value_raw.strip()
412
- try:
413
- parsed = ast.literal_eval(value)
414
- if not isinstance(parsed, list):
415
- raise ValueError("Value is not a list")
416
- return parsed
417
- except (ValueError, SyntaxError) as e:
418
- raise OrionisEnvironmentValueException(f"Cannot convert '{value}' to list: {str(e)}")
419
-
420
- def __toList(self):
421
- """
422
- Converts the internal value to a list representation.
423
-
424
- Returns
425
- -------
426
- str
427
- A string representing the type hint and the value as a list.
428
-
429
- Raises
430
- ------
431
- OrionisEnvironmentValueError
432
- If the internal value is not a list.
433
- """
434
- if not isinstance(self.__value_raw, list):
435
- raise OrionisEnvironmentValueError(f"Value must be a list to convert to list, got {type(self.__value_raw).__name__} instead.")
436
- return f"{self.__type_hint}:{repr(self.__value_raw)}"
437
-
438
- def __parseDict(self):
439
- """
440
- Returns the value as a dict, assuming the type hint is 'dict:'.
441
-
442
- Parameters
443
- ----------
444
- None
445
-
446
- Returns
447
- -------
448
- dict
449
- The value converted to a dict if the type hint is 'dict:'.
450
-
451
- Raises
452
- ------
453
- OrionisEnvironmentValueException
454
- If the value cannot be converted to a dict.
455
- """
456
- import ast
457
-
458
- value = self.__value_raw.strip()
459
- try:
460
- parsed = ast.literal_eval(value)
461
- if not isinstance(parsed, dict):
462
- raise ValueError("Value is not a dict")
463
- return parsed
464
- except (ValueError, SyntaxError) as e:
465
- raise OrionisEnvironmentValueException(f"Cannot convert '{value}' to dict: {str(e)}")
466
-
467
- def __toDict(self):
468
- """
469
- Converts the internal value to a dict representation.
470
-
471
- Returns
472
- -------
473
- str
474
- A string representing the type hint and the value as a dict.
475
-
476
- Raises
477
- ------
478
- OrionisEnvironmentValueError
479
- If the internal value is not a dict.
480
- """
481
- if not isinstance(self.__value_raw, dict):
482
- raise OrionisEnvironmentValueError(f"Value must be a dict to convert to dict, got {type(self.__value_raw).__name__} instead.")
483
- return f"{self.__type_hint}:{repr(self.__value_raw)}"
484
-
485
- def __parseTuple(self):
486
- """
487
- Returns the value as a tuple, assuming the type hint is 'tuple:'.
488
-
489
- Parameters
490
- ----------
491
- None
492
-
493
- Returns
494
- -------
495
- tuple
496
- The value converted to a tuple if the type hint is 'tuple:'.
497
-
498
- Raises
499
- ------
500
- OrionisEnvironmentValueException
501
- If the value cannot be converted to a tuple.
502
- """
503
- import ast
504
-
505
- value = self.__value_raw.strip()
506
- try:
507
- parsed = ast.literal_eval(value)
508
- if not isinstance(parsed, tuple):
509
- raise ValueError("Value is not a tuple")
510
- return parsed
511
- except (ValueError, SyntaxError) as e:
512
- raise OrionisEnvironmentValueException(f"Cannot convert '{value}' to tuple: {str(e)}")
513
-
514
- def __toTuple(self):
515
- """
516
- Converts the internal value to a tuple representation.
517
-
518
- Returns
519
- -------
520
- str
521
- A string representing the type hint and the value as a tuple.
522
-
523
- Raises
524
- ------
525
- OrionisEnvironmentValueError
526
- If the internal value is not a tuple.
527
- """
528
- if not isinstance(self.__value_raw, tuple):
529
- raise OrionisEnvironmentValueError(f"Value must be a tuple to convert to tuple, got {type(self.__value_raw).__name__} instead.")
530
- return f"{self.__type_hint}:{repr(self.__value_raw)}"
531
-
532
- def __parseSet(self):
533
- """
534
- Returns the value as a set, assuming the type hint is 'set:'.
535
-
536
- Parameters
537
- ----------
538
- None
539
-
540
- Returns
541
- -------
542
- set
543
- The value converted to a set if the type hint is 'set:'.
544
-
545
- Raises
546
- ------
547
- OrionisEnvironmentValueException
548
- If the value cannot be converted to a set.
549
- """
550
- import ast
551
-
552
- value = self.__value_raw.strip()
553
- try:
554
- parsed = ast.literal_eval(value)
555
- if not isinstance(parsed, set):
556
- raise ValueError("Value is not a set")
557
- return parsed
558
- except (ValueError, SyntaxError) as e:
559
- raise OrionisEnvironmentValueException(f"Cannot convert '{value}' to set: {str(e)}")
560
-
561
- def __toSet(self):
562
- """
563
- Converts the internal value to a set representation.
564
-
565
- Returns
566
- -------
567
- str
568
- A string representing the type hint and the value as a set.
569
-
570
- Raises
571
- ------
572
- OrionisEnvironmentValueError
573
- If the internal value is not a set.
574
- """
575
- if not isinstance(self.__value_raw, set):
576
- raise OrionisEnvironmentValueError(f"Value must be a set to convert to set, got {type(self.__value_raw).__name__} instead.")
577
- return f"{self.__type_hint}:{repr(self.__value_raw)}"
File without changes
@@ -1,21 +0,0 @@
1
- from orionis.services.environment.enums.cast_type import EnvCastType
2
-
3
- class SerializerValue:
4
-
5
- def __init__(self, value):
6
- pass
7
-
8
- def to(self, type_hint: str | EnvCastType = None):
9
- pass
10
-
11
- def get(self):
12
- pass
13
-
14
-
15
- class SerializerFrom:
16
-
17
- def __init__(self, key: str):
18
- pass
19
-
20
- def get(self):
21
- pass