aspyx 1.7.0__py3-none-any.whl → 1.8.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.
Potentially problematic release.
This version of aspyx might be problematic. Click here for more details.
- aspyx/di/di.py +1 -1
- aspyx/reflection/__init__.py +3 -2
- aspyx/reflection/reflection.py +21 -0
- aspyx/util/copy_on_write_cache.py +3 -0
- aspyx/util/serialization.py +41 -12
- {aspyx-1.7.0.dist-info → aspyx-1.8.0.dist-info}/METADATA +1 -1
- {aspyx-1.7.0.dist-info → aspyx-1.8.0.dist-info}/RECORD +9 -9
- {aspyx-1.7.0.dist-info → aspyx-1.8.0.dist-info}/WHEEL +0 -0
- {aspyx-1.7.0.dist-info → aspyx-1.8.0.dist-info}/licenses/LICENSE +0 -0
aspyx/di/di.py
CHANGED
|
@@ -975,7 +975,7 @@ class Environment:
|
|
|
975
975
|
"""
|
|
976
976
|
|
|
977
977
|
def add_provider(type: Type, provider: AbstractInstanceProvider):
|
|
978
|
-
Environment.logger.
|
|
978
|
+
Environment.logger.debug("\tadd provider %s for %s", provider, type)
|
|
979
979
|
|
|
980
980
|
self.providers[type] = provider
|
|
981
981
|
|
aspyx/reflection/__init__.py
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
This module provides tools for dynamic proxy creation and reflection
|
|
3
3
|
"""
|
|
4
4
|
from .proxy import DynamicProxy
|
|
5
|
-
from .reflection import Decorators, TypeDescriptor, DecoratorDescriptor
|
|
5
|
+
from .reflection import Decorators, TypeDescriptor, DecoratorDescriptor, get_method_class
|
|
6
6
|
|
|
7
7
|
__all__ = [
|
|
8
8
|
"DynamicProxy",
|
|
9
9
|
"Decorators",
|
|
10
10
|
"DecoratorDescriptor",
|
|
11
|
-
"TypeDescriptor"
|
|
11
|
+
"TypeDescriptor",
|
|
12
|
+
"get_method_class"
|
|
12
13
|
]
|
aspyx/reflection/reflection.py
CHANGED
|
@@ -12,6 +12,27 @@ from types import FunctionType
|
|
|
12
12
|
from typing import Callable, get_type_hints, Type, Dict, Optional
|
|
13
13
|
from weakref import WeakKeyDictionary
|
|
14
14
|
|
|
15
|
+
def get_method_class(method):
|
|
16
|
+
"""
|
|
17
|
+
return the class of the specified method
|
|
18
|
+
Args:
|
|
19
|
+
method: the method
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
the class of the specified method
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
if inspect.ismethod(method) or inspect.isfunction(method):
|
|
26
|
+
qualname = method.__qualname__
|
|
27
|
+
module = inspect.getmodule(method)
|
|
28
|
+
if module:
|
|
29
|
+
cls_name = qualname.split('.<locals>', 1)[0].rsplit('.', 1)[0]
|
|
30
|
+
cls = getattr(module, cls_name, None)
|
|
31
|
+
if inspect.isclass(cls):
|
|
32
|
+
return cls
|
|
33
|
+
|
|
34
|
+
return None
|
|
35
|
+
|
|
15
36
|
|
|
16
37
|
class DecoratorDescriptor:
|
|
17
38
|
"""
|
|
@@ -4,6 +4,9 @@ K = TypeVar("K")
|
|
|
4
4
|
V = TypeVar("V")
|
|
5
5
|
|
|
6
6
|
class CopyOnWriteCache(Generic[K, V]):
|
|
7
|
+
"""
|
|
8
|
+
cache, that clones the existing dict, whenever a new item is added, avoiding any locks
|
|
9
|
+
"""
|
|
7
10
|
# constructor
|
|
8
11
|
|
|
9
12
|
def __init__(self, factory: Optional[Callable[[K], V]] = None) -> None:
|
aspyx/util/serialization.py
CHANGED
|
@@ -24,7 +24,9 @@ class TypeDeserializer:
|
|
|
24
24
|
args = get_args(typ)
|
|
25
25
|
|
|
26
26
|
if origin is Union:
|
|
27
|
-
|
|
27
|
+
# Optional[X] => Union[X, NoneType]
|
|
28
|
+
deserializers = [self._build_deserializer(arg) for arg in args if arg is not type(None)]
|
|
29
|
+
|
|
28
30
|
def deser_union(value):
|
|
29
31
|
if value is None:
|
|
30
32
|
return None
|
|
@@ -33,34 +35,61 @@ class TypeDeserializer:
|
|
|
33
35
|
return d(value)
|
|
34
36
|
except Exception:
|
|
35
37
|
continue
|
|
36
|
-
|
|
38
|
+
raise ValueError(f"Cannot deserialize value: {value!r} into Union[{args}]")
|
|
39
|
+
|
|
37
40
|
return deser_union
|
|
38
41
|
|
|
39
42
|
if isinstance(typ, type) and issubclass(typ, BaseModel):
|
|
40
|
-
|
|
43
|
+
field_deserializers = {
|
|
44
|
+
name: self._build_deserializer(field.annotation)
|
|
45
|
+
for name, field in typ.model_fields.items()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
def deser_model(value):
|
|
49
|
+
if isinstance(value, typ):
|
|
50
|
+
return value
|
|
51
|
+
if not isinstance(value, dict):
|
|
52
|
+
raise TypeError(f"Expected dict to construct {typ.__name__}, got {type(value).__name__}")
|
|
53
|
+
kwargs = {
|
|
54
|
+
k: field_deserializers[k](v)
|
|
55
|
+
for k, v in value.items()
|
|
56
|
+
if k in field_deserializers
|
|
57
|
+
}
|
|
58
|
+
return typ.model_construct(**kwargs)
|
|
59
|
+
|
|
60
|
+
return deser_model
|
|
41
61
|
|
|
42
62
|
if is_dataclass(typ):
|
|
43
|
-
field_deserializers = {
|
|
63
|
+
field_deserializers = {
|
|
64
|
+
f.name: self._build_deserializer(f.type) for f in fields(typ)
|
|
65
|
+
}
|
|
66
|
+
|
|
44
67
|
def deser_dataclass(value):
|
|
45
|
-
if
|
|
68
|
+
if isinstance(value, typ):
|
|
46
69
|
return value
|
|
47
|
-
|
|
70
|
+
if not isinstance(value, dict):
|
|
71
|
+
raise TypeError(f"Expected dict to construct {typ}, got {type(value).__name__}")
|
|
48
72
|
return typ(**{
|
|
49
|
-
k: field_deserializers[k](v) for k, v in value.items()
|
|
73
|
+
k: field_deserializers[k](v) for k, v in value.items() if k in field_deserializers
|
|
50
74
|
})
|
|
75
|
+
|
|
51
76
|
return deser_dataclass
|
|
52
77
|
|
|
53
78
|
if origin is list:
|
|
54
|
-
|
|
79
|
+
item_type = args[0] if args else Any
|
|
80
|
+
item_deser = self._build_deserializer(item_type)
|
|
55
81
|
return lambda v: [item_deser(item) for item in v]
|
|
56
82
|
|
|
57
83
|
if origin is dict:
|
|
58
|
-
|
|
59
|
-
|
|
84
|
+
key_type = args[0] if args else Any
|
|
85
|
+
val_type = args[1] if len(args) > 1 else Any
|
|
86
|
+
key_deser = self._build_deserializer(key_type)
|
|
87
|
+
val_deser = self._build_deserializer(val_type)
|
|
60
88
|
return lambda v: {key_deser(k): val_deser(val) for k, val in v.items()}
|
|
61
89
|
|
|
62
|
-
# Fallback
|
|
63
|
-
return lambda v: v
|
|
90
|
+
# Fallback: primitive types, str, int, etc.
|
|
91
|
+
return lambda v: typ(v) if callable(typ) else v
|
|
92
|
+
|
|
64
93
|
|
|
65
94
|
class TypeSerializer:
|
|
66
95
|
def __init__(self, typ):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
aspyx/__init__.py,sha256=MsSFjiLMLJZ7QhUPpVBWKiyDnCzryquRyr329NoCACI,2
|
|
2
2
|
aspyx/di/__init__.py,sha256=AGVU2VBWQyBxSssvbk_GOKrYWIYtcmSoIlupz-Oqxi4,1138
|
|
3
|
-
aspyx/di/di.py,sha256=
|
|
3
|
+
aspyx/di/di.py,sha256=UX07kwGQMIcIn2UOPeCcSPuh4sFmK48150EWFaKXVl8,44822
|
|
4
4
|
aspyx/di/aop/__init__.py,sha256=rn6LSpzFtUOlgaBATyhLRWBzFmZ6XoVKA9B8SgQzYEI,746
|
|
5
5
|
aspyx/di/aop/aop.py,sha256=y300DG713Gcn97CdTKuBdFL2jaS5ouW6J0azZk0Byws,19181
|
|
6
6
|
aspyx/di/configuration/__init__.py,sha256=flM9A79J2wfA5I8goQbxs4tTqYustR9tn_9s0YO2WJQ,484
|
|
@@ -11,18 +11,18 @@ aspyx/di/threading/__init__.py,sha256=qrWdaq7MewQ2UmZy4J0Dn6BhY-ahfiG3xsv-EHqoqS
|
|
|
11
11
|
aspyx/di/threading/synchronized.py,sha256=6JOg5BXWrRIS5nRPH9iWR7T-kUglO4qWBQpLwhy99pI,1325
|
|
12
12
|
aspyx/exception/__init__.py,sha256=HfK0kk1Tcw9QaUYgIyMeBFDAIE83pkTrIGYUnoKJXPE,231
|
|
13
13
|
aspyx/exception/exception_manager.py,sha256=wTxLjSVZ_vYfeo06PKZZS9hbrv_dRCwQotSwowUHLZY,5475
|
|
14
|
-
aspyx/reflection/__init__.py,sha256=
|
|
14
|
+
aspyx/reflection/__init__.py,sha256=GDd0tE94WaKd0hwBM8H1NdRihEYefK-xb97zzCgF088,324
|
|
15
15
|
aspyx/reflection/proxy.py,sha256=1-pgw-TNORFXbV0gowFZqGd-bcWv1ny69bJhq8TLsKs,2761
|
|
16
|
-
aspyx/reflection/reflection.py,sha256=
|
|
16
|
+
aspyx/reflection/reflection.py,sha256=mimTxXmvblB_iQ5dk_Bnb-bKUGRXCNe1zO-nc59oNDw,10015
|
|
17
17
|
aspyx/threading/__init__.py,sha256=YWqLk-MOtSg4i3cdzRZUBR25okbbftRRxkaEdfrdMZo,207
|
|
18
18
|
aspyx/threading/context_local.py,sha256=2I-942IHbR0jCrM1N6Mo56VJwuNWMs2f3R8NJsHygBI,1270
|
|
19
19
|
aspyx/threading/thread_local.py,sha256=86dNtbA4k2B-rNUUnZgn3_pU0DAojgLrRnh8RL6zf1E,1196
|
|
20
20
|
aspyx/util/__init__.py,sha256=fiivk3IpXfErFbcVZ1VHDkYQHzSmOysNtKVE9kZFbvU,427
|
|
21
|
-
aspyx/util/copy_on_write_cache.py,sha256=
|
|
21
|
+
aspyx/util/copy_on_write_cache.py,sha256=nJPo9rzNLhRe7kzmiV-3Enx95YFaDzAyWHlppepob_o,1106
|
|
22
22
|
aspyx/util/logger.py,sha256=Hti5JyajdPXlf_1jvVT3e6Gf9eLyAsIVJRdNBMahbJs,608
|
|
23
|
-
aspyx/util/serialization.py,sha256=
|
|
23
|
+
aspyx/util/serialization.py,sha256=Yc7oMeYc6Zupwppzp0SI3GNDd9QTFIlLQg3OjJ3h3TY,5434
|
|
24
24
|
aspyx/util/stringbuilder.py,sha256=a-0T4YEXSJFUuQ3ztKN1ZPARkh8dIGMSkNEEJHRN7dc,856
|
|
25
|
-
aspyx-1.
|
|
26
|
-
aspyx-1.
|
|
27
|
-
aspyx-1.
|
|
28
|
-
aspyx-1.
|
|
25
|
+
aspyx-1.8.0.dist-info/METADATA,sha256=SXqZA_ebcwJbggWNiYfmk3vgLQs3VyWN7-IPMAmehlA,26017
|
|
26
|
+
aspyx-1.8.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
27
|
+
aspyx-1.8.0.dist-info/licenses/LICENSE,sha256=n4jfx_MNj7cBtPhhI7MCoB_K35cj1icP9yJ4Rh4vlvY,1070
|
|
28
|
+
aspyx-1.8.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|