omlish 0.0.0.dev415__py3-none-any.whl → 0.0.0.dev417__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.
- omlish/__about__.py +2 -2
- omlish/bootstrap/__init__.py +2 -2
- omlish/dataclasses/__init__.py +28 -14
- omlish/dataclasses/impl/processing/base.py +1 -1
- omlish/lang/__init__.py +486 -473
- omlish/lang/imports/proxyinit.py +161 -48
- omlish/lang/maybes.py +8 -0
- omlish/marshal/__init__.py +224 -203
- omlish/marshal/base/configs.py +18 -0
- omlish/marshal/base/contexts.py +23 -19
- omlish/marshal/base/overrides.py +26 -12
- omlish/marshal/base/registries.py +66 -16
- omlish/marshal/base/types.py +60 -8
- omlish/marshal/factories/invalidate.py +118 -0
- omlish/marshal/factories/moduleimport/__init__.py +0 -0
- omlish/marshal/factories/moduleimport/configs.py +26 -0
- omlish/marshal/factories/moduleimport/factories.py +114 -0
- omlish/marshal/factories/typecache.py +24 -4
- omlish/marshal/globals.py +52 -27
- omlish/marshal/polymorphism/metadata.py +2 -2
- omlish/marshal/standard.py +132 -65
- omlish/reflect/__init__.py +57 -47
- omlish/reflect/types.py +144 -15
- omlish/secrets/all.py +0 -9
- omlish/secrets/secrets.py +4 -6
- omlish/specs/jsonrpc/__init__.py +2 -2
- omlish/specs/jsonschema/__init__.py +2 -2
- omlish/specs/openapi/__init__.py +2 -2
- omlish/sql/queries/__init__.py +4 -2
- omlish/sql/tabledefs/__init__.py +2 -2
- omlish/typedvalues/__init__.py +2 -2
- {omlish-0.0.0.dev415.dist-info → omlish-0.0.0.dev417.dist-info}/METADATA +14 -9
- {omlish-0.0.0.dev415.dist-info → omlish-0.0.0.dev417.dist-info}/RECORD +43 -37
- /omlish/bootstrap/{marshal.py → _marshal.py} +0 -0
- /omlish/specs/jsonrpc/{marshal.py → _marshal.py} +0 -0
- /omlish/specs/jsonschema/{marshal.py → _marshal.py} +0 -0
- /omlish/specs/openapi/{marshal.py → _marshal.py} +0 -0
- /omlish/sql/queries/{marshal.py → _marshal.py} +0 -0
- /omlish/sql/tabledefs/{marshal.py → _marshal.py} +0 -0
- {omlish-0.0.0.dev415.dist-info → omlish-0.0.0.dev417.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev415.dist-info → omlish-0.0.0.dev417.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev415.dist-info → omlish-0.0.0.dev417.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev415.dist-info → omlish-0.0.0.dev417.dist-info}/top_level.txt +0 -0
omlish/marshal/__init__.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# ruff: noqa: I001
|
1
2
|
"""
|
2
3
|
TODO:
|
3
4
|
- redacted
|
@@ -15,211 +16,231 @@ See:
|
|
15
16
|
- https://github.com/Fatal1ty/mashumaro
|
16
17
|
- https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#custom-serializers
|
17
18
|
"""
|
19
|
+
from .. import lang as _lang
|
18
20
|
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
)
|
67
|
-
|
68
|
-
from .
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
)
|
115
|
-
|
116
|
-
from .
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
22
|
+
with _lang.auto_proxy_init(globals()) as _api_cap:
|
23
|
+
##
|
24
|
+
|
25
|
+
from .base.configs import ( # noqa
|
26
|
+
Config,
|
27
|
+
ConfigRegistry,
|
28
|
+
)
|
29
|
+
|
30
|
+
from .base.contexts import ( # noqa
|
31
|
+
BaseContext,
|
32
|
+
MarshalContext,
|
33
|
+
UnmarshalContext,
|
34
|
+
)
|
35
|
+
|
36
|
+
from .base.errors import ( # noqa
|
37
|
+
ForbiddenTypeError,
|
38
|
+
MarshalError,
|
39
|
+
UnhandledTypeError,
|
40
|
+
)
|
41
|
+
|
42
|
+
from .base.options import ( # noqa
|
43
|
+
Option,
|
44
|
+
)
|
45
|
+
|
46
|
+
from .base.overrides import ( # noqa
|
47
|
+
Override,
|
48
|
+
ReflectOverride,
|
49
|
+
)
|
50
|
+
|
51
|
+
from .base.registries import ( # noqa
|
52
|
+
RegistrySealedError,
|
53
|
+
Registry,
|
54
|
+
)
|
55
|
+
|
56
|
+
from .base.types import ( # noqa
|
57
|
+
Marshaler,
|
58
|
+
Unmarshaler,
|
59
|
+
|
60
|
+
MarshalerMaker,
|
61
|
+
UnmarshalerMaker,
|
62
|
+
|
63
|
+
MarshalerFactory,
|
64
|
+
UnmarshalerFactory,
|
65
|
+
|
66
|
+
MarshalerFactory_,
|
67
|
+
UnmarshalerFactory_,
|
68
|
+
)
|
69
|
+
|
70
|
+
from .base.values import ( # noqa
|
71
|
+
Value,
|
72
|
+
)
|
73
|
+
|
74
|
+
from .composite.iterables import ( # noqa
|
75
|
+
IterableMarshaler,
|
76
|
+
IterableUnmarshaler,
|
77
|
+
)
|
78
|
+
|
79
|
+
from .composite.wrapped import ( # noqa
|
80
|
+
WrappedMarshaler,
|
81
|
+
WrappedUnmarshaler,
|
82
|
+
)
|
83
|
+
|
84
|
+
from .factories.simple import ( # noqa
|
85
|
+
SimpleMarshalerFactory,
|
86
|
+
SimpleUnmarshalerFactory,
|
87
|
+
)
|
88
|
+
|
89
|
+
from .factories.match import ( # noqa
|
90
|
+
MarshalerFactoryMatchClass,
|
91
|
+
UnmarshalerFactoryMatchClass,
|
92
|
+
)
|
93
|
+
|
94
|
+
from .factories.moduleimport.configs import ( # noqa
|
95
|
+
ModuleImport,
|
96
|
+
)
|
97
|
+
|
98
|
+
from .factories.moduleimport.factories import ( # noqa
|
99
|
+
ModuleImportingMarshalerFactory,
|
100
|
+
ModuleImportingUnmarshalerFactory,
|
101
|
+
)
|
102
|
+
|
103
|
+
from .factories.multi import ( # noqa
|
104
|
+
MultiMarshalerFactory,
|
105
|
+
MultiUnmarshalerFactory,
|
106
|
+
)
|
107
|
+
|
108
|
+
from .factories.typemap import ( # noqa
|
109
|
+
TypeMapMarshalerFactory,
|
110
|
+
TypeMapUnmarshalerFactory,
|
111
|
+
)
|
112
|
+
|
113
|
+
from .factories.typecache import ( # noqa
|
114
|
+
TypeCacheMarshalerFactory,
|
115
|
+
TypeCacheUnmarshalerFactory,
|
116
|
+
)
|
117
|
+
|
118
|
+
from .factories.func import ( # noqa
|
119
|
+
FuncMarshaler,
|
120
|
+
FuncUnmarshaler,
|
121
|
+
)
|
122
|
+
|
123
|
+
from .factories.recursive import ( # noqa
|
124
|
+
RecursiveMarshalerFactory,
|
125
|
+
RecursiveUnmarshalerFactory,
|
126
|
+
)
|
127
|
+
|
128
|
+
from .objects.dataclasses import ( # noqa
|
129
|
+
AbstractDataclassFactory,
|
130
|
+
DataclassMarshalerFactory,
|
131
|
+
DataclassUnmarshalerFactory,
|
132
|
+
get_dataclass_field_infos,
|
133
|
+
get_dataclass_metadata,
|
134
|
+
)
|
135
|
+
|
136
|
+
from .objects.helpers import ( # noqa
|
137
|
+
update_fields_metadata,
|
138
|
+
update_object_metadata,
|
139
|
+
with_field_metadata,
|
140
|
+
)
|
141
|
+
|
142
|
+
from .objects.marshal import ( # noqa
|
143
|
+
ObjectMarshaler,
|
144
|
+
SimpleObjectMarshalerFactory,
|
145
|
+
)
|
146
|
+
|
147
|
+
from .objects.metadata import ( # noqa
|
148
|
+
FieldInfo,
|
149
|
+
FieldInfos,
|
150
|
+
FieldMetadata,
|
151
|
+
FieldOptions,
|
152
|
+
ObjectMetadata,
|
153
|
+
ObjectSpecials,
|
154
|
+
)
|
155
|
+
|
156
|
+
from .objects.unmarshal import ( # noqa
|
157
|
+
ObjectUnmarshaler,
|
158
|
+
SimpleObjectUnmarshalerFactory,
|
159
|
+
)
|
160
|
+
|
161
|
+
from .polymorphism.marshal import ( # noqa
|
162
|
+
PolymorphismMarshaler,
|
163
|
+
PolymorphismMarshalerFactory,
|
164
|
+
make_polymorphism_marshaler,
|
165
|
+
)
|
166
|
+
|
167
|
+
from .polymorphism.metadata import ( # noqa
|
168
|
+
FieldTypeTagging,
|
169
|
+
Impl,
|
170
|
+
Impls,
|
171
|
+
Polymorphism,
|
172
|
+
TypeTagging,
|
173
|
+
WrapperTypeTagging,
|
174
|
+
polymorphism_from_impls,
|
175
|
+
polymorphism_from_subclasses,
|
176
|
+
)
|
177
|
+
|
178
|
+
from .polymorphism.standard import ( # noqa
|
179
|
+
standard_polymorphism_factories,
|
180
|
+
)
|
181
|
+
|
182
|
+
from .polymorphism.unions import ( # noqa
|
183
|
+
PRIMITIVE_UNION_TYPES,
|
184
|
+
PolymorphismUnionMarshalerFactory,
|
185
|
+
PolymorphismUnionUnmarshalerFactory,
|
186
|
+
PrimitiveUnionMarshaler,
|
187
|
+
PrimitiveUnionMarshalerFactory,
|
188
|
+
PrimitiveUnionUnmarshaler,
|
189
|
+
PrimitiveUnionUnmarshalerFactory,
|
190
|
+
)
|
191
|
+
|
192
|
+
from .polymorphism.unmarshal import ( # noqa
|
193
|
+
PolymorphismUnmarshaler,
|
194
|
+
PolymorphismUnmarshalerFactory,
|
195
|
+
make_polymorphism_unmarshaler,
|
196
|
+
)
|
197
|
+
|
198
|
+
from .singular.base64 import ( # noqa
|
199
|
+
BASE64_MARSHALER_FACTORY,
|
200
|
+
BASE64_UNMARSHALER_FACTORY,
|
201
|
+
)
|
202
|
+
|
203
|
+
from .singular.primitives import ( # noqa
|
204
|
+
PRIMITIVE_TYPES,
|
205
|
+
)
|
206
|
+
|
207
|
+
from .trivial.forbidden import ( # noqa
|
208
|
+
ForbiddenTypeMarshalerFactory,
|
209
|
+
ForbiddenTypeUnmarshalerFactory,
|
210
|
+
)
|
211
|
+
|
212
|
+
from .trivial.nop import ( # noqa
|
213
|
+
NOP_MARSHALER_UNMARSHALER,
|
214
|
+
NopMarshalerUnmarshaler,
|
215
|
+
)
|
216
|
+
|
217
|
+
from .globals import ( # noqa
|
218
|
+
global_config_registry,
|
219
|
+
global_marshaler_factory,
|
220
|
+
global_unmarshaler_factory,
|
221
|
+
global_marshaling,
|
222
|
+
|
223
|
+
marshal,
|
224
|
+
unmarshal,
|
225
|
+
|
226
|
+
register_global_config,
|
227
|
+
register_global_module_import,
|
228
|
+
)
|
229
|
+
|
230
|
+
from .naming import ( # noqa
|
231
|
+
Naming,
|
232
|
+
translate_name,
|
233
|
+
)
|
234
|
+
|
235
|
+
from .standard import ( # noqa
|
236
|
+
StandardFactories,
|
237
|
+
DEFAULT_STANDARD_FACTORIES,
|
238
|
+
|
239
|
+
new_standard_marshaler_factory,
|
240
|
+
new_standard_unmarshaler_factory,
|
241
|
+
|
242
|
+
install_standard_factories,
|
243
|
+
)
|
223
244
|
|
224
245
|
|
225
246
|
##
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import typing as ta
|
2
|
+
|
3
|
+
from ... import lang
|
4
|
+
from .registries import Registry
|
5
|
+
from .registries import RegistryItem
|
6
|
+
|
7
|
+
|
8
|
+
##
|
9
|
+
|
10
|
+
|
11
|
+
class Config(RegistryItem, lang.Abstract):
|
12
|
+
pass
|
13
|
+
|
14
|
+
|
15
|
+
ConfigRegistry: ta.TypeAlias = Registry[Config]
|
16
|
+
|
17
|
+
|
18
|
+
EMPTY_CONFIG_REGISTRY = ConfigRegistry().seal()
|
omlish/marshal/base/contexts.py
CHANGED
@@ -1,20 +1,24 @@
|
|
1
|
+
import dataclasses as dc
|
1
2
|
import typing as ta
|
2
3
|
|
3
4
|
from ... import check
|
4
5
|
from ... import collections as col
|
5
|
-
from ... import dataclasses as dc
|
6
6
|
from ... import lang
|
7
7
|
from ... import reflect as rfl
|
8
8
|
from ...funcs import match as mfs
|
9
|
+
from .configs import EMPTY_CONFIG_REGISTRY
|
10
|
+
from .configs import ConfigRegistry
|
9
11
|
from .errors import UnhandledTypeError
|
10
12
|
from .options import Option
|
11
13
|
from .overrides import ReflectOverride
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
from .types import
|
16
|
-
from .types import
|
17
|
-
from .
|
14
|
+
|
15
|
+
|
16
|
+
if ta.TYPE_CHECKING:
|
17
|
+
from .types import Marshaler
|
18
|
+
from .types import MarshalerFactory
|
19
|
+
from .types import Unmarshaler
|
20
|
+
from .types import UnmarshalerFactory
|
21
|
+
from .values import Value
|
18
22
|
|
19
23
|
|
20
24
|
T = ta.TypeVar('T')
|
@@ -23,40 +27,40 @@ T = ta.TypeVar('T')
|
|
23
27
|
##
|
24
28
|
|
25
29
|
|
26
|
-
@dc.dataclass(frozen=True)
|
30
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
27
31
|
class BaseContext(lang.Abstract):
|
28
|
-
|
32
|
+
config_registry: ConfigRegistry = EMPTY_CONFIG_REGISTRY
|
29
33
|
options: col.TypeMap[Option] = col.TypeMap()
|
30
34
|
|
31
35
|
def _reflect(self, o: ta.Any) -> rfl.Type:
|
32
36
|
def override(o):
|
33
|
-
if (ovr := self.
|
37
|
+
if (ovr := self.config_registry.get_of(o, ReflectOverride)):
|
34
38
|
return ovr[-1].rty
|
35
39
|
return None
|
36
40
|
|
37
41
|
return rfl.Reflector(override=override).type(o)
|
38
42
|
|
39
43
|
|
40
|
-
@dc.dataclass(frozen=True)
|
44
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
41
45
|
class MarshalContext(BaseContext, lang.Final):
|
42
|
-
factory: MarshalerFactory
|
46
|
+
factory: ta.Optional['MarshalerFactory'] = None
|
43
47
|
|
44
|
-
def make(self, o: ta.Any) -> Marshaler:
|
48
|
+
def make(self, o: ta.Any) -> 'Marshaler':
|
45
49
|
rty = self._reflect(o)
|
46
50
|
try:
|
47
51
|
return check.not_none(self.factory).make_marshaler(self, rty)
|
48
52
|
except mfs.MatchGuardError:
|
49
53
|
raise UnhandledTypeError(rty) # noqa
|
50
54
|
|
51
|
-
def marshal(self, obj: ta.Any, ty: ta.Any | None = None) -> Value:
|
55
|
+
def marshal(self, obj: ta.Any, ty: ta.Any | None = None) -> 'Value':
|
52
56
|
return self.make(ty if ty is not None else type(obj)).marshal(self, obj)
|
53
57
|
|
54
58
|
|
55
|
-
@dc.dataclass(frozen=True)
|
59
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
56
60
|
class UnmarshalContext(BaseContext, lang.Final):
|
57
|
-
factory: UnmarshalerFactory
|
61
|
+
factory: ta.Optional['UnmarshalerFactory'] = None
|
58
62
|
|
59
|
-
def make(self, o: ta.Any) -> Unmarshaler:
|
63
|
+
def make(self, o: ta.Any) -> 'Unmarshaler':
|
60
64
|
rty = self._reflect(o)
|
61
65
|
try:
|
62
66
|
return check.not_none(self.factory).make_unmarshaler(self, rty)
|
@@ -64,11 +68,11 @@ class UnmarshalContext(BaseContext, lang.Final):
|
|
64
68
|
raise UnhandledTypeError(rty) # noqa
|
65
69
|
|
66
70
|
@ta.overload
|
67
|
-
def unmarshal(self, v: Value, ty: type[T]) -> T:
|
71
|
+
def unmarshal(self, v: 'Value', ty: type[T]) -> T:
|
68
72
|
...
|
69
73
|
|
70
74
|
@ta.overload
|
71
|
-
def unmarshal(self, v: Value, ty: ta.Any) -> ta.Any:
|
75
|
+
def unmarshal(self, v: 'Value', ty: ta.Any) -> ta.Any:
|
72
76
|
...
|
73
77
|
|
74
78
|
def unmarshal(self, v, ty):
|
omlish/marshal/base/overrides.py
CHANGED
@@ -1,25 +1,39 @@
|
|
1
|
-
|
1
|
+
import dataclasses as dc
|
2
|
+
import typing as ta
|
3
|
+
|
4
|
+
from ... import check
|
2
5
|
from ... import lang
|
3
6
|
from ... import reflect as rfl
|
4
|
-
from .
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
from .
|
7
|
+
from .configs import Config
|
8
|
+
|
9
|
+
|
10
|
+
if ta.TYPE_CHECKING:
|
11
|
+
from . import types as _types
|
12
|
+
from .types import Marshaler
|
13
|
+
from .types import MarshalerFactory
|
14
|
+
from .types import Unmarshaler
|
15
|
+
from .types import UnmarshalerFactory
|
16
|
+
|
17
|
+
else:
|
18
|
+
_types = lang.proxy_import('.types', __package__)
|
9
19
|
|
10
20
|
|
11
21
|
##
|
12
22
|
|
13
23
|
|
14
24
|
@dc.dataclass(frozen=True, kw_only=True)
|
15
|
-
class Override(
|
16
|
-
marshaler: Marshaler
|
17
|
-
marshaler_factory: MarshalerFactory
|
25
|
+
class Override(Config, lang.Final):
|
26
|
+
marshaler: ta.Optional['Marshaler'] = None
|
27
|
+
marshaler_factory: ta.Optional['MarshalerFactory'] = None
|
28
|
+
|
29
|
+
unmarshaler: ta.Optional['Unmarshaler'] = None
|
30
|
+
unmarshaler_factory: ta.Optional['UnmarshalerFactory'] = None
|
18
31
|
|
19
|
-
|
20
|
-
|
32
|
+
def __post_init__(self) -> None:
|
33
|
+
check.isinstance(self.marshaler, (_types.Marshaler, None))
|
34
|
+
check.isinstance(self.unmarshaler, (_types.Unmarshaler, None))
|
21
35
|
|
22
36
|
|
23
37
|
@dc.dataclass(frozen=True)
|
24
|
-
class ReflectOverride(
|
38
|
+
class ReflectOverride(Config, lang.Final):
|
25
39
|
rty: rfl.Type
|