ominfra 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.
@@ -5077,6 +5077,18 @@ class FieldsObjMarshaler(ObjMarshaler):
5077
5077
  })
5078
5078
 
5079
5079
 
5080
+ @dc.dataclass(frozen=True)
5081
+ class SingleFieldObjMarshaler(ObjMarshaler):
5082
+ ty: type
5083
+ fld: str
5084
+
5085
+ def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
5086
+ return getattr(o, self.fld)
5087
+
5088
+ def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
5089
+ return self.ty(**{self.fld: o})
5090
+
5091
+
5080
5092
  @dc.dataclass(frozen=True)
5081
5093
  class PolymorphicObjMarshaler(ObjMarshaler):
5082
5094
  class Impl(ta.NamedTuple):
@@ -5151,7 +5163,7 @@ _DEFAULT_OBJ_MARSHALERS: ta.Dict[ta.Any, ObjMarshaler] = {
5151
5163
  **{t: IterableObjMarshaler(t, DynamicObjMarshaler()) for t in (list, tuple, set, frozenset)},
5152
5164
  **{t: MappingObjMarshaler(t, DynamicObjMarshaler(), DynamicObjMarshaler()) for t in (dict,)},
5153
5165
 
5154
- ta.Any: DynamicObjMarshaler(),
5166
+ **{t: DynamicObjMarshaler() for t in (ta.Any, object)},
5155
5167
 
5156
5168
  **{t: DatetimeObjMarshaler(t) for t in (datetime.date, datetime.time, datetime.datetime)},
5157
5169
  decimal.Decimal: DecimalObjMarshaler(),
@@ -5176,6 +5188,16 @@ _OBJ_MARSHALER_GENERIC_ITERABLE_TYPES: ta.Dict[ta.Any, type] = {
5176
5188
  ##
5177
5189
 
5178
5190
 
5191
+ _REGISTERED_OBJ_MARSHALERS_BY_TYPE: ta.MutableMapping[type, ObjMarshaler] = weakref.WeakKeyDictionary()
5192
+
5193
+
5194
+ def register_type_obj_marshaler(ty: type, om: ObjMarshaler) -> None:
5195
+ _REGISTERED_OBJ_MARSHALERS_BY_TYPE[ty] = om
5196
+
5197
+
5198
+ ##
5199
+
5200
+
5179
5201
  class ObjMarshalerManager:
5180
5202
  def __init__(
5181
5203
  self,
@@ -5185,6 +5207,8 @@ class ObjMarshalerManager:
5185
5207
  default_obj_marshalers: ta.Dict[ta.Any, ObjMarshaler] = _DEFAULT_OBJ_MARSHALERS, # noqa
5186
5208
  generic_mapping_types: ta.Dict[ta.Any, type] = _OBJ_MARSHALER_GENERIC_MAPPING_TYPES, # noqa
5187
5209
  generic_iterable_types: ta.Dict[ta.Any, type] = _OBJ_MARSHALER_GENERIC_ITERABLE_TYPES, # noqa
5210
+
5211
+ registered_obj_marshalers: ta.Mapping[type, ObjMarshaler] = _REGISTERED_OBJ_MARSHALERS_BY_TYPE,
5188
5212
  ) -> None:
5189
5213
  super().__init__()
5190
5214
 
@@ -5193,6 +5217,7 @@ class ObjMarshalerManager:
5193
5217
  self._obj_marshalers = dict(default_obj_marshalers)
5194
5218
  self._generic_mapping_types = generic_mapping_types
5195
5219
  self._generic_iterable_types = generic_iterable_types
5220
+ self._registered_obj_marshalers = registered_obj_marshalers
5196
5221
 
5197
5222
  self._lock = threading.RLock()
5198
5223
  self._marshalers: ta.Dict[ta.Any, ObjMarshaler] = dict(_DEFAULT_OBJ_MARSHALERS)
@@ -5208,6 +5233,9 @@ class ObjMarshalerManager:
5208
5233
  non_strict_fields: bool = False,
5209
5234
  ) -> ObjMarshaler:
5210
5235
  if isinstance(ty, type):
5236
+ if (reg := self._registered_obj_marshalers.get(ty)) is not None:
5237
+ return reg
5238
+
5211
5239
  if abc.ABC in ty.__bases__:
5212
5240
  impls = [ity for ity in deep_subclasses(ty) if abc.ABC not in ity.__bases__] # type: ignore
5213
5241
  if all(ity.__qualname__.endswith(ty.__name__) for ity in impls):
@@ -5272,9 +5300,15 @@ class ObjMarshalerManager:
5272
5300
 
5273
5301
  #
5274
5302
 
5275
- def register_opj_marshaler(self, ty: ta.Any, m: ObjMarshaler) -> None:
5303
+ def set_obj_marshaler(
5304
+ self,
5305
+ ty: ta.Any,
5306
+ m: ObjMarshaler,
5307
+ *,
5308
+ override: bool = False,
5309
+ ) -> None:
5276
5310
  with self._lock:
5277
- if ty in self._obj_marshalers:
5311
+ if not override and ty in self._obj_marshalers:
5278
5312
  raise KeyError(ty)
5279
5313
  self._obj_marshalers[ty] = m
5280
5314
 
@@ -5365,7 +5399,7 @@ class ObjMarshalContext:
5365
5399
 
5366
5400
  OBJ_MARSHALER_MANAGER = ObjMarshalerManager()
5367
5401
 
5368
- register_opj_marshaler = OBJ_MARSHALER_MANAGER.register_opj_marshaler
5402
+ set_obj_marshaler = OBJ_MARSHALER_MANAGER.set_obj_marshaler
5369
5403
  get_obj_marshaler = OBJ_MARSHALER_MANAGER.get_obj_marshaler
5370
5404
 
5371
5405
  marshal_obj = OBJ_MARSHALER_MANAGER.marshal_obj
@@ -5636,6 +5670,7 @@ def read_config_file(
5636
5670
  cls: ta.Type[T],
5637
5671
  *,
5638
5672
  prepare: ta.Optional[ta.Callable[[ConfigMapping], ConfigMapping]] = None,
5673
+ msh: ObjMarshalerManager = OBJ_MARSHALER_MANAGER,
5639
5674
  ) -> T:
5640
5675
  with open(path) as cf:
5641
5676
  config_dct = parse_config_file(os.path.basename(path), cf)
@@ -5643,7 +5678,7 @@ def read_config_file(
5643
5678
  if prepare is not None:
5644
5679
  config_dct = prepare(config_dct)
5645
5680
 
5646
- return unmarshal_obj(config_dct, cls)
5681
+ return msh.unmarshal_obj(config_dct, cls)
5647
5682
 
5648
5683
 
5649
5684
  def build_config_named_children(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ominfra
3
- Version: 0.0.0.dev175
3
+ Version: 0.0.0.dev176
4
4
  Summary: ominfra
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -12,8 +12,8 @@ Classifier: Operating System :: OS Independent
12
12
  Classifier: Operating System :: POSIX
13
13
  Requires-Python: >=3.12
14
14
  License-File: LICENSE
15
- Requires-Dist: omdev==0.0.0.dev175
16
- Requires-Dist: omlish==0.0.0.dev175
15
+ Requires-Dist: omdev==0.0.0.dev176
16
+ Requires-Dist: omlish==0.0.0.dev176
17
17
  Provides-Extra: all
18
18
  Requires-Dist: paramiko~=3.5; extra == "all"
19
19
  Requires-Dist: asyncssh~=2.18; extra == "all"
@@ -2,7 +2,7 @@ ominfra/.manifests.json,sha256=8KREXxMAlsilZOktXPYru1ND3V5hFI22vnrp6hT3bio,589
2
2
  ominfra/__about__.py,sha256=6i1AoruFYQCd-PyhhbDQDWY2d1tiQu9nkwWr-fXAqfY,705
3
3
  ominfra/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  ominfra/cmds.py,sha256=E0AfnvEmnKntXWvmLW5L05_NeDpBET1VBXn7vV6EwBQ,2083
5
- ominfra/configs.py,sha256=fUjGcYTZDyWcIF0BkHBxkGz64S33DR5NP8tHIf3IaXk,2291
5
+ ominfra/configs.py,sha256=gY49bZgAQU1IP3lfLbJxOlEuQcL1tlX3TjyJd-XYHt4,2413
6
6
  ominfra/pyremote.py,sha256=HLfAZl3Xw5CpxLS5PS380zqCyE7n3vKVksIYT2Fbdc8,15197
7
7
  ominfra/ssh.py,sha256=jQpc4WvkMckIfk4vILda8zFaeharRqc_6wxW50b0OjQ,5431
8
8
  ominfra/threadworkers.py,sha256=oX4ubZn7h932saXpRIJu2MNhBExgGGMuGhdXarZxLJw,4948
@@ -33,18 +33,18 @@ ominfra/manage/bootstrap.py,sha256=1RIRhVkUZjxZcZerHMg8U6xgWhhemGgPN5cDye8dQ68,4
33
33
  ominfra/manage/bootstrap_.py,sha256=B9UfR9J7mS3J54PFaSe1MQS5lCnKgxt5dDRJ9mnHYwg,656
34
34
  ominfra/manage/config.py,sha256=1y2N_8nXHBZc6YbW6BaRZoDDCTBmiHuWtTOQ7zdr5VE,184
35
35
  ominfra/manage/inject.py,sha256=_FVaMZUBKi-oObv14H77luWYCodxNJJD1t4pNQzckFE,2030
36
- ominfra/manage/main.py,sha256=xc8iTMNCvdS_leKA-5vodEj_Dc-V8pThpPxcewrROns,4287
36
+ ominfra/manage/main.py,sha256=LwtkPvnNWH87kxkZOlU925HqVlMtt-nQHHJ8koUYE3E,4564
37
37
  ominfra/manage/marshal.py,sha256=WKj7IU9bo4fBMSSzT6ZMm_WFalXIJZ-V7j8oi92fNhk,305
38
38
  ominfra/manage/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
39
  ominfra/manage/commands/base.py,sha256=LtaI0AgnplttQK7gNncNItq8yuTZQimJTaprVpZktI8,3993
40
40
  ominfra/manage/commands/inject.py,sha256=uRw6DsllEoL6GDy0dZJdu2z9tf6I7l3YObMli-qIuIo,3426
41
41
  ominfra/manage/commands/local.py,sha256=DyHIsQ03_YS6kAA8WLeMyXyGgyizkd1WZUZdATkSsZE,532
42
- ominfra/manage/commands/marshal.py,sha256=4DSCMPzRiRhufIB_9DPL6LrZkRZOle5ruOWU4MVlcXM,694
42
+ ominfra/manage/commands/marshal.py,sha256=Xl_yRgCD94yDmAx6e2uKVRjkmhV5EOr-Akqo3C0DGXw,689
43
43
  ominfra/manage/commands/ping.py,sha256=DVZFzL1Z_f-Bq53vxMrL3xOi0iK_nMonJE4KvQf9wsI,546
44
44
  ominfra/manage/commands/subprocess.py,sha256=yHGMbAI-xKe_9BUs5IZ3Yav8qRE-I9aGnBtTwW15Pnw,2440
45
45
  ominfra/manage/commands/types.py,sha256=XFZPeqeIBAaIIQF3pdPbGxLlb-LCrz6WtlDWO2q_vz0,210
46
46
  ominfra/manage/deploy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
- ominfra/manage/deploy/apps.py,sha256=4qcUi7Zxd2Sgfb8ZQSbjiMv1ppkHpJ37zJJMeDs6_xo,4738
47
+ ominfra/manage/deploy/apps.py,sha256=lowBeJICKMT6CNi7JULd0EbYVatmJRxVgIjTpnqnmgc,4819
48
48
  ominfra/manage/deploy/commands.py,sha256=fKFKhFwqIqC_PsgA-W66qIJ5S32xRgBBaRt3lbPX5Zg,763
49
49
  ominfra/manage/deploy/conf.py,sha256=cGu9q-mtbBsBXydTGrNE11NGyYdxbn7aPiGx28rxhsg,5639
50
50
  ominfra/manage/deploy/config.py,sha256=aR6ubMEWqkTI55XtcG1Cczn6YhCVN6eSL8DT5EHQJN0,166
@@ -53,10 +53,10 @@ ominfra/manage/deploy/git.py,sha256=cfTCx1qD-FQPFkbYW28tkU8nVxQbnfnWxpuJuGQHtBw,
53
53
  ominfra/manage/deploy/inject.py,sha256=kzGl2N2jhijUw4-PYUK1LNG8_MJD7BMgCbi6nDViMWg,1965
54
54
  ominfra/manage/deploy/interp.py,sha256=OKkenH8YKEW_mEDR6X7_ZLxK9a1Ox6KHSwFPTHT6OzA,1029
55
55
  ominfra/manage/deploy/specs.py,sha256=XIEOdLwULFprLajjzX6Qf_T3wVvEWeC4tIZgYbycCHI,3656
56
- ominfra/manage/deploy/tags.py,sha256=f2gTcV9aOGv5A6-6ZESHzeQ47TcLTkaEXe60_JyvqQo,4977
56
+ ominfra/manage/deploy/tags.py,sha256=NVEJhHKMwoDuCFd8lInH_jIe99FQILBX3wrulh3GiDg,5166
57
57
  ominfra/manage/deploy/tmp.py,sha256=dFJuqGfSf5otCxSaCI01a5UOSaArMlU4MzzYcyr74-s,1237
58
58
  ominfra/manage/deploy/types.py,sha256=ZcIoheZ3zW7n0IZiqTRW_Uo3JyWWeWg5nyKGryvGc2I,112
59
- ominfra/manage/deploy/venvs.py,sha256=1co8l3eSxl2WccrF-XOTqeltoMccRH63o69NblV3yok,1366
59
+ ominfra/manage/deploy/venvs.py,sha256=XJ6wellka8xpCWf4BAEb3BPwyHummFpSdHGKx4sv1I4,1741
60
60
  ominfra/manage/deploy/paths/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
61
61
  ominfra/manage/deploy/paths/inject.py,sha256=X81C-Qhef1LQ7tILWvkomBwFTvgooLVmWRnKL7TeVoI,596
62
62
  ominfra/manage/deploy/paths/manager.py,sha256=gxr_CsjLmjxXx8w3J8ookJk9OGltCpyBFYBnxXaw5lg,1050
@@ -85,9 +85,9 @@ ominfra/manage/targets/connection.py,sha256=rVI1YJxFClcF-sdttqWyIz9_XjPI01GUdwxY
85
85
  ominfra/manage/targets/inject.py,sha256=P4597xWM-V3I_gCt2O71OLhYQkkXtuJvkYRsIbhhMcE,1561
86
86
  ominfra/manage/targets/targets.py,sha256=7GP6UAZyJFEhpkJN6UQdpr_WN3p7C76v-s445y-WB6U,1885
87
87
  ominfra/scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
88
- ominfra/scripts/journald2aws.py,sha256=fbs8jZCsnwi5vF8Bg892wu3rscHCHeLQlvsDs6oAZBs,156681
89
- ominfra/scripts/manage.py,sha256=K9Z5QjGH3maQYwRnW3UbvL7dkdAk4-mLwvgWVC8TLSg,316780
90
- ominfra/scripts/supervisor.py,sha256=CD8o9RktPyB3L8nMBa6rabWE0tZlti6dmzoEEKRPWvY,275447
88
+ ominfra/scripts/journald2aws.py,sha256=yEnBAd0Q_3lBkVoTvlJ_uCcUxz7Ckn2qoSWZVhMihvQ,157696
89
+ ominfra/scripts/manage.py,sha256=Ight37o5Hq0-DRssyDmEtAw5-rF2kI3_hAin72YIj58,318454
90
+ ominfra/scripts/supervisor.py,sha256=9pEop3S5txoA2Gip9mcOrOJWFjMJVXCH6-NKYYnOVic,276462
91
91
  ominfra/supervisor/LICENSE.txt,sha256=yvqaMNsDhWxziHa9ien6qCW1SkZv-DQlAg96XjfSee8,1746
92
92
  ominfra/supervisor/__init__.py,sha256=Y3l4WY4JRi2uLG6kgbGp93fuGfkxkKwZDvhsa0Rwgtk,15
93
93
  ominfra/supervisor/__main__.py,sha256=I0yFw-C08OOiZ3BF6lF1Oiv789EQXu-_j6whDhQUTEA,66
@@ -129,9 +129,9 @@ ominfra/tailscale/api.py,sha256=C5-t_b6jZXUWcy5k8bXm7CFnk73pSdrlMOgGDeGVrpw,1370
129
129
  ominfra/tailscale/cli.py,sha256=h6akQJMl0KuWLHS7Ur6WcBZ2JwF0DJQhsPTnFBdGyNk,3571
130
130
  ominfra/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
131
131
  ominfra/tools/listresources.py,sha256=4qVg5txsb10EHhvqXXeM6gJ2jx9LbroEnPydDv1uXs0,6176
132
- ominfra-0.0.0.dev175.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
133
- ominfra-0.0.0.dev175.dist-info/METADATA,sha256=mSx5m3-8qdibsCJFkrdMM2Z7H2DonPWOBSnJFlETz2M,731
134
- ominfra-0.0.0.dev175.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
135
- ominfra-0.0.0.dev175.dist-info/entry_points.txt,sha256=kgecQ2MgGrM9qK744BoKS3tMesaC3yjLnl9pa5CRczg,37
136
- ominfra-0.0.0.dev175.dist-info/top_level.txt,sha256=E-b2OHkk_AOBLXHYZQ2EOFKl-_6uOGd8EjeG-Zy6h_w,8
137
- ominfra-0.0.0.dev175.dist-info/RECORD,,
132
+ ominfra-0.0.0.dev176.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
133
+ ominfra-0.0.0.dev176.dist-info/METADATA,sha256=pHdVlfo1mvUMcaCwCqtlhJsRy6azW5Ra87B2Fwwt7vU,731
134
+ ominfra-0.0.0.dev176.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
135
+ ominfra-0.0.0.dev176.dist-info/entry_points.txt,sha256=kgecQ2MgGrM9qK744BoKS3tMesaC3yjLnl9pa5CRczg,37
136
+ ominfra-0.0.0.dev176.dist-info/top_level.txt,sha256=E-b2OHkk_AOBLXHYZQ2EOFKl-_6uOGd8EjeG-Zy6h_w,8
137
+ ominfra-0.0.0.dev176.dist-info/RECORD,,