everysk-lib 1.10.3__cp312-cp312-win_amd64.whl → 1.11.0__cp312-cp312-win_amd64.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.
- everysk/core/_tests/mapping/__init__.py +9 -0
- everysk/core/_tests/mapping/base.py +306 -0
- everysk/core/_tests/mapping/fields.py +1154 -0
- everysk/core/datetime/datetime.py +1 -1
- everysk/core/http.py +6 -6
- everysk/core/mapping/__init__.py +29 -0
- everysk/core/mapping/base.py +214 -0
- everysk/core/mapping/fields.py +1133 -0
- everysk/core/mapping/metaclass.py +101 -0
- everysk/core/object.py +132 -124
- everysk/core/tests.py +19 -0
- everysk/sdk/engines/expression.cp312-win_amd64.pyd +0 -0
- everysk/sdk/engines/helpers.cp312-win_amd64.pyd +0 -0
- everysk/sdk/entities/script.py +0 -1
- everysk/sql/connection.py +24 -0
- {everysk_lib-1.10.3.dist-info → everysk_lib-1.11.0.dist-info}/METADATA +2 -2
- {everysk_lib-1.10.3.dist-info → everysk_lib-1.11.0.dist-info}/RECORD +21 -14
- {everysk_lib-1.10.3.dist-info → everysk_lib-1.11.0.dist-info}/.gitignore +0 -0
- {everysk_lib-1.10.3.dist-info → everysk_lib-1.11.0.dist-info}/WHEEL +0 -0
- {everysk_lib-1.10.3.dist-info → everysk_lib-1.11.0.dist-info}/licenses/LICENSE.txt +0 -0
- {everysk_lib-1.10.3.dist-info → everysk_lib-1.11.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright 2025 EVERYSK TECHNOLOGIES
|
|
4
|
+
#
|
|
5
|
+
# This is an unpublished work containing confidential and proprietary
|
|
6
|
+
# information of EVERYSK TECHNOLOGIES. Disclosure, use, or reproduction
|
|
7
|
+
# without authorization of EVERYSK TECHNOLOGIES is prohibited.
|
|
8
|
+
#
|
|
9
|
+
###############################################################################
|
|
10
|
+
from inspect import isroutine
|
|
11
|
+
from typing import TYPE_CHECKING, Any, TypeVar
|
|
12
|
+
|
|
13
|
+
from everysk.core.mapping.fields import BaseMappingField, get_field_type
|
|
14
|
+
|
|
15
|
+
MT = TypeVar('MT', bound='BaseMapping')
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from everysk.core.mapping.base import BaseMapping
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class BaseMappingMetaClass(type):
|
|
21
|
+
# Method called when a class is created in the Python runtime
|
|
22
|
+
def __new__(cls, name: str, bases: tuple[type, ...], attrs: dict[str, Any]) -> MT:
|
|
23
|
+
# We need to ensure that __annotations__ exists so the code doesn't fail
|
|
24
|
+
if '__annotations__' not in attrs or attrs['__annotations__'] is None:
|
|
25
|
+
attrs['__annotations__'] = {}
|
|
26
|
+
|
|
27
|
+
if '__attributes__' not in attrs or attrs['__attributes__'] is None:
|
|
28
|
+
attrs['__attributes__'] = set()
|
|
29
|
+
|
|
30
|
+
# Attributes that are inside annotations -> var: str or var: str = 'value'
|
|
31
|
+
# Attributes that are not inside annotations -> var = 'value'
|
|
32
|
+
# We need to get both
|
|
33
|
+
for key in attrs['__annotations__'].keys() | attrs.keys():
|
|
34
|
+
# Discard internal attributes
|
|
35
|
+
if not key.startswith('__'):
|
|
36
|
+
default_value = attrs.get(key)
|
|
37
|
+
if not isroutine(default_value) and not isinstance(default_value, property):
|
|
38
|
+
if not isinstance(default_value, BaseMappingField):
|
|
39
|
+
# If the attribute is not inside annotations (Ex: var = 'value'), we add it
|
|
40
|
+
if key not in attrs['__annotations__']:
|
|
41
|
+
field_type = get_field_type(type(default_value))
|
|
42
|
+
attrs['__annotations__'][key] = field_type
|
|
43
|
+
else:
|
|
44
|
+
field_type = get_field_type(attrs['__annotations__'][key])
|
|
45
|
+
|
|
46
|
+
# Change the attribute to a BaseMappingField descriptor
|
|
47
|
+
attrs[key] = BaseMappingField(default=default_value, field_name=key, field_type=field_type)
|
|
48
|
+
else:
|
|
49
|
+
# By default, descriptors don't add themselves to annotations
|
|
50
|
+
field_type = default_value.field_type
|
|
51
|
+
attrs['__annotations__'][key] = field_type
|
|
52
|
+
|
|
53
|
+
obj: BaseMapping = super().__new__(cls, name, bases, attrs)
|
|
54
|
+
obj._generate_attributes() # noqa: SLF001
|
|
55
|
+
return obj
|
|
56
|
+
|
|
57
|
+
def __setattr__(cls: 'BaseMapping', name: str, value: Any) -> None:
|
|
58
|
+
"""
|
|
59
|
+
Set attribute in the class, used to define new attributes dynamically.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
cls (BaseMapping): The class in which to set the attribute.
|
|
63
|
+
name (str): The name of the attribute to set.
|
|
64
|
+
value (Any): The value to set for the attribute.
|
|
65
|
+
"""
|
|
66
|
+
# Internal attributes are set normally
|
|
67
|
+
# They are __attributes__, __annotations__, etc.
|
|
68
|
+
if name.startswith('__'):
|
|
69
|
+
return super().__setattr__(name, value)
|
|
70
|
+
|
|
71
|
+
if name not in cls.__dict__:
|
|
72
|
+
# If the attribute is not defined, we add it
|
|
73
|
+
field_type = get_field_type(type(value))
|
|
74
|
+
cls.__annotations__[name] = field_type
|
|
75
|
+
cls.__attributes__.add(name)
|
|
76
|
+
else:
|
|
77
|
+
field_type = cls.__dict__[name].field_type
|
|
78
|
+
|
|
79
|
+
# Value is always wrapped in a BaseMappingField descriptor to handle
|
|
80
|
+
# getting and setting correctly in the instance
|
|
81
|
+
value = BaseMappingField(default=value, field_name=name, field_type=field_type)
|
|
82
|
+
return super().__setattr__(name, value)
|
|
83
|
+
|
|
84
|
+
def __delattr__(cls: 'BaseMapping', name: str) -> None:
|
|
85
|
+
"""
|
|
86
|
+
Delete attribute from the class and remove it from internal tracking.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
cls (BaseMapping): The class from which to delete the attribute.
|
|
90
|
+
name (str): The name of the attribute to delete.
|
|
91
|
+
"""
|
|
92
|
+
if name in cls.__annotations__:
|
|
93
|
+
del cls.__annotations__[name]
|
|
94
|
+
|
|
95
|
+
if name in cls.__attributes__:
|
|
96
|
+
cls.__attributes__.remove(name)
|
|
97
|
+
|
|
98
|
+
if name in cls.__dict__:
|
|
99
|
+
del cls.__dict__[name]
|
|
100
|
+
|
|
101
|
+
return super().__delattr__(name)
|