omlish 0.0.0.dev416__py3-none-any.whl → 0.0.0.dev418__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 +23 -13
- omlish/dataclasses/impl/configs.py +1 -1
- omlish/dataclasses/impl/processing/base.py +1 -1
- omlish/inject/__init__.py +12 -0
- omlish/marshal/__init__.py +229 -202
- omlish/marshal/base/configs.py +18 -0
- omlish/marshal/base/contexts.py +8 -7
- omlish/marshal/base/funcs.py +57 -0
- omlish/marshal/base/overrides.py +11 -6
- omlish/marshal/base/registries.py +58 -14
- omlish/marshal/base/types.py +4 -26
- 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 +28 -13
- omlish/marshal/objects/dataclasses.py +29 -4
- omlish/marshal/polymorphism/metadata.py +2 -2
- omlish/marshal/standard.py +132 -65
- 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/text/templating.py +9 -7
- omlish/typedvalues/__init__.py +41 -34
- {omlish-0.0.0.dev416.dist-info → omlish-0.0.0.dev418.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev416.dist-info → omlish-0.0.0.dev418.dist-info}/RECORD +43 -38
- omlish/marshal/factories/func.py +0 -28
- /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.dev416.dist-info → omlish-0.0.0.dev418.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev416.dist-info → omlish-0.0.0.dev418.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev416.dist-info → omlish-0.0.0.dev418.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev416.dist-info → omlish-0.0.0.dev418.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
omlish/bootstrap/__init__.py
CHANGED
omlish/dataclasses/__init__.py
CHANGED
@@ -31,18 +31,6 @@ with _lang.auto_proxy_init(globals()) as _api_cap:
|
|
31
31
|
replace,
|
32
32
|
)
|
33
33
|
|
34
|
-
from .impl.api import ( # noqa
|
35
|
-
dataclass as xdataclass,
|
36
|
-
|
37
|
-
make_dataclass as xmake_dataclass,
|
38
|
-
|
39
|
-
field as xfield,
|
40
|
-
)
|
41
|
-
|
42
|
-
from .impl.concerns.replace import ( # noqa
|
43
|
-
replace as xreplace,
|
44
|
-
)
|
45
|
-
|
46
34
|
from .tools.as_ import ( # noqa
|
47
35
|
asdict,
|
48
36
|
astuple,
|
@@ -51,19 +39,41 @@ with _lang.auto_proxy_init(globals()) as _api_cap:
|
|
51
39
|
##
|
52
40
|
# additional interface
|
53
41
|
|
54
|
-
from .impl.api import ( # noqa
|
42
|
+
from .impl.api.classes.decorator import ( # noqa
|
43
|
+
dataclass as xdataclass,
|
44
|
+
)
|
45
|
+
|
46
|
+
from .impl.api.classes.make import ( # noqa
|
47
|
+
make_dataclass as xmake_dataclass,
|
48
|
+
)
|
49
|
+
|
50
|
+
from .impl.api.classes.metadata import ( # noqa
|
55
51
|
append_class_metadata,
|
56
52
|
extra_class_params,
|
57
53
|
init,
|
58
54
|
metadata,
|
59
55
|
validate,
|
56
|
+
)
|
60
57
|
|
58
|
+
from .impl.api.fields.metadata import ( # noqa
|
61
59
|
extra_field_params,
|
62
60
|
set_field_metadata,
|
63
61
|
update_extra_field_params,
|
64
62
|
with_extra_field_params,
|
65
63
|
)
|
66
64
|
|
65
|
+
from .impl.api.fields.constructor import ( # noqa
|
66
|
+
field as xfield,
|
67
|
+
)
|
68
|
+
|
69
|
+
from .impl.concerns.replace import ( # noqa
|
70
|
+
replace as xreplace,
|
71
|
+
)
|
72
|
+
|
73
|
+
from .impl.configs import ( # noqa
|
74
|
+
init_package,
|
75
|
+
)
|
76
|
+
|
67
77
|
from .errors import ( # noqa
|
68
78
|
FieldFnValidationError,
|
69
79
|
FieldTypeValidationError,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
2
|
TODO:
|
3
|
-
- Configurable? class Config
|
3
|
+
- Configurable? class Config crtp?
|
4
4
|
- all config on specs? prob not desirable purity, prob want ~some~ global config if only defaults
|
5
5
|
- ProcessorConfigSpecProviderFactoryThingy?
|
6
6
|
- FIXME: for now these are processor ctor kwargs that are never overridden
|
omlish/inject/__init__.py
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
"""
|
2
2
|
~> https://github.com/google/guice/commit/70248eafa90cd70a68b293763e53f6aec656e73c
|
3
3
|
"""
|
4
|
+
from .. import dataclasses as _dc
|
5
|
+
|
6
|
+
|
7
|
+
_dc.init_package(
|
8
|
+
globals(),
|
9
|
+
codegen=True,
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
##
|
14
|
+
|
15
|
+
|
4
16
|
from .binder import ( # noqa
|
5
17
|
bind,
|
6
18
|
bind_as_fn,
|
omlish/marshal/__init__.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# ruff: noqa: I001
|
1
2
|
"""
|
2
3
|
TODO:
|
3
4
|
- redacted
|
@@ -15,216 +16,242 @@ 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 dataclasses as _dc # noqa
|
18
20
|
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
UnmarshalContext,
|
22
|
+
_dc.init_package(
|
23
|
+
globals(),
|
24
|
+
codegen=True,
|
24
25
|
)
|
25
26
|
|
26
|
-
from .base.errors import ( # noqa
|
27
|
-
ForbiddenTypeError,
|
28
|
-
MarshalError,
|
29
|
-
UnhandledTypeError,
|
30
|
-
)
|
31
|
-
|
32
|
-
from .base.options import ( # noqa
|
33
|
-
Option,
|
34
|
-
)
|
35
|
-
|
36
|
-
from .base.overrides import ( # noqa
|
37
|
-
Override,
|
38
|
-
ReflectOverride,
|
39
|
-
)
|
40
|
-
|
41
|
-
from .base.registries import ( # noqa
|
42
|
-
Registry,
|
43
|
-
)
|
44
|
-
|
45
|
-
from .base.types import ( # noqa
|
46
|
-
Marshaler,
|
47
|
-
Unmarshaler,
|
48
|
-
|
49
|
-
MarshalerMaker,
|
50
|
-
UnmarshalerMaker,
|
51
|
-
|
52
|
-
MarshalerFactory,
|
53
|
-
UnmarshalerFactory,
|
54
|
-
|
55
|
-
MarshalerFactory_,
|
56
|
-
UnmarshalerFactory_,
|
57
|
-
)
|
58
|
-
|
59
|
-
from .base.values import ( # noqa
|
60
|
-
Value,
|
61
|
-
)
|
62
|
-
|
63
|
-
from .composite.iterables import ( # noqa
|
64
|
-
IterableMarshaler,
|
65
|
-
IterableUnmarshaler,
|
66
|
-
)
|
67
|
-
|
68
|
-
from .composite.wrapped import ( # noqa
|
69
|
-
WrappedMarshaler,
|
70
|
-
WrappedUnmarshaler,
|
71
|
-
)
|
72
|
-
|
73
|
-
from .factories.simple import ( # noqa
|
74
|
-
SimpleMarshalerFactory,
|
75
|
-
SimpleUnmarshalerFactory,
|
76
|
-
)
|
77
|
-
|
78
|
-
from .factories.match import ( # noqa
|
79
|
-
MarshalerFactoryMatchClass,
|
80
|
-
UnmarshalerFactoryMatchClass,
|
81
|
-
)
|
82
|
-
|
83
|
-
from .factories.multi import ( # noqa
|
84
|
-
MultiMarshalerFactory,
|
85
|
-
MultiUnmarshalerFactory,
|
86
|
-
)
|
87
|
-
|
88
|
-
from .factories.typemap import ( # noqa
|
89
|
-
TypeMapMarshalerFactory,
|
90
|
-
TypeMapUnmarshalerFactory,
|
91
|
-
)
|
92
|
-
|
93
|
-
from .factories.typecache import ( # noqa
|
94
|
-
TypeCacheMarshalerFactory,
|
95
|
-
TypeCacheUnmarshalerFactory,
|
96
|
-
)
|
97
|
-
|
98
|
-
from .factories.func import ( # noqa
|
99
|
-
FuncMarshaler,
|
100
|
-
FuncUnmarshaler,
|
101
|
-
)
|
102
|
-
|
103
|
-
from .factories.recursive import ( # noqa
|
104
|
-
RecursiveMarshalerFactory,
|
105
|
-
RecursiveUnmarshalerFactory,
|
106
|
-
)
|
107
|
-
|
108
|
-
from .objects.dataclasses import ( # noqa
|
109
|
-
AbstractDataclassFactory,
|
110
|
-
DataclassMarshalerFactory,
|
111
|
-
DataclassUnmarshalerFactory,
|
112
|
-
get_dataclass_field_infos,
|
113
|
-
get_dataclass_metadata,
|
114
|
-
)
|
115
|
-
|
116
|
-
from .objects.helpers import ( # noqa
|
117
|
-
update_fields_metadata,
|
118
|
-
update_object_metadata,
|
119
|
-
with_field_metadata,
|
120
|
-
)
|
121
|
-
|
122
|
-
from .objects.marshal import ( # noqa
|
123
|
-
ObjectMarshaler,
|
124
|
-
SimpleObjectMarshalerFactory,
|
125
|
-
)
|
126
|
-
|
127
|
-
from .objects.metadata import ( # noqa
|
128
|
-
FieldInfo,
|
129
|
-
FieldInfos,
|
130
|
-
FieldMetadata,
|
131
|
-
FieldOptions,
|
132
|
-
ObjectMetadata,
|
133
|
-
ObjectSpecials,
|
134
|
-
)
|
135
|
-
|
136
|
-
from .objects.unmarshal import ( # noqa
|
137
|
-
ObjectUnmarshaler,
|
138
|
-
SimpleObjectUnmarshalerFactory,
|
139
|
-
)
|
140
|
-
|
141
|
-
from .polymorphism.marshal import ( # noqa
|
142
|
-
PolymorphismMarshaler,
|
143
|
-
PolymorphismMarshalerFactory,
|
144
|
-
make_polymorphism_marshaler,
|
145
|
-
)
|
146
27
|
|
147
|
-
|
148
|
-
FieldTypeTagging,
|
149
|
-
Impl,
|
150
|
-
Impls,
|
151
|
-
Polymorphism,
|
152
|
-
TypeTagging,
|
153
|
-
WrapperTypeTagging,
|
154
|
-
polymorphism_from_impls,
|
155
|
-
polymorphism_from_subclasses,
|
156
|
-
)
|
157
|
-
|
158
|
-
from .polymorphism.standard import ( # noqa
|
159
|
-
standard_polymorphism_factories,
|
160
|
-
)
|
161
|
-
|
162
|
-
from .polymorphism.unions import ( # noqa
|
163
|
-
PRIMITIVE_UNION_TYPES,
|
164
|
-
PolymorphismUnionMarshalerFactory,
|
165
|
-
PolymorphismUnionUnmarshalerFactory,
|
166
|
-
PrimitiveUnionMarshaler,
|
167
|
-
PrimitiveUnionMarshalerFactory,
|
168
|
-
PrimitiveUnionUnmarshaler,
|
169
|
-
PrimitiveUnionUnmarshalerFactory,
|
170
|
-
)
|
171
|
-
|
172
|
-
from .polymorphism.unmarshal import ( # noqa
|
173
|
-
PolymorphismUnmarshaler,
|
174
|
-
PolymorphismUnmarshalerFactory,
|
175
|
-
make_polymorphism_unmarshaler,
|
176
|
-
)
|
177
|
-
|
178
|
-
from .singular.base64 import ( # noqa
|
179
|
-
BASE64_MARSHALER_FACTORY,
|
180
|
-
BASE64_UNMARSHALER_FACTORY,
|
181
|
-
)
|
182
|
-
|
183
|
-
from .singular.primitives import ( # noqa
|
184
|
-
PRIMITIVE_TYPES,
|
185
|
-
)
|
186
|
-
|
187
|
-
from .trivial.forbidden import ( # noqa
|
188
|
-
ForbiddenTypeMarshalerFactory,
|
189
|
-
ForbiddenTypeUnmarshalerFactory,
|
190
|
-
)
|
191
|
-
|
192
|
-
from .trivial.nop import ( # noqa
|
193
|
-
NOP_MARSHALER_UNMARSHALER,
|
194
|
-
NopMarshalerUnmarshaler,
|
195
|
-
)
|
196
|
-
|
197
|
-
from .globals import ( # noqa
|
198
|
-
global_registry,
|
199
|
-
global_marshaler_factory,
|
200
|
-
global_unmarshaler_factory,
|
201
|
-
global_marshaling,
|
202
|
-
|
203
|
-
marshal,
|
204
|
-
unmarshal,
|
205
|
-
|
206
|
-
register_global,
|
207
|
-
)
|
208
|
-
|
209
|
-
from .naming import ( # noqa
|
210
|
-
Naming,
|
211
|
-
translate_name,
|
212
|
-
)
|
213
|
-
|
214
|
-
from .standard import ( # noqa
|
215
|
-
STANDARD_MARSHALER_FACTORIES,
|
216
|
-
new_standard_marshaler_factory,
|
217
|
-
|
218
|
-
STANDARD_UNMARSHALER_FACTORIES,
|
219
|
-
new_standard_unmarshaler_factory,
|
28
|
+
##
|
220
29
|
|
221
|
-
install_standard_factories,
|
222
|
-
)
|
223
30
|
|
31
|
+
from .. import lang as _lang # noqa
|
224
32
|
|
225
|
-
##
|
226
33
|
|
34
|
+
with _lang.auto_proxy_init(globals()) as _api_cap:
|
35
|
+
##
|
227
36
|
|
228
|
-
from
|
37
|
+
from .base.configs import ( # noqa
|
38
|
+
Config,
|
39
|
+
ConfigRegistry,
|
40
|
+
)
|
229
41
|
|
230
|
-
|
42
|
+
from .base.contexts import ( # noqa
|
43
|
+
BaseContext,
|
44
|
+
MarshalContext,
|
45
|
+
UnmarshalContext,
|
46
|
+
)
|
47
|
+
|
48
|
+
from .base.errors import ( # noqa
|
49
|
+
ForbiddenTypeError,
|
50
|
+
MarshalError,
|
51
|
+
UnhandledTypeError,
|
52
|
+
)
|
53
|
+
|
54
|
+
from .base.funcs import ( # noqa
|
55
|
+
FuncMarshaler,
|
56
|
+
FuncUnmarshaler,
|
57
|
+
|
58
|
+
FuncMarshalerFactory,
|
59
|
+
FuncUnmarshalerFactory,
|
60
|
+
)
|
61
|
+
|
62
|
+
from .base.options import ( # noqa
|
63
|
+
Option,
|
64
|
+
)
|
65
|
+
|
66
|
+
from .base.overrides import ( # noqa
|
67
|
+
Override,
|
68
|
+
ReflectOverride,
|
69
|
+
)
|
70
|
+
|
71
|
+
from .base.registries import ( # noqa
|
72
|
+
RegistrySealedError,
|
73
|
+
Registry,
|
74
|
+
)
|
75
|
+
|
76
|
+
from .base.types import ( # noqa
|
77
|
+
Marshaler,
|
78
|
+
Unmarshaler,
|
79
|
+
|
80
|
+
MarshalerMaker,
|
81
|
+
UnmarshalerMaker,
|
82
|
+
|
83
|
+
MarshalerFactory,
|
84
|
+
UnmarshalerFactory,
|
85
|
+
|
86
|
+
Marshaling,
|
87
|
+
)
|
88
|
+
|
89
|
+
from .base.values import ( # noqa
|
90
|
+
Value,
|
91
|
+
)
|
92
|
+
|
93
|
+
from .composite.iterables import ( # noqa
|
94
|
+
IterableMarshaler,
|
95
|
+
IterableUnmarshaler,
|
96
|
+
)
|
97
|
+
|
98
|
+
from .composite.wrapped import ( # noqa
|
99
|
+
WrappedMarshaler,
|
100
|
+
WrappedUnmarshaler,
|
101
|
+
)
|
102
|
+
|
103
|
+
from .factories.simple import ( # noqa
|
104
|
+
SimpleMarshalerFactory,
|
105
|
+
SimpleUnmarshalerFactory,
|
106
|
+
)
|
107
|
+
|
108
|
+
from .factories.match import ( # noqa
|
109
|
+
MarshalerFactoryMatchClass,
|
110
|
+
UnmarshalerFactoryMatchClass,
|
111
|
+
)
|
112
|
+
|
113
|
+
from .factories.moduleimport.configs import ( # noqa
|
114
|
+
ModuleImport,
|
115
|
+
)
|
116
|
+
|
117
|
+
from .factories.moduleimport.factories import ( # noqa
|
118
|
+
ModuleImportingMarshalerFactory,
|
119
|
+
ModuleImportingUnmarshalerFactory,
|
120
|
+
)
|
121
|
+
|
122
|
+
from .factories.multi import ( # noqa
|
123
|
+
MultiMarshalerFactory,
|
124
|
+
MultiUnmarshalerFactory,
|
125
|
+
)
|
126
|
+
|
127
|
+
from .factories.typemap import ( # noqa
|
128
|
+
TypeMapMarshalerFactory,
|
129
|
+
TypeMapUnmarshalerFactory,
|
130
|
+
)
|
131
|
+
|
132
|
+
from .factories.typecache import ( # noqa
|
133
|
+
TypeCacheMarshalerFactory,
|
134
|
+
TypeCacheUnmarshalerFactory,
|
135
|
+
)
|
136
|
+
|
137
|
+
from .factories.recursive import ( # noqa
|
138
|
+
RecursiveMarshalerFactory,
|
139
|
+
RecursiveUnmarshalerFactory,
|
140
|
+
)
|
141
|
+
|
142
|
+
from .objects.dataclasses import ( # noqa
|
143
|
+
AbstractDataclassFactory,
|
144
|
+
DataclassMarshalerFactory,
|
145
|
+
DataclassUnmarshalerFactory,
|
146
|
+
get_dataclass_field_infos,
|
147
|
+
get_dataclass_metadata,
|
148
|
+
)
|
149
|
+
|
150
|
+
from .objects.helpers import ( # noqa
|
151
|
+
update_fields_metadata,
|
152
|
+
update_object_metadata,
|
153
|
+
with_field_metadata,
|
154
|
+
)
|
155
|
+
|
156
|
+
from .objects.marshal import ( # noqa
|
157
|
+
ObjectMarshaler,
|
158
|
+
SimpleObjectMarshalerFactory,
|
159
|
+
)
|
160
|
+
|
161
|
+
from .objects.metadata import ( # noqa
|
162
|
+
FieldInfo,
|
163
|
+
FieldInfos,
|
164
|
+
FieldMetadata,
|
165
|
+
FieldOptions,
|
166
|
+
ObjectMetadata,
|
167
|
+
ObjectSpecials,
|
168
|
+
)
|
169
|
+
|
170
|
+
from .objects.unmarshal import ( # noqa
|
171
|
+
ObjectUnmarshaler,
|
172
|
+
SimpleObjectUnmarshalerFactory,
|
173
|
+
)
|
174
|
+
|
175
|
+
from .polymorphism.marshal import ( # noqa
|
176
|
+
PolymorphismMarshaler,
|
177
|
+
PolymorphismMarshalerFactory,
|
178
|
+
make_polymorphism_marshaler,
|
179
|
+
)
|
180
|
+
|
181
|
+
from .polymorphism.metadata import ( # noqa
|
182
|
+
FieldTypeTagging,
|
183
|
+
Impl,
|
184
|
+
Impls,
|
185
|
+
Polymorphism,
|
186
|
+
TypeTagging,
|
187
|
+
WrapperTypeTagging,
|
188
|
+
polymorphism_from_impls,
|
189
|
+
polymorphism_from_subclasses,
|
190
|
+
)
|
191
|
+
|
192
|
+
from .polymorphism.standard import ( # noqa
|
193
|
+
standard_polymorphism_factories,
|
194
|
+
)
|
195
|
+
|
196
|
+
from .polymorphism.unions import ( # noqa
|
197
|
+
PRIMITIVE_UNION_TYPES,
|
198
|
+
PolymorphismUnionMarshalerFactory,
|
199
|
+
PolymorphismUnionUnmarshalerFactory,
|
200
|
+
PrimitiveUnionMarshaler,
|
201
|
+
PrimitiveUnionMarshalerFactory,
|
202
|
+
PrimitiveUnionUnmarshaler,
|
203
|
+
PrimitiveUnionUnmarshalerFactory,
|
204
|
+
)
|
205
|
+
|
206
|
+
from .polymorphism.unmarshal import ( # noqa
|
207
|
+
PolymorphismUnmarshaler,
|
208
|
+
PolymorphismUnmarshalerFactory,
|
209
|
+
make_polymorphism_unmarshaler,
|
210
|
+
)
|
211
|
+
|
212
|
+
from .singular.base64 import ( # noqa
|
213
|
+
BASE64_MARSHALER_FACTORY,
|
214
|
+
BASE64_UNMARSHALER_FACTORY,
|
215
|
+
)
|
216
|
+
|
217
|
+
from .singular.primitives import ( # noqa
|
218
|
+
PRIMITIVE_TYPES,
|
219
|
+
)
|
220
|
+
|
221
|
+
from .trivial.forbidden import ( # noqa
|
222
|
+
ForbiddenTypeMarshalerFactory,
|
223
|
+
ForbiddenTypeUnmarshalerFactory,
|
224
|
+
)
|
225
|
+
|
226
|
+
from .trivial.nop import ( # noqa
|
227
|
+
NOP_MARSHALER_UNMARSHALER,
|
228
|
+
NopMarshalerUnmarshaler,
|
229
|
+
)
|
230
|
+
|
231
|
+
from .globals import ( # noqa
|
232
|
+
global_config_registry,
|
233
|
+
global_marshaler_factory,
|
234
|
+
global_unmarshaler_factory,
|
235
|
+
global_marshaling,
|
236
|
+
|
237
|
+
marshal,
|
238
|
+
unmarshal,
|
239
|
+
|
240
|
+
register_global_config,
|
241
|
+
register_global_module_import,
|
242
|
+
)
|
243
|
+
|
244
|
+
from .naming import ( # noqa
|
245
|
+
Naming,
|
246
|
+
translate_name,
|
247
|
+
)
|
248
|
+
|
249
|
+
from .standard import ( # noqa
|
250
|
+
StandardFactories,
|
251
|
+
DEFAULT_STANDARD_FACTORIES,
|
252
|
+
|
253
|
+
new_standard_marshaler_factory,
|
254
|
+
new_standard_unmarshaler_factory,
|
255
|
+
|
256
|
+
install_standard_factories,
|
257
|
+
)
|
@@ -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,18 +1,19 @@
|
|
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
14
|
|
13
15
|
|
14
16
|
if ta.TYPE_CHECKING:
|
15
|
-
from .registries import Registry
|
16
17
|
from .types import Marshaler
|
17
18
|
from .types import MarshalerFactory
|
18
19
|
from .types import Unmarshaler
|
@@ -26,21 +27,21 @@ T = ta.TypeVar('T')
|
|
26
27
|
##
|
27
28
|
|
28
29
|
|
29
|
-
@dc.dataclass(frozen=True)
|
30
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
30
31
|
class BaseContext(lang.Abstract):
|
31
|
-
|
32
|
+
config_registry: ConfigRegistry = EMPTY_CONFIG_REGISTRY
|
32
33
|
options: col.TypeMap[Option] = col.TypeMap()
|
33
34
|
|
34
35
|
def _reflect(self, o: ta.Any) -> rfl.Type:
|
35
36
|
def override(o):
|
36
|
-
if (ovr := self.
|
37
|
+
if (ovr := self.config_registry.get_of(o, ReflectOverride)):
|
37
38
|
return ovr[-1].rty
|
38
39
|
return None
|
39
40
|
|
40
41
|
return rfl.Reflector(override=override).type(o)
|
41
42
|
|
42
43
|
|
43
|
-
@dc.dataclass(frozen=True)
|
44
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
44
45
|
class MarshalContext(BaseContext, lang.Final):
|
45
46
|
factory: ta.Optional['MarshalerFactory'] = None
|
46
47
|
|
@@ -55,7 +56,7 @@ class MarshalContext(BaseContext, lang.Final):
|
|
55
56
|
return self.make(ty if ty is not None else type(obj)).marshal(self, obj)
|
56
57
|
|
57
58
|
|
58
|
-
@dc.dataclass(frozen=True)
|
59
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
59
60
|
class UnmarshalContext(BaseContext, lang.Final):
|
60
61
|
factory: ta.Optional['UnmarshalerFactory'] = None
|
61
62
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import dataclasses as dc
|
2
|
+
import typing as ta
|
3
|
+
|
4
|
+
from ... import lang
|
5
|
+
from ... import reflect as rfl
|
6
|
+
from ...funcs import match as mfs
|
7
|
+
from .contexts import MarshalContext
|
8
|
+
from .contexts import UnmarshalContext
|
9
|
+
from .types import Marshaler
|
10
|
+
from .types import MarshalerFactory
|
11
|
+
from .types import MarshalerMaker
|
12
|
+
from .types import Unmarshaler
|
13
|
+
from .types import UnmarshalerFactory
|
14
|
+
from .types import UnmarshalerMaker
|
15
|
+
from .values import Value
|
16
|
+
|
17
|
+
|
18
|
+
##
|
19
|
+
|
20
|
+
|
21
|
+
@dc.dataclass(frozen=True)
|
22
|
+
class FuncMarshaler(Marshaler, lang.Final):
|
23
|
+
fn: ta.Callable[[MarshalContext, ta.Any], Value]
|
24
|
+
|
25
|
+
def marshal(self, ctx: MarshalContext, o: ta.Any) -> Value:
|
26
|
+
return self.fn(ctx, o)
|
27
|
+
|
28
|
+
|
29
|
+
@dc.dataclass(frozen=True)
|
30
|
+
class FuncUnmarshaler(Unmarshaler, lang.Final):
|
31
|
+
fn: ta.Callable[[UnmarshalContext, Value], ta.Any]
|
32
|
+
|
33
|
+
def unmarshal(self, ctx: UnmarshalContext, v: Value) -> ta.Any:
|
34
|
+
return self.fn(ctx, v)
|
35
|
+
|
36
|
+
|
37
|
+
##
|
38
|
+
|
39
|
+
|
40
|
+
@dc.dataclass(frozen=True)
|
41
|
+
class FuncMarshalerFactory(MarshalerFactory): # noqa
|
42
|
+
guard: ta.Callable[[MarshalContext, rfl.Type], bool]
|
43
|
+
fn: ta.Callable[[MarshalContext, rfl.Type], Marshaler]
|
44
|
+
|
45
|
+
@lang.cached_property
|
46
|
+
def make_marshaler(self) -> MarshalerMaker:
|
47
|
+
return mfs.simple(self.guard, self.fn)
|
48
|
+
|
49
|
+
|
50
|
+
@dc.dataclass(frozen=True)
|
51
|
+
class FuncUnmarshalerFactory(UnmarshalerFactory): # noqa
|
52
|
+
guard: ta.Callable[[UnmarshalContext, rfl.Type], bool]
|
53
|
+
fn: ta.Callable[[UnmarshalContext, rfl.Type], Unmarshaler]
|
54
|
+
|
55
|
+
@lang.cached_property
|
56
|
+
def make_unmarshaler(self) -> UnmarshalerMaker:
|
57
|
+
return mfs.simple(self.guard, self.fn)
|