omlish 0.0.0.dev454__py3-none-any.whl → 0.0.0.dev455__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/lang/functions.py +2 -2
- omlish/marshal/__init__.py +4 -0
- omlish/marshal/base/contexts.py +29 -13
- omlish/marshal/base/funcs.py +4 -12
- omlish/marshal/base/options.py +8 -0
- omlish/marshal/base/types.py +25 -11
- omlish/marshal/composite/iterables.py +10 -8
- omlish/marshal/composite/literals.py +6 -4
- omlish/marshal/composite/mappings.py +10 -8
- omlish/marshal/composite/maybes.py +10 -8
- omlish/marshal/composite/newtypes.py +6 -6
- omlish/marshal/composite/optionals.py +6 -4
- omlish/marshal/composite/special.py +6 -6
- omlish/marshal/composite/unions/literals.py +6 -4
- omlish/marshal/composite/unions/primitives.py +6 -4
- omlish/marshal/factories/invalidate.py +4 -4
- omlish/marshal/factories/method.py +4 -6
- omlish/marshal/factories/moduleimport/factories.py +4 -4
- omlish/marshal/factories/multi.py +4 -4
- omlish/marshal/factories/recursive.py +4 -2
- omlish/marshal/factories/typecache.py +4 -9
- omlish/marshal/factories/typemap.py +4 -4
- omlish/marshal/objects/dataclasses.py +30 -16
- omlish/marshal/objects/marshal.py +4 -3
- omlish/marshal/objects/namedtuples.py +6 -6
- omlish/marshal/objects/unmarshal.py +4 -3
- omlish/marshal/polymorphism/marshal.py +4 -3
- omlish/marshal/polymorphism/unions.py +7 -7
- omlish/marshal/polymorphism/unmarshal.py +4 -3
- omlish/marshal/singular/enums.py +4 -2
- omlish/marshal/trivial/any.py +1 -1
- omlish/marshal/trivial/forbidden.py +4 -4
- omlish/specs/jsonrpc/_marshal.py +4 -4
- omlish/specs/openapi/_marshal.py +16 -10
- omlish/typedvalues/marshal.py +14 -14
- {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev455.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev455.dist-info}/RECORD +42 -43
- omlish/funcs/match.py +0 -229
- {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev455.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev455.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev455.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev454.dist-info → omlish-0.0.0.dev455.dist-info}/top_level.txt +0 -0
@@ -12,8 +12,8 @@ import typing as ta
|
|
12
12
|
|
13
13
|
from .... import reflect as rfl
|
14
14
|
from ...base.contexts import BaseContext
|
15
|
-
from ...base.contexts import
|
16
|
-
from ...base.contexts import
|
15
|
+
from ...base.contexts import MarshalFactoryContext
|
16
|
+
from ...base.contexts import UnmarshalFactoryContext
|
17
17
|
from ...base.types import Marshaler
|
18
18
|
from ...base.types import MarshalerFactory
|
19
19
|
from ...base.types import Unmarshaler
|
@@ -60,12 +60,12 @@ class _ModuleImportingFactory(ta.Generic[FactoryT]):
|
|
60
60
|
|
61
61
|
|
62
62
|
class ModuleImportingMarshalerFactory(_ModuleImportingFactory[MarshalerFactory], MarshalerFactory):
|
63
|
-
def make_marshaler(self, ctx:
|
63
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
64
64
|
self._import_if_necessary(ctx)
|
65
65
|
return self._fac.make_marshaler(ctx, rty)
|
66
66
|
|
67
67
|
|
68
68
|
class ModuleImportingUnmarshalerFactory(_ModuleImportingFactory[UnmarshalerFactory], UnmarshalerFactory):
|
69
|
-
def make_unmarshaler(self, ctx:
|
69
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
70
70
|
self._import_if_necessary(ctx)
|
71
71
|
return self._fac.make_unmarshaler(ctx, rty)
|
@@ -2,8 +2,8 @@ import typing as ta
|
|
2
2
|
|
3
3
|
from ... import reflect as rfl
|
4
4
|
from ...funcs import guard as gfs
|
5
|
-
from ..base.contexts import
|
6
|
-
from ..base.contexts import
|
5
|
+
from ..base.contexts import MarshalFactoryContext
|
6
|
+
from ..base.contexts import UnmarshalFactoryContext
|
7
7
|
from ..base.types import Marshaler
|
8
8
|
from ..base.types import MarshalerFactory
|
9
9
|
from ..base.types import Unmarshaler
|
@@ -24,7 +24,7 @@ class MultiMarshalerFactory(MarshalerFactory):
|
|
24
24
|
self._facs = facs
|
25
25
|
self._mgf = gfs.multi(*[f.make_marshaler for f in self._facs], strict=strict)
|
26
26
|
|
27
|
-
def make_marshaler(self, ctx:
|
27
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
28
28
|
return self._mgf(ctx, rty)
|
29
29
|
|
30
30
|
|
@@ -39,5 +39,5 @@ class MultiUnmarshalerFactory(UnmarshalerFactory):
|
|
39
39
|
self._facs = facs
|
40
40
|
self._mgf = gfs.multi(*[f.make_unmarshaler for f in self._facs], strict=strict)
|
41
41
|
|
42
|
-
def make_unmarshaler(self, ctx:
|
42
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
43
43
|
return self._mgf(ctx, rty)
|
@@ -2,7 +2,9 @@ import typing as ta
|
|
2
2
|
|
3
3
|
from ... import reflect as rfl
|
4
4
|
from ..base.contexts import MarshalContext
|
5
|
+
from ..base.contexts import MarshalFactoryContext
|
5
6
|
from ..base.contexts import UnmarshalContext
|
7
|
+
from ..base.contexts import UnmarshalFactoryContext
|
6
8
|
from ..base.types import Marshaler
|
7
9
|
from ..base.types import MarshalerFactory
|
8
10
|
from ..base.types import Unmarshaler
|
@@ -80,7 +82,7 @@ class RecursiveMarshalerFactory(_RecursiveFactory[MarshalerFactory], MarshalerFa
|
|
80
82
|
def __init__(self, fac: MarshalerFactory) -> None:
|
81
83
|
super().__init__(fac, _ProxyMarshaler._new) # noqa
|
82
84
|
|
83
|
-
def make_marshaler(self, ctx:
|
85
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
84
86
|
if (m := self._fac.make_marshaler(ctx, rty)) is None:
|
85
87
|
return None
|
86
88
|
return self._wrap(m, rty)
|
@@ -98,7 +100,7 @@ class RecursiveUnmarshalerFactory(_RecursiveFactory[UnmarshalerFactory], Unmarsh
|
|
98
100
|
def __init__(self, fac: UnmarshalerFactory) -> None:
|
99
101
|
super().__init__(fac, _ProxyUnmarshaler._new) # noqa
|
100
102
|
|
101
|
-
def make_unmarshaler(self, ctx:
|
103
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
102
104
|
if (m := self._fac.make_unmarshaler(ctx, rty)) is None:
|
103
105
|
return None
|
104
106
|
return self._wrap(m, rty)
|
@@ -1,15 +1,10 @@
|
|
1
|
-
"""
|
2
|
-
FIXME:
|
3
|
-
- fix Context lifetime broken design already
|
4
|
-
- obvious: FactoryContext
|
5
|
-
"""
|
6
1
|
import threading
|
7
2
|
import typing as ta
|
8
3
|
|
9
4
|
from ... import check
|
10
5
|
from ... import reflect as rfl
|
11
|
-
from ..base.contexts import
|
12
|
-
from ..base.contexts import
|
6
|
+
from ..base.contexts import MarshalFactoryContext
|
7
|
+
from ..base.contexts import UnmarshalFactoryContext
|
13
8
|
from ..base.types import Marshaler
|
14
9
|
from ..base.types import MarshalerFactory
|
15
10
|
from ..base.types import Unmarshaler
|
@@ -50,10 +45,10 @@ class _TypeCacheFactory(ta.Generic[FactoryT]):
|
|
50
45
|
|
51
46
|
|
52
47
|
class TypeCacheMarshalerFactory(_TypeCacheFactory[MarshalerFactory], MarshalerFactory):
|
53
|
-
def make_marshaler(self, ctx:
|
48
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
54
49
|
return self._make(rty, lambda: self._fac.make_marshaler(ctx, rty))
|
55
50
|
|
56
51
|
|
57
52
|
class TypeCacheUnmarshalerFactory(_TypeCacheFactory[UnmarshalerFactory], UnmarshalerFactory):
|
58
|
-
def make_unmarshaler(self, ctx:
|
53
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
59
54
|
return self._make(rty, lambda: self._fac.make_unmarshaler(ctx, rty))
|
@@ -3,8 +3,8 @@ import typing as ta
|
|
3
3
|
from ... import check
|
4
4
|
from ... import dataclasses as dc
|
5
5
|
from ... import reflect as rfl
|
6
|
-
from ..base.contexts import
|
7
|
-
from ..base.contexts import
|
6
|
+
from ..base.contexts import MarshalFactoryContext
|
7
|
+
from ..base.contexts import UnmarshalFactoryContext
|
8
8
|
from ..base.types import Marshaler
|
9
9
|
from ..base.types import MarshalerFactory
|
10
10
|
from ..base.types import Unmarshaler
|
@@ -24,7 +24,7 @@ class TypeMapMarshalerFactory(MarshalerFactory):
|
|
24
24
|
},
|
25
25
|
)
|
26
26
|
|
27
|
-
def make_marshaler(self, ctx:
|
27
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
28
28
|
check.isinstance(rty, rfl.TYPES)
|
29
29
|
try:
|
30
30
|
m = self.m[rty]
|
@@ -49,7 +49,7 @@ class TypeMapUnmarshalerFactory(UnmarshalerFactory):
|
|
49
49
|
},
|
50
50
|
)
|
51
51
|
|
52
|
-
def make_unmarshaler(self, ctx:
|
52
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
53
53
|
check.isinstance(rty, rfl.TYPES)
|
54
54
|
try:
|
55
55
|
u = self.u[rty]
|
@@ -11,8 +11,8 @@ from ... import dataclasses as dc
|
|
11
11
|
from ... import lang
|
12
12
|
from ... import reflect as rfl
|
13
13
|
from ...lite import marshal as lm
|
14
|
-
from ..base.contexts import
|
15
|
-
from ..base.contexts import
|
14
|
+
from ..base.contexts import MarshalFactoryContext
|
15
|
+
from ..base.contexts import UnmarshalFactoryContext
|
16
16
|
from ..base.errors import UnhandledTypeError
|
17
17
|
from ..base.options import Option
|
18
18
|
from ..base.types import Marshaler
|
@@ -160,22 +160,38 @@ def get_dataclass_field_infos(
|
|
160
160
|
return FieldInfos(ret)
|
161
161
|
|
162
162
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
163
|
+
##
|
164
|
+
|
165
|
+
|
166
|
+
def _make_field_marshal_obj(
|
167
|
+
ctx: MarshalFactoryContext,
|
168
|
+
ty: ta.Any,
|
169
|
+
obj: Marshaler | None,
|
170
|
+
fac: MarshalerFactory | None,
|
169
171
|
):
|
170
172
|
if obj is not None:
|
171
173
|
return obj
|
172
174
|
if fac is not None:
|
173
|
-
if (m :=
|
175
|
+
if (m := fac.make_marshaler(ctx, ty)) is None:
|
174
176
|
raise UnhandledTypeError(ty)
|
175
177
|
return m()
|
176
|
-
return ctx.
|
178
|
+
return ctx.make_marshaler(ty)
|
177
179
|
|
178
180
|
|
181
|
+
def _make_field_unmarshal_obj(
|
182
|
+
ctx: UnmarshalFactoryContext,
|
183
|
+
ty: ta.Any,
|
184
|
+
obj: Unmarshaler | None,
|
185
|
+
fac: UnmarshalerFactory | None,
|
186
|
+
):
|
187
|
+
if obj is not None:
|
188
|
+
return obj
|
189
|
+
if fac is not None:
|
190
|
+
if (m := fac.make_unmarshaler(ctx, ty)) is None:
|
191
|
+
raise UnhandledTypeError(ty)
|
192
|
+
return m()
|
193
|
+
return ctx.make_unmarshaler(ty)
|
194
|
+
|
179
195
|
##
|
180
196
|
|
181
197
|
|
@@ -204,7 +220,7 @@ def _type_or_generic_base(rty: rfl.Type) -> type | None:
|
|
204
220
|
|
205
221
|
|
206
222
|
class DataclassMarshalerFactory(AbstractDataclassFactory, MarshalerFactory):
|
207
|
-
def make_marshaler(self, ctx:
|
223
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
208
224
|
if not (
|
209
225
|
(ty := _type_or_generic_base(rty)) is not None and
|
210
226
|
dc.is_dataclass(ty) and
|
@@ -223,12 +239,11 @@ class DataclassMarshalerFactory(AbstractDataclassFactory, MarshalerFactory):
|
|
223
239
|
fields = [
|
224
240
|
(
|
225
241
|
fi,
|
226
|
-
|
242
|
+
_make_field_marshal_obj(
|
227
243
|
ctx,
|
228
244
|
fi.type,
|
229
245
|
fi.metadata.marshaler,
|
230
246
|
fi.metadata.marshaler_factory,
|
231
|
-
'make_marshaler',
|
232
247
|
),
|
233
248
|
)
|
234
249
|
for fi in fis
|
@@ -247,7 +262,7 @@ class DataclassMarshalerFactory(AbstractDataclassFactory, MarshalerFactory):
|
|
247
262
|
|
248
263
|
|
249
264
|
class DataclassUnmarshalerFactory(AbstractDataclassFactory, UnmarshalerFactory):
|
250
|
-
def make_unmarshaler(self, ctx:
|
265
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
251
266
|
if not (
|
252
267
|
(ty := _type_or_generic_base(rty)) is not None and
|
253
268
|
dc.is_dataclass(ty) and
|
@@ -287,12 +302,11 @@ class DataclassUnmarshalerFactory(AbstractDataclassFactory, UnmarshalerFactory):
|
|
287
302
|
else:
|
288
303
|
tup = (
|
289
304
|
fi,
|
290
|
-
|
305
|
+
_make_field_unmarshal_obj(
|
291
306
|
ctx,
|
292
307
|
fi.type,
|
293
308
|
fi.metadata.unmarshaler,
|
294
309
|
fi.metadata.unmarshaler_factory,
|
295
|
-
'make_unmarshaler',
|
296
310
|
),
|
297
311
|
)
|
298
312
|
|
@@ -5,6 +5,7 @@ from ... import check
|
|
5
5
|
from ... import dataclasses as dc
|
6
6
|
from ... import reflect as rfl
|
7
7
|
from ..base.contexts import MarshalContext
|
8
|
+
from ..base.contexts import MarshalFactoryContext
|
8
9
|
from ..base.types import Marshaler
|
9
10
|
from ..base.types import MarshalerFactory
|
10
11
|
from ..base.values import Value
|
@@ -29,12 +30,12 @@ class ObjectMarshaler(Marshaler):
|
|
29
30
|
@classmethod
|
30
31
|
def make(
|
31
32
|
cls,
|
32
|
-
ctx:
|
33
|
+
ctx: MarshalFactoryContext,
|
33
34
|
fis: FieldInfos,
|
34
35
|
**kwargs: ta.Any,
|
35
36
|
) -> Marshaler:
|
36
37
|
fields = [
|
37
|
-
(fi, ctx.
|
38
|
+
(fi, ctx.make_marshaler(fi.type))
|
38
39
|
for fi in fis
|
39
40
|
]
|
40
41
|
|
@@ -93,7 +94,7 @@ class SimpleObjectMarshalerFactory(MarshalerFactory):
|
|
93
94
|
|
94
95
|
specials: ObjectSpecials = ObjectSpecials()
|
95
96
|
|
96
|
-
def make_marshaler(self, ctx:
|
97
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
97
98
|
if not (isinstance(rty, type) and rty in self.dct):
|
98
99
|
return None
|
99
100
|
|
@@ -5,8 +5,8 @@ from ... import check
|
|
5
5
|
from ... import collections as col
|
6
6
|
from ... import lang
|
7
7
|
from ... import reflect as rfl
|
8
|
-
from ..base.contexts import
|
9
|
-
from ..base.contexts import
|
8
|
+
from ..base.contexts import MarshalFactoryContext
|
9
|
+
from ..base.contexts import UnmarshalFactoryContext
|
10
10
|
from ..base.options import Option
|
11
11
|
from ..base.types import Marshaler
|
12
12
|
from ..base.types import MarshalerFactory
|
@@ -56,7 +56,7 @@ def get_namedtuple_field_infos(
|
|
56
56
|
|
57
57
|
|
58
58
|
class NamedtupleMarshalerFactory(MarshalerFactory):
|
59
|
-
def make_marshaler(self, ctx:
|
59
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
60
60
|
if not _is_namedtuple(rty):
|
61
61
|
return None
|
62
62
|
|
@@ -68,7 +68,7 @@ class NamedtupleMarshalerFactory(MarshalerFactory):
|
|
68
68
|
fis = get_namedtuple_field_infos(ty, ctx.options)
|
69
69
|
|
70
70
|
fields = [
|
71
|
-
(fi, ctx.
|
71
|
+
(fi, ctx.make_marshaler(fi.type))
|
72
72
|
for fi in fis
|
73
73
|
]
|
74
74
|
|
@@ -83,7 +83,7 @@ class NamedtupleMarshalerFactory(MarshalerFactory):
|
|
83
83
|
|
84
84
|
|
85
85
|
class NamedtupleUnmarshalerFactory(UnmarshalerFactory):
|
86
|
-
def make_unmarshaler(self, ctx:
|
86
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
87
87
|
if not _is_namedtuple(rty):
|
88
88
|
return None
|
89
89
|
|
@@ -98,7 +98,7 @@ class NamedtupleUnmarshalerFactory(UnmarshalerFactory):
|
|
98
98
|
defaults: dict[str, ta.Any] = {}
|
99
99
|
|
100
100
|
for fi in fis:
|
101
|
-
tup = (fi, ctx.
|
101
|
+
tup = (fi, ctx.make_unmarshaler(fi.type))
|
102
102
|
|
103
103
|
for un in fi.unmarshal_names:
|
104
104
|
if un in d:
|
@@ -5,6 +5,7 @@ from ... import check
|
|
5
5
|
from ... import dataclasses as dc
|
6
6
|
from ... import reflect as rfl
|
7
7
|
from ..base.contexts import UnmarshalContext
|
8
|
+
from ..base.contexts import UnmarshalFactoryContext
|
8
9
|
from ..base.types import Unmarshaler
|
9
10
|
from ..base.types import UnmarshalerFactory
|
10
11
|
from ..base.values import Value
|
@@ -35,13 +36,13 @@ class ObjectUnmarshaler(Unmarshaler):
|
|
35
36
|
@classmethod
|
36
37
|
def make(
|
37
38
|
cls,
|
38
|
-
ctx:
|
39
|
+
ctx: UnmarshalFactoryContext,
|
39
40
|
factory: ta.Callable,
|
40
41
|
fis: FieldInfos,
|
41
42
|
**kwargs: ta.Any,
|
42
43
|
) -> Unmarshaler:
|
43
44
|
fields_by_unmarshal_name = {
|
44
|
-
n: (fi, ctx.
|
45
|
+
n: (fi, ctx.make_unmarshaler(fi.type))
|
45
46
|
for fi in fis
|
46
47
|
for n in fi.unmarshal_names
|
47
48
|
}
|
@@ -125,7 +126,7 @@ class SimpleObjectUnmarshalerFactory(UnmarshalerFactory):
|
|
125
126
|
|
126
127
|
specials: ObjectSpecials = ObjectSpecials()
|
127
128
|
|
128
|
-
def make_unmarshaler(self, ctx:
|
129
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
129
130
|
if not (isinstance(rty, type) and rty in self.dct):
|
130
131
|
return None
|
131
132
|
|
@@ -5,6 +5,7 @@ import typing as ta
|
|
5
5
|
from ... import lang
|
6
6
|
from ... import reflect as rfl
|
7
7
|
from ..base.contexts import MarshalContext
|
8
|
+
from ..base.contexts import MarshalFactoryContext
|
8
9
|
from ..base.types import Marshaler
|
9
10
|
from ..base.types import MarshalerFactory
|
10
11
|
from ..base.values import Value
|
@@ -52,10 +53,10 @@ class FieldPolymorphismMarshaler(PolymorphismMarshaler):
|
|
52
53
|
def make_polymorphism_marshaler(
|
53
54
|
impls: Impls,
|
54
55
|
tt: TypeTagging,
|
55
|
-
ctx:
|
56
|
+
ctx: MarshalFactoryContext,
|
56
57
|
) -> Marshaler:
|
57
58
|
m = {
|
58
|
-
i.ty: (i.tag, ctx.
|
59
|
+
i.ty: (i.tag, ctx.make_marshaler(i.ty))
|
59
60
|
for i in impls
|
60
61
|
}
|
61
62
|
if isinstance(tt, WrapperTypeTagging):
|
@@ -71,7 +72,7 @@ class PolymorphismMarshalerFactory(MarshalerFactory):
|
|
71
72
|
p: Polymorphism
|
72
73
|
tt: TypeTagging = WrapperTypeTagging()
|
73
74
|
|
74
|
-
def make_marshaler(self, ctx:
|
75
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
75
76
|
if rty is not self.p.ty:
|
76
77
|
return None
|
77
78
|
return lambda: make_polymorphism_marshaler(self.p.impls, self.tt, ctx)
|
@@ -5,8 +5,8 @@ from ... import check
|
|
5
5
|
from ... import dataclasses as dc
|
6
6
|
from ... import lang
|
7
7
|
from ... import reflect as rfl
|
8
|
-
from ..base.contexts import
|
9
|
-
from ..base.contexts import
|
8
|
+
from ..base.contexts import MarshalFactoryContext
|
9
|
+
from ..base.contexts import UnmarshalFactoryContext
|
10
10
|
from ..base.types import Marshaler
|
11
11
|
from ..base.types import MarshalerFactory
|
12
12
|
from ..base.types import Unmarshaler
|
@@ -32,7 +32,7 @@ class _BasePolymorphismUnionFactory(lang.Abstract):
|
|
32
32
|
def rtys(self) -> frozenset[rfl.Type]:
|
33
33
|
return frozenset(i.ty for i in self.impls)
|
34
34
|
|
35
|
-
def _guard(self,
|
35
|
+
def _guard(self, rty: rfl.Type) -> bool:
|
36
36
|
if not isinstance(rty, rfl.Union):
|
37
37
|
return False
|
38
38
|
if self.allow_partial:
|
@@ -47,15 +47,15 @@ class _BasePolymorphismUnionFactory(lang.Abstract):
|
|
47
47
|
|
48
48
|
@dc.dataclass(frozen=True)
|
49
49
|
class PolymorphismUnionMarshalerFactory(_BasePolymorphismUnionFactory, MarshalerFactory):
|
50
|
-
def make_marshaler(self, ctx:
|
51
|
-
if not self._guard(
|
50
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
51
|
+
if not self._guard(rty):
|
52
52
|
return None
|
53
53
|
return lambda: make_polymorphism_marshaler(self.get_impls(rty), self.tt, ctx)
|
54
54
|
|
55
55
|
|
56
56
|
@dc.dataclass(frozen=True)
|
57
57
|
class PolymorphismUnionUnmarshalerFactory(_BasePolymorphismUnionFactory, UnmarshalerFactory):
|
58
|
-
def make_unmarshaler(self, ctx:
|
59
|
-
if not self._guard(
|
58
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
59
|
+
if not self._guard(rty):
|
60
60
|
return None
|
61
61
|
return lambda: make_polymorphism_unmarshaler(self.get_impls(rty), self.tt, ctx)
|
@@ -7,6 +7,7 @@ from ... import check
|
|
7
7
|
from ... import lang
|
8
8
|
from ... import reflect as rfl
|
9
9
|
from ..base.contexts import UnmarshalContext
|
10
|
+
from ..base.contexts import UnmarshalFactoryContext
|
10
11
|
from ..base.types import Unmarshaler
|
11
12
|
from ..base.types import UnmarshalerFactory
|
12
13
|
from ..base.values import Value
|
@@ -58,12 +59,12 @@ class FieldPolymorphismUnmarshaler(PolymorphismUnmarshaler):
|
|
58
59
|
def make_polymorphism_unmarshaler(
|
59
60
|
impls: Impls,
|
60
61
|
tt: TypeTagging,
|
61
|
-
ctx:
|
62
|
+
ctx: UnmarshalFactoryContext,
|
62
63
|
) -> Unmarshaler:
|
63
64
|
m = {
|
64
65
|
t: u
|
65
66
|
for i in impls
|
66
|
-
for u in [ctx.
|
67
|
+
for u in [ctx.make_unmarshaler(i.ty)]
|
67
68
|
for t in [i.tag, *i.alts]
|
68
69
|
}
|
69
70
|
if isinstance(tt, WrapperTypeTagging):
|
@@ -79,7 +80,7 @@ class PolymorphismUnmarshalerFactory(UnmarshalerFactory):
|
|
79
80
|
p: Polymorphism
|
80
81
|
tt: TypeTagging = WrapperTypeTagging()
|
81
82
|
|
82
|
-
def make_unmarshaler(self, ctx:
|
83
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
83
84
|
if rty is not self.p.ty:
|
84
85
|
return None
|
85
86
|
return lambda: make_polymorphism_unmarshaler(self.p.impls, self.tt, ctx)
|
omlish/marshal/singular/enums.py
CHANGED
@@ -5,7 +5,9 @@ import typing as ta
|
|
5
5
|
from ... import check
|
6
6
|
from ... import reflect as rfl
|
7
7
|
from ..base.contexts import MarshalContext
|
8
|
+
from ..base.contexts import MarshalFactoryContext
|
8
9
|
from ..base.contexts import UnmarshalContext
|
10
|
+
from ..base.contexts import UnmarshalFactoryContext
|
9
11
|
from ..base.types import Marshaler
|
10
12
|
from ..base.types import MarshalerFactory
|
11
13
|
from ..base.types import Unmarshaler
|
@@ -25,7 +27,7 @@ class EnumMarshaler(Marshaler):
|
|
25
27
|
|
26
28
|
|
27
29
|
class EnumMarshalerFactory(MarshalerFactory):
|
28
|
-
def make_marshaler(self, ctx:
|
30
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
29
31
|
if not (isinstance(rty, type) and issubclass(rty, enum.Enum)):
|
30
32
|
return None
|
31
33
|
return lambda: EnumMarshaler(rty) # noqa
|
@@ -40,7 +42,7 @@ class EnumUnmarshaler(Unmarshaler):
|
|
40
42
|
|
41
43
|
|
42
44
|
class EnumUnmarshalerFactory(UnmarshalerFactory):
|
43
|
-
def make_unmarshaler(self, ctx:
|
45
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
44
46
|
if not (isinstance(rty, type) and issubclass(rty, enum.Enum)):
|
45
47
|
return None
|
46
48
|
return lambda: EnumUnmarshaler(rty) # noqa
|
omlish/marshal/trivial/any.py
CHANGED
@@ -15,7 +15,7 @@ from ..factories.typemap import TypeMapUnmarshalerFactory
|
|
15
15
|
|
16
16
|
class AnyMarshalerUnmarshaler(Marshaler, Unmarshaler):
|
17
17
|
def marshal(self, ctx: MarshalContext, o: ta.Any) -> Value:
|
18
|
-
return ctx.
|
18
|
+
return ctx.marshal_factory_context.make_marshaler(type(o)).marshal(ctx, o)
|
19
19
|
|
20
20
|
def unmarshal(self, ctx: UnmarshalContext, v: Value) -> ta.Any:
|
21
21
|
return v
|
@@ -2,8 +2,8 @@ import dataclasses as dc
|
|
2
2
|
import typing as ta
|
3
3
|
|
4
4
|
from ... import reflect as rfl
|
5
|
-
from ..base.contexts import
|
6
|
-
from ..base.contexts import
|
5
|
+
from ..base.contexts import MarshalFactoryContext
|
6
|
+
from ..base.contexts import UnmarshalFactoryContext
|
7
7
|
from ..base.errors import ForbiddenTypeError
|
8
8
|
from ..base.types import Marshaler
|
9
9
|
from ..base.types import MarshalerFactory
|
@@ -18,7 +18,7 @@ from ..base.types import UnmarshalerFactory
|
|
18
18
|
class ForbiddenTypeMarshalerFactoryUnmarshalerFactory(MarshalerFactory, UnmarshalerFactory):
|
19
19
|
rtys: ta.AbstractSet[rfl.Type]
|
20
20
|
|
21
|
-
def make_marshaler(self, ctx:
|
21
|
+
def make_marshaler(self, ctx: MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Marshaler] | None:
|
22
22
|
if rty not in self.rtys:
|
23
23
|
return None
|
24
24
|
|
@@ -27,7 +27,7 @@ class ForbiddenTypeMarshalerFactoryUnmarshalerFactory(MarshalerFactory, Unmarsha
|
|
27
27
|
|
28
28
|
return inner
|
29
29
|
|
30
|
-
def make_unmarshaler(self, ctx:
|
30
|
+
def make_unmarshaler(self, ctx: UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], Unmarshaler] | None:
|
31
31
|
if rty not in self.rtys:
|
32
32
|
return None
|
33
33
|
|
omlish/specs/jsonrpc/_marshal.py
CHANGED
@@ -25,7 +25,7 @@ class NotSpecifiedUnionMarshaler(msh.Marshaler):
|
|
25
25
|
|
26
26
|
|
27
27
|
class NotSpecifiedUnionMarshalerFactory(msh.MarshalerFactory):
|
28
|
-
def make_marshaler(self, ctx: msh.
|
28
|
+
def make_marshaler(self, ctx: msh.MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Marshaler] | None:
|
29
29
|
if not (
|
30
30
|
isinstance(rty, rfl.Union) and
|
31
31
|
not rty.is_optional and
|
@@ -36,14 +36,14 @@ class NotSpecifiedUnionMarshalerFactory(msh.MarshalerFactory):
|
|
36
36
|
def inner() -> msh.Marshaler:
|
37
37
|
args = set(check.isinstance(rty, rfl.Union).args) - {_NOT_SPECIFIED_RTY}
|
38
38
|
nty = rfl.type_(ta.Union[*args])
|
39
|
-
m = ctx.
|
39
|
+
m = ctx.make_marshaler(nty)
|
40
40
|
return NotSpecifiedUnionMarshaler(m)
|
41
41
|
|
42
42
|
return inner
|
43
43
|
|
44
44
|
|
45
45
|
class NotSpecifiedUnionUnmarshalerFactory(msh.UnmarshalerFactory):
|
46
|
-
def make_unmarshaler(self, ctx: msh.
|
46
|
+
def make_unmarshaler(self, ctx: msh.UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None: # noqa
|
47
47
|
if not (
|
48
48
|
isinstance(rty, rfl.Union) and
|
49
49
|
not rty.is_optional and
|
@@ -54,7 +54,7 @@ class NotSpecifiedUnionUnmarshalerFactory(msh.UnmarshalerFactory):
|
|
54
54
|
def inner() -> msh.Unmarshaler:
|
55
55
|
args = set(check.isinstance(rty, rfl.Union).args) - {_NOT_SPECIFIED_RTY}
|
56
56
|
nty = rfl.type_(ta.Union[*args])
|
57
|
-
return ctx.
|
57
|
+
return ctx.make_unmarshaler(nty)
|
58
58
|
|
59
59
|
return inner
|
60
60
|
|
omlish/specs/openapi/_marshal.py
CHANGED
@@ -36,10 +36,13 @@ class _ReferenceUnionMarshaler(msh.Marshaler):
|
|
36
36
|
|
37
37
|
|
38
38
|
class _ReferenceUnionMarshalerFactory(msh.MarshalerFactory):
|
39
|
-
def make_marshaler(self, ctx: msh.
|
39
|
+
def make_marshaler(self, ctx: msh.MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Marshaler] | None:
|
40
40
|
if (rua := _reference_union_arg(rty)) is None:
|
41
41
|
return None
|
42
|
-
return lambda: _ReferenceUnionMarshaler(
|
42
|
+
return lambda: _ReferenceUnionMarshaler(
|
43
|
+
ctx.make_marshaler(check.not_none(rua)),
|
44
|
+
ctx.make_marshaler(Reference),
|
45
|
+
)
|
43
46
|
|
44
47
|
|
45
48
|
#
|
@@ -60,10 +63,13 @@ class _ReferenceUnionUnmarshaler(msh.Unmarshaler):
|
|
60
63
|
|
61
64
|
|
62
65
|
class _ReferenceUnionUnmarshalerFactory(msh.UnmarshalerFactory):
|
63
|
-
def make_unmarshaler(self, ctx: msh.
|
66
|
+
def make_unmarshaler(self, ctx: msh.UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None: # noqa
|
64
67
|
if (rua := _reference_union_arg(rty)) is None:
|
65
68
|
return None
|
66
|
-
return lambda: _ReferenceUnionUnmarshaler(
|
69
|
+
return lambda: _ReferenceUnionUnmarshaler(
|
70
|
+
ctx.make_unmarshaler(check.not_none(rua)),
|
71
|
+
ctx.make_unmarshaler(Reference),
|
72
|
+
)
|
67
73
|
|
68
74
|
|
69
75
|
##
|
@@ -88,16 +94,16 @@ class _SchemaMarshaler(msh.Marshaler):
|
|
88
94
|
|
89
95
|
|
90
96
|
class _SchemaMarshalerFactory(msh.MarshalerFactory):
|
91
|
-
def make_marshaler(self, ctx: msh.
|
97
|
+
def make_marshaler(self, ctx: msh.MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Marshaler] | None:
|
92
98
|
if rty is not Schema:
|
93
99
|
return None
|
94
100
|
return lambda: _SchemaMarshaler(
|
95
101
|
{
|
96
|
-
f: (msh.translate_name(f, msh.Naming.LOW_CAMEL), ctx.
|
102
|
+
f: (msh.translate_name(f, msh.Naming.LOW_CAMEL), ctx.make_marshaler(rfl.type_(a)))
|
97
103
|
for f, a in dc.reflect(Schema).field_annotations.items()
|
98
104
|
if f != 'keywords'
|
99
105
|
},
|
100
|
-
ctx.
|
106
|
+
ctx.make_marshaler(jsch.Keywords),
|
101
107
|
)
|
102
108
|
|
103
109
|
|
@@ -124,16 +130,16 @@ class _SchemaUnmarshaler(msh.Unmarshaler):
|
|
124
130
|
|
125
131
|
|
126
132
|
class _SchemaUnmarshalerFactory(msh.UnmarshalerFactory):
|
127
|
-
def make_unmarshaler(self, ctx: msh.
|
133
|
+
def make_unmarshaler(self, ctx: msh.UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None: # noqa
|
128
134
|
if rty is not Schema:
|
129
135
|
return None
|
130
136
|
return lambda: _SchemaUnmarshaler(
|
131
137
|
{
|
132
|
-
msh.translate_name(f, msh.Naming.LOW_CAMEL): (f, ctx.
|
138
|
+
msh.translate_name(f, msh.Naming.LOW_CAMEL): (f, ctx.make_unmarshaler(rfl.type_(a)))
|
133
139
|
for f, a in dc.reflect(Schema).field_annotations.items()
|
134
140
|
if f != 'keywords'
|
135
141
|
},
|
136
|
-
ctx.
|
142
|
+
ctx.make_unmarshaler(jsch.Keywords),
|
137
143
|
)
|
138
144
|
|
139
145
|
|