omlish 0.0.0.dev175__py3-none-any.whl → 0.0.0.dev176__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- omlish/__about__.py +2 -2
- omlish/lite/marshal.py +38 -4
- {omlish-0.0.0.dev175.dist-info → omlish-0.0.0.dev176.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev175.dist-info → omlish-0.0.0.dev176.dist-info}/RECORD +8 -8
- {omlish-0.0.0.dev175.dist-info → omlish-0.0.0.dev176.dist-info}/LICENSE +0 -0
- {omlish-0.0.0.dev175.dist-info → omlish-0.0.0.dev176.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev175.dist-info → omlish-0.0.0.dev176.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev175.dist-info → omlish-0.0.0.dev176.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
omlish/lite/marshal.py
CHANGED
@@ -200,6 +200,18 @@ class FieldsObjMarshaler(ObjMarshaler):
|
|
200
200
|
})
|
201
201
|
|
202
202
|
|
203
|
+
@dc.dataclass(frozen=True)
|
204
|
+
class SingleFieldObjMarshaler(ObjMarshaler):
|
205
|
+
ty: type
|
206
|
+
fld: str
|
207
|
+
|
208
|
+
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
209
|
+
return getattr(o, self.fld)
|
210
|
+
|
211
|
+
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
212
|
+
return self.ty(**{self.fld: o})
|
213
|
+
|
214
|
+
|
203
215
|
@dc.dataclass(frozen=True)
|
204
216
|
class PolymorphicObjMarshaler(ObjMarshaler):
|
205
217
|
class Impl(ta.NamedTuple):
|
@@ -274,7 +286,7 @@ _DEFAULT_OBJ_MARSHALERS: ta.Dict[ta.Any, ObjMarshaler] = {
|
|
274
286
|
**{t: IterableObjMarshaler(t, DynamicObjMarshaler()) for t in (list, tuple, set, frozenset)},
|
275
287
|
**{t: MappingObjMarshaler(t, DynamicObjMarshaler(), DynamicObjMarshaler()) for t in (dict,)},
|
276
288
|
|
277
|
-
|
289
|
+
**{t: DynamicObjMarshaler() for t in (ta.Any, object)},
|
278
290
|
|
279
291
|
**{t: DatetimeObjMarshaler(t) for t in (datetime.date, datetime.time, datetime.datetime)},
|
280
292
|
decimal.Decimal: DecimalObjMarshaler(),
|
@@ -299,6 +311,16 @@ _OBJ_MARSHALER_GENERIC_ITERABLE_TYPES: ta.Dict[ta.Any, type] = {
|
|
299
311
|
##
|
300
312
|
|
301
313
|
|
314
|
+
_REGISTERED_OBJ_MARSHALERS_BY_TYPE: ta.MutableMapping[type, ObjMarshaler] = weakref.WeakKeyDictionary()
|
315
|
+
|
316
|
+
|
317
|
+
def register_type_obj_marshaler(ty: type, om: ObjMarshaler) -> None:
|
318
|
+
_REGISTERED_OBJ_MARSHALERS_BY_TYPE[ty] = om
|
319
|
+
|
320
|
+
|
321
|
+
##
|
322
|
+
|
323
|
+
|
302
324
|
class ObjMarshalerManager:
|
303
325
|
def __init__(
|
304
326
|
self,
|
@@ -308,6 +330,8 @@ class ObjMarshalerManager:
|
|
308
330
|
default_obj_marshalers: ta.Dict[ta.Any, ObjMarshaler] = _DEFAULT_OBJ_MARSHALERS, # noqa
|
309
331
|
generic_mapping_types: ta.Dict[ta.Any, type] = _OBJ_MARSHALER_GENERIC_MAPPING_TYPES, # noqa
|
310
332
|
generic_iterable_types: ta.Dict[ta.Any, type] = _OBJ_MARSHALER_GENERIC_ITERABLE_TYPES, # noqa
|
333
|
+
|
334
|
+
registered_obj_marshalers: ta.Mapping[type, ObjMarshaler] = _REGISTERED_OBJ_MARSHALERS_BY_TYPE,
|
311
335
|
) -> None:
|
312
336
|
super().__init__()
|
313
337
|
|
@@ -316,6 +340,7 @@ class ObjMarshalerManager:
|
|
316
340
|
self._obj_marshalers = dict(default_obj_marshalers)
|
317
341
|
self._generic_mapping_types = generic_mapping_types
|
318
342
|
self._generic_iterable_types = generic_iterable_types
|
343
|
+
self._registered_obj_marshalers = registered_obj_marshalers
|
319
344
|
|
320
345
|
self._lock = threading.RLock()
|
321
346
|
self._marshalers: ta.Dict[ta.Any, ObjMarshaler] = dict(_DEFAULT_OBJ_MARSHALERS)
|
@@ -331,6 +356,9 @@ class ObjMarshalerManager:
|
|
331
356
|
non_strict_fields: bool = False,
|
332
357
|
) -> ObjMarshaler:
|
333
358
|
if isinstance(ty, type):
|
359
|
+
if (reg := self._registered_obj_marshalers.get(ty)) is not None:
|
360
|
+
return reg
|
361
|
+
|
334
362
|
if abc.ABC in ty.__bases__:
|
335
363
|
impls = [ity for ity in deep_subclasses(ty) if abc.ABC not in ity.__bases__] # type: ignore
|
336
364
|
if all(ity.__qualname__.endswith(ty.__name__) for ity in impls):
|
@@ -395,9 +423,15 @@ class ObjMarshalerManager:
|
|
395
423
|
|
396
424
|
#
|
397
425
|
|
398
|
-
def
|
426
|
+
def set_obj_marshaler(
|
427
|
+
self,
|
428
|
+
ty: ta.Any,
|
429
|
+
m: ObjMarshaler,
|
430
|
+
*,
|
431
|
+
override: bool = False,
|
432
|
+
) -> None:
|
399
433
|
with self._lock:
|
400
|
-
if ty in self._obj_marshalers:
|
434
|
+
if not override and ty in self._obj_marshalers:
|
401
435
|
raise KeyError(ty)
|
402
436
|
self._obj_marshalers[ty] = m
|
403
437
|
|
@@ -488,7 +522,7 @@ class ObjMarshalContext:
|
|
488
522
|
|
489
523
|
OBJ_MARSHALER_MANAGER = ObjMarshalerManager()
|
490
524
|
|
491
|
-
|
525
|
+
set_obj_marshaler = OBJ_MARSHALER_MANAGER.set_obj_marshaler
|
492
526
|
get_obj_marshaler = OBJ_MARSHALER_MANAGER.get_obj_marshaler
|
493
527
|
|
494
528
|
marshal_obj = OBJ_MARSHALER_MANAGER.marshal_obj
|
@@ -1,5 +1,5 @@
|
|
1
1
|
omlish/.manifests.json,sha256=lRkBDFxlAbf6lN5upo3WSf-owW8YG1T21dfpbQL-XHM,7598
|
2
|
-
omlish/__about__.py,sha256=
|
2
|
+
omlish/__about__.py,sha256=RBsHqgr7y9qfTJmoVH5GI5S3QcYfEugaqakxVkSTWjk,3409
|
3
3
|
omlish/__init__.py,sha256=SsyiITTuK0v74XpKV8dqNaCmjOlan1JZKrHQv5rWKPA,253
|
4
4
|
omlish/c3.py,sha256=ubu7lHwss5V4UznbejAI0qXhXahrU01MysuHOZI9C4U,8116
|
5
5
|
omlish/cached.py,sha256=UI-XTFBwA6YXWJJJeBn-WkwBkfzDjLBBaZf4nIJA9y0,510
|
@@ -382,7 +382,7 @@ omlish/lite/dataclasses.py,sha256=M6UD4VwGo0Ky7RNzKWbO0IOy7iBZVCIbTiC6EYbFnX8,10
|
|
382
382
|
omlish/lite/inject.py,sha256=EEaioN9ESAveVCMe2s5osjwI97FPRUVoU8P95vGUiYo,23376
|
383
383
|
omlish/lite/json.py,sha256=7-02Ny4fq-6YAu5ynvqoijhuYXWpLmfCI19GUeZnb1c,740
|
384
384
|
omlish/lite/logs.py,sha256=CWFG0NKGhqNeEgryF5atN2gkPYbUdTINEw_s1phbINM,51
|
385
|
-
omlish/lite/marshal.py,sha256=
|
385
|
+
omlish/lite/marshal.py,sha256=O_v_slgjAAiSGWComdRhqLXdumuIlBDc3SvoG_p00QM,15863
|
386
386
|
omlish/lite/maybes.py,sha256=7OlHJ8Q2r4wQ-aRbZSlJY7x0e8gDvufFdlohGEIJ3P4,833
|
387
387
|
omlish/lite/pycharm.py,sha256=pUOJevrPClSqTCEOkQBO11LKX2003tfDcp18a03QFrc,1163
|
388
388
|
omlish/lite/reflect.py,sha256=pzOY2PPuHH0omdtglkN6DheXDrGopdL3PtTJnejyLFU,2189
|
@@ -570,9 +570,9 @@ omlish/text/glyphsplit.py,sha256=Ug-dPRO7x-OrNNr8g1y6DotSZ2KH0S-VcOmUobwa4B0,329
|
|
570
570
|
omlish/text/indent.py,sha256=6Jj6TFY9unaPa4xPzrnZemJ-fHsV53IamP93XGjSUHs,1274
|
571
571
|
omlish/text/parts.py,sha256=7vPF1aTZdvLVYJ4EwBZVzRSy8XB3YqPd7JwEnNGGAOo,6495
|
572
572
|
omlish/text/random.py,sha256=jNWpqiaKjKyTdMXC-pWAsSC10AAP-cmRRPVhm59ZWLk,194
|
573
|
-
omlish-0.0.0.
|
574
|
-
omlish-0.0.0.
|
575
|
-
omlish-0.0.0.
|
576
|
-
omlish-0.0.0.
|
577
|
-
omlish-0.0.0.
|
578
|
-
omlish-0.0.0.
|
573
|
+
omlish-0.0.0.dev176.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
574
|
+
omlish-0.0.0.dev176.dist-info/METADATA,sha256=5-3GbbCrNa96UjitAH5tN4L4YlNjWLwyCMzobgcWWRE,4264
|
575
|
+
omlish-0.0.0.dev176.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
576
|
+
omlish-0.0.0.dev176.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
577
|
+
omlish-0.0.0.dev176.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
578
|
+
omlish-0.0.0.dev176.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|