ominfra 0.0.0.dev149__py3-none-any.whl → 0.0.0.dev151__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@
7
7
  import abc
8
8
  import argparse
9
9
  import base64
10
+ import collections
10
11
  import collections.abc
11
12
  import contextlib
12
13
  import dataclasses as dc
@@ -62,6 +63,11 @@ CallableT = ta.TypeVar('CallableT', bound=ta.Callable)
62
63
 
63
64
  # ../../../../omlish/lite/check.py
64
65
  SizedT = ta.TypeVar('SizedT', bound=ta.Sized)
66
+ CheckMessage = ta.Union[str, ta.Callable[..., ta.Optional[str]], None] # ta.TypeAlias
67
+ CheckLateConfigureFn = ta.Callable[['Checks'], None] # ta.TypeAlias
68
+ CheckOnRaiseFn = ta.Callable[[Exception], None] # ta.TypeAlias
69
+ CheckExceptionFactory = ta.Callable[..., Exception] # ta.TypeAlias
70
+ CheckArgsRenderer = ta.Callable[..., ta.Optional[str]] # ta.TypeAlias
65
71
 
66
72
  # ../../../../omlish/lite/contextmanagers.py
67
73
  ExitStackedT = ta.TypeVar('ExitStackedT', bound='ExitStacked')
@@ -952,104 +958,454 @@ def async_cached_nullary(fn): # ta.Callable[..., T]) -> ta.Callable[..., T]:
952
958
 
953
959
  ########################################
954
960
  # ../../../../../omlish/lite/check.py
961
+ """
962
+ TODO:
963
+ - def maybe(v: lang.Maybe[T])
964
+ - patch / override lite.check ?
965
+ - checker interface?
966
+ """
967
+
968
+
969
+ ##
970
+
971
+
972
+ class Checks:
973
+ def __init__(self) -> None:
974
+ super().__init__()
975
+
976
+ self._config_lock = threading.RLock()
977
+ self._on_raise_fns: ta.Sequence[CheckOnRaiseFn] = []
978
+ self._exception_factory: CheckExceptionFactory = Checks.default_exception_factory
979
+ self._args_renderer: ta.Optional[CheckArgsRenderer] = None
980
+ self._late_configure_fns: ta.Sequence[CheckLateConfigureFn] = []
981
+
982
+ @staticmethod
983
+ def default_exception_factory(exc_cls: ta.Type[Exception], *args, **kwargs) -> Exception:
984
+ return exc_cls(*args, **kwargs) # noqa
955
985
 
986
+ #
956
987
 
957
- def check_isinstance(v: ta.Any, spec: ta.Union[ta.Type[T], tuple]) -> T:
958
- if not isinstance(v, spec):
959
- raise TypeError(v)
960
- return v
988
+ def register_on_raise(self, fn: CheckOnRaiseFn) -> None:
989
+ with self._config_lock:
990
+ self._on_raise_fns = [*self._on_raise_fns, fn]
961
991
 
992
+ def unregister_on_raise(self, fn: CheckOnRaiseFn) -> None:
993
+ with self._config_lock:
994
+ self._on_raise_fns = [e for e in self._on_raise_fns if e != fn]
962
995
 
963
- def check_not_isinstance(v: T, spec: ta.Union[type, tuple]) -> T:
964
- if isinstance(v, spec):
965
- raise TypeError(v)
966
- return v
996
+ #
967
997
 
998
+ def set_exception_factory(self, factory: CheckExceptionFactory) -> None:
999
+ self._exception_factory = factory
968
1000
 
969
- def check_none(v: T) -> None:
970
- if v is not None:
971
- raise ValueError(v)
1001
+ def set_args_renderer(self, renderer: ta.Optional[CheckArgsRenderer]) -> None:
1002
+ self._args_renderer = renderer
972
1003
 
1004
+ #
973
1005
 
974
- def check_not_none(v: ta.Optional[T]) -> T:
975
- if v is None:
976
- raise ValueError
977
- return v
1006
+ def register_late_configure(self, fn: CheckLateConfigureFn) -> None:
1007
+ with self._config_lock:
1008
+ self._late_configure_fns = [*self._late_configure_fns, fn]
978
1009
 
1010
+ def _late_configure(self) -> None:
1011
+ if not self._late_configure_fns:
1012
+ return
979
1013
 
980
- def check_not(v: ta.Any) -> None:
981
- if v:
982
- raise ValueError(v)
983
- return v
1014
+ with self._config_lock:
1015
+ if not (lc := self._late_configure_fns):
1016
+ return
984
1017
 
1018
+ for fn in lc:
1019
+ fn(self)
985
1020
 
986
- def check_non_empty_str(v: ta.Optional[str]) -> str:
987
- if not v:
988
- raise ValueError
989
- return v
1021
+ self._late_configure_fns = []
990
1022
 
1023
+ #
991
1024
 
992
- def check_arg(v: bool, msg: str = 'Illegal argument') -> None:
993
- if not v:
994
- raise ValueError(msg)
1025
+ class _ArgsKwargs:
1026
+ def __init__(self, *args, **kwargs):
1027
+ self.args = args
1028
+ self.kwargs = kwargs
995
1029
 
1030
+ def _raise(
1031
+ self,
1032
+ exception_type: ta.Type[Exception],
1033
+ default_message: str,
1034
+ message: CheckMessage,
1035
+ ak: _ArgsKwargs = _ArgsKwargs(),
1036
+ *,
1037
+ render_fmt: ta.Optional[str] = None,
1038
+ ) -> ta.NoReturn:
1039
+ exc_args = ()
1040
+ if callable(message):
1041
+ message = ta.cast(ta.Callable, message)(*ak.args, **ak.kwargs)
1042
+ if isinstance(message, tuple):
1043
+ message, *exc_args = message # type: ignore
1044
+
1045
+ if message is None:
1046
+ message = default_message
1047
+
1048
+ self._late_configure()
1049
+
1050
+ if render_fmt is not None and (af := self._args_renderer) is not None:
1051
+ rendered_args = af(render_fmt, *ak.args)
1052
+ if rendered_args is not None:
1053
+ message = f'{message} : {rendered_args}'
1054
+
1055
+ exc = self._exception_factory(
1056
+ exception_type,
1057
+ message,
1058
+ *exc_args,
1059
+ *ak.args,
1060
+ **ak.kwargs,
1061
+ )
996
1062
 
997
- def check_state(v: bool, msg: str = 'Illegal state') -> None:
998
- if not v:
999
- raise ValueError(msg)
1063
+ for fn in self._on_raise_fns:
1064
+ fn(exc)
1000
1065
 
1066
+ raise exc
1001
1067
 
1002
- def check_equal(l: T, r: T) -> T:
1003
- if l != r:
1004
- raise ValueError(l, r)
1005
- return l
1068
+ #
1006
1069
 
1070
+ def _unpack_isinstance_spec(self, spec: ta.Any) -> tuple:
1071
+ if isinstance(spec, type):
1072
+ return (spec,)
1073
+ if not isinstance(spec, tuple):
1074
+ spec = (spec,)
1075
+ if None in spec:
1076
+ spec = tuple(filter(None, spec)) + (None.__class__,) # noqa
1077
+ if ta.Any in spec:
1078
+ spec = (object,)
1079
+ return spec
1080
+
1081
+ def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> T: # noqa
1082
+ if not isinstance(v, self._unpack_isinstance_spec(spec)):
1083
+ self._raise(
1084
+ TypeError,
1085
+ 'Must be instance',
1086
+ msg,
1087
+ Checks._ArgsKwargs(v, spec),
1088
+ render_fmt='not isinstance(%s, %s)',
1089
+ )
1007
1090
 
1008
- def check_not_equal(l: T, r: T) -> T:
1009
- if l == r:
1010
- raise ValueError(l, r)
1011
- return l
1091
+ return v
1012
1092
 
1093
+ def of_isinstance(self, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
1094
+ def inner(v):
1095
+ return self.isinstance(v, self._unpack_isinstance_spec(spec), msg)
1013
1096
 
1014
- def check_is(l: T, r: T) -> T:
1015
- if l is not r:
1016
- raise ValueError(l, r)
1017
- return l
1097
+ return inner
1018
1098
 
1099
+ def cast(self, v: ta.Any, cls: ta.Type[T], msg: CheckMessage = None) -> T: # noqa
1100
+ if not isinstance(v, cls):
1101
+ self._raise(
1102
+ TypeError,
1103
+ 'Must be instance',
1104
+ msg,
1105
+ Checks._ArgsKwargs(v, cls),
1106
+ )
1019
1107
 
1020
- def check_is_not(l: T, r: ta.Any) -> T:
1021
- if l is r:
1022
- raise ValueError(l, r)
1023
- return l
1108
+ return v
1024
1109
 
1110
+ def of_cast(self, cls: ta.Type[T], msg: CheckMessage = None) -> ta.Callable[[T], T]:
1111
+ def inner(v):
1112
+ return self.cast(v, cls, msg)
1025
1113
 
1026
- def check_in(v: T, c: ta.Container[T]) -> T:
1027
- if v not in c:
1028
- raise ValueError(v, c)
1029
- return v
1114
+ return inner
1030
1115
 
1116
+ def not_isinstance(self, v: T, spec: ta.Any, msg: CheckMessage = None) -> T: # noqa
1117
+ if isinstance(v, self._unpack_isinstance_spec(spec)):
1118
+ self._raise(
1119
+ TypeError,
1120
+ 'Must not be instance',
1121
+ msg,
1122
+ Checks._ArgsKwargs(v, spec),
1123
+ render_fmt='isinstance(%s, %s)',
1124
+ )
1031
1125
 
1032
- def check_not_in(v: T, c: ta.Container[T]) -> T:
1033
- if v in c:
1034
- raise ValueError(v, c)
1035
- return v
1126
+ return v
1036
1127
 
1128
+ def of_not_isinstance(self, spec: ta.Any, msg: CheckMessage = None) -> ta.Callable[[T], T]:
1129
+ def inner(v):
1130
+ return self.not_isinstance(v, self._unpack_isinstance_spec(spec), msg)
1037
1131
 
1038
- def check_single(vs: ta.Iterable[T]) -> T:
1039
- [v] = vs
1040
- return v
1132
+ return inner
1041
1133
 
1134
+ ##
1135
+
1136
+ def issubclass(self, v: ta.Type[T], spec: ta.Any, msg: CheckMessage = None) -> ta.Type[T]: # noqa
1137
+ if not issubclass(v, spec):
1138
+ self._raise(
1139
+ TypeError,
1140
+ 'Must be subclass',
1141
+ msg,
1142
+ Checks._ArgsKwargs(v, spec),
1143
+ render_fmt='not issubclass(%s, %s)',
1144
+ )
1145
+
1146
+ return v
1147
+
1148
+ def not_issubclass(self, v: ta.Type[T], spec: ta.Any, msg: CheckMessage = None) -> ta.Type[T]: # noqa
1149
+ if issubclass(v, spec):
1150
+ self._raise(
1151
+ TypeError,
1152
+ 'Must not be subclass',
1153
+ msg,
1154
+ Checks._ArgsKwargs(v, spec),
1155
+ render_fmt='issubclass(%s, %s)',
1156
+ )
1157
+
1158
+ return v
1159
+
1160
+ #
1161
+
1162
+ def in_(self, v: T, c: ta.Container[T], msg: CheckMessage = None) -> T:
1163
+ if v not in c:
1164
+ self._raise(
1165
+ ValueError,
1166
+ 'Must be in',
1167
+ msg,
1168
+ Checks._ArgsKwargs(v, c),
1169
+ render_fmt='%s not in %s',
1170
+ )
1171
+
1172
+ return v
1173
+
1174
+ def not_in(self, v: T, c: ta.Container[T], msg: CheckMessage = None) -> T:
1175
+ if v in c:
1176
+ self._raise(
1177
+ ValueError,
1178
+ 'Must not be in',
1179
+ msg,
1180
+ Checks._ArgsKwargs(v, c),
1181
+ render_fmt='%s in %s',
1182
+ )
1183
+
1184
+ return v
1185
+
1186
+ def empty(self, v: SizedT, msg: CheckMessage = None) -> SizedT:
1187
+ if len(v) != 0:
1188
+ self._raise(
1189
+ ValueError,
1190
+ 'Must be empty',
1191
+ msg,
1192
+ Checks._ArgsKwargs(v),
1193
+ render_fmt='%s',
1194
+ )
1195
+
1196
+ return v
1197
+
1198
+ def iterempty(self, v: ta.Iterable[T], msg: CheckMessage = None) -> ta.Iterable[T]:
1199
+ it = iter(v)
1200
+ try:
1201
+ next(it)
1202
+ except StopIteration:
1203
+ pass
1204
+ else:
1205
+ self._raise(
1206
+ ValueError,
1207
+ 'Must be empty',
1208
+ msg,
1209
+ Checks._ArgsKwargs(v),
1210
+ render_fmt='%s',
1211
+ )
1212
+
1213
+ return v
1214
+
1215
+ def not_empty(self, v: SizedT, msg: CheckMessage = None) -> SizedT:
1216
+ if len(v) == 0:
1217
+ self._raise(
1218
+ ValueError,
1219
+ 'Must not be empty',
1220
+ msg,
1221
+ Checks._ArgsKwargs(v),
1222
+ render_fmt='%s',
1223
+ )
1042
1224
 
1043
- def check_empty(v: SizedT) -> SizedT:
1044
- if len(v):
1045
- raise ValueError(v)
1046
- return v
1225
+ return v
1226
+
1227
+ def unique(self, it: ta.Iterable[T], msg: CheckMessage = None) -> ta.Iterable[T]:
1228
+ dupes = [e for e, c in collections.Counter(it).items() if c > 1]
1229
+ if dupes:
1230
+ self._raise(
1231
+ ValueError,
1232
+ 'Must be unique',
1233
+ msg,
1234
+ Checks._ArgsKwargs(it, dupes),
1235
+ )
1236
+
1237
+ return it
1238
+
1239
+ def single(self, obj: ta.Iterable[T], message: CheckMessage = None) -> T:
1240
+ try:
1241
+ [value] = obj
1242
+ except ValueError:
1243
+ self._raise(
1244
+ ValueError,
1245
+ 'Must be single',
1246
+ message,
1247
+ Checks._ArgsKwargs(obj),
1248
+ render_fmt='%s',
1249
+ )
1250
+
1251
+ return value
1252
+
1253
+ def opt_single(self, obj: ta.Iterable[T], message: CheckMessage = None) -> ta.Optional[T]:
1254
+ it = iter(obj)
1255
+ try:
1256
+ value = next(it)
1257
+ except StopIteration:
1258
+ return None
1259
+
1260
+ try:
1261
+ next(it)
1262
+ except StopIteration:
1263
+ return value # noqa
1264
+
1265
+ self._raise(
1266
+ ValueError,
1267
+ 'Must be empty or single',
1268
+ message,
1269
+ Checks._ArgsKwargs(obj),
1270
+ render_fmt='%s',
1271
+ )
1272
+
1273
+ raise RuntimeError # noqa
1274
+
1275
+ #
1276
+
1277
+ def none(self, v: ta.Any, msg: CheckMessage = None) -> None:
1278
+ if v is not None:
1279
+ self._raise(
1280
+ ValueError,
1281
+ 'Must be None',
1282
+ msg,
1283
+ Checks._ArgsKwargs(v),
1284
+ render_fmt='%s',
1285
+ )
1286
+
1287
+ def not_none(self, v: ta.Optional[T], msg: CheckMessage = None) -> T:
1288
+ if v is None:
1289
+ self._raise(
1290
+ ValueError,
1291
+ 'Must not be None',
1292
+ msg,
1293
+ Checks._ArgsKwargs(v),
1294
+ render_fmt='%s',
1295
+ )
1296
+
1297
+ return v
1298
+
1299
+ #
1300
+
1301
+ def equal(self, v: T, o: ta.Any, msg: CheckMessage = None) -> T:
1302
+ if o != v:
1303
+ self._raise(
1304
+ ValueError,
1305
+ 'Must be equal',
1306
+ msg,
1307
+ Checks._ArgsKwargs(v, o),
1308
+ render_fmt='%s != %s',
1309
+ )
1310
+
1311
+ return v
1312
+
1313
+ def is_(self, v: T, o: ta.Any, msg: CheckMessage = None) -> T:
1314
+ if o is not v:
1315
+ self._raise(
1316
+ ValueError,
1317
+ 'Must be the same',
1318
+ msg,
1319
+ Checks._ArgsKwargs(v, o),
1320
+ render_fmt='%s is not %s',
1321
+ )
1322
+
1323
+ return v
1324
+
1325
+ def is_not(self, v: T, o: ta.Any, msg: CheckMessage = None) -> T:
1326
+ if o is v:
1327
+ self._raise(
1328
+ ValueError,
1329
+ 'Must not be the same',
1330
+ msg,
1331
+ Checks._ArgsKwargs(v, o),
1332
+ render_fmt='%s is %s',
1333
+ )
1334
+
1335
+ return v
1336
+
1337
+ def callable(self, v: T, msg: CheckMessage = None) -> T: # noqa
1338
+ if not callable(v):
1339
+ self._raise(
1340
+ TypeError,
1341
+ 'Must be callable',
1342
+ msg,
1343
+ Checks._ArgsKwargs(v),
1344
+ render_fmt='%s',
1345
+ )
1346
+
1347
+ return v # type: ignore
1348
+
1349
+ def non_empty_str(self, v: ta.Optional[str], msg: CheckMessage = None) -> str:
1350
+ if not isinstance(v, str) or not v:
1351
+ self._raise(
1352
+ ValueError,
1353
+ 'Must be non-empty str',
1354
+ msg,
1355
+ Checks._ArgsKwargs(v),
1356
+ render_fmt='%s',
1357
+ )
1358
+
1359
+ return v
1360
+
1361
+ def replacing(self, expected: ta.Any, old: ta.Any, new: T, msg: CheckMessage = None) -> T:
1362
+ if old != expected:
1363
+ self._raise(
1364
+ ValueError,
1365
+ 'Must be replacing',
1366
+ msg,
1367
+ Checks._ArgsKwargs(expected, old, new),
1368
+ render_fmt='%s -> %s -> %s',
1369
+ )
1370
+
1371
+ return new
1372
+
1373
+ def replacing_none(self, old: ta.Any, new: T, msg: CheckMessage = None) -> T:
1374
+ if old is not None:
1375
+ self._raise(
1376
+ ValueError,
1377
+ 'Must be replacing None',
1378
+ msg,
1379
+ Checks._ArgsKwargs(old, new),
1380
+ render_fmt='%s -> %s',
1381
+ )
1382
+
1383
+ return new
1384
+
1385
+ #
1386
+
1387
+ def arg(self, v: bool, msg: CheckMessage = None) -> None:
1388
+ if not v:
1389
+ self._raise(
1390
+ RuntimeError,
1391
+ 'Argument condition not met',
1392
+ msg,
1393
+ Checks._ArgsKwargs(v),
1394
+ render_fmt='%s',
1395
+ )
1396
+
1397
+ def state(self, v: bool, msg: CheckMessage = None) -> None:
1398
+ if not v:
1399
+ self._raise(
1400
+ RuntimeError,
1401
+ 'State condition not met',
1402
+ msg,
1403
+ Checks._ArgsKwargs(v),
1404
+ render_fmt='%s',
1405
+ )
1047
1406
 
1048
1407
 
1049
- def check_not_empty(v: SizedT) -> SizedT:
1050
- if not len(v):
1051
- raise ValueError(v)
1052
- return v
1408
+ check = Checks()
1053
1409
 
1054
1410
 
1055
1411
  ########################################
@@ -1324,7 +1680,7 @@ class AwsSigner:
1324
1680
  @staticmethod
1325
1681
  def _host_from_url(url: str) -> str:
1326
1682
  url_parts = urllib.parse.urlsplit(url)
1327
- host = check_non_empty_str(url_parts.hostname)
1683
+ host = check.non_empty_str(url_parts.hostname)
1328
1684
  default_ports = {
1329
1685
  'http': 80,
1330
1686
  'https': 443,
@@ -1338,7 +1694,7 @@ class AwsSigner:
1338
1694
  def _lower_case_http_map(d: ta.Mapping[str, ta.Sequence[str]]) -> ta.Mapping[str, ta.Sequence[str]]:
1339
1695
  o: ta.Dict[str, ta.List[str]] = {}
1340
1696
  for k, vs in d.items():
1341
- o.setdefault(k.lower(), []).extend(check_not_isinstance(vs, str))
1697
+ o.setdefault(k.lower(), []).extend(check.not_isinstance(vs, str))
1342
1698
  return o
1343
1699
 
1344
1700
  #
@@ -1371,12 +1727,12 @@ class AwsSigner:
1371
1727
  ])
1372
1728
 
1373
1729
  def _validate_request(self, req: Request) -> None:
1374
- check_non_empty_str(req.method)
1375
- check_equal(req.method.upper(), req.method)
1730
+ check.non_empty_str(req.method)
1731
+ check.equal(req.method.upper(), req.method)
1376
1732
  for k, vs in req.headers.items():
1377
- check_equal(k.strip(), k)
1733
+ check.equal(k.strip(), k)
1378
1734
  for v in vs:
1379
- check_equal(v.strip(), v)
1735
+ check.equal(v.strip(), v)
1380
1736
 
1381
1737
 
1382
1738
  AwsSigner._EMPTY_SHA256 = AwsSigner._sha256(b'') # noqa
@@ -1669,7 +2025,7 @@ class DelimitingBuffer:
1669
2025
  ) -> None:
1670
2026
  super().__init__()
1671
2027
 
1672
- self._delimiters = frozenset(check_isinstance(d, int) for d in delimiters)
2028
+ self._delimiters = frozenset(check.isinstance(d, int) for d in delimiters)
1673
2029
  self._keep_ends = keep_ends
1674
2030
  self._max_size = max_size
1675
2031
 
@@ -1700,7 +2056,7 @@ class DelimitingBuffer:
1700
2056
  return r
1701
2057
 
1702
2058
  def _append_and_reset(self, chunk: bytes) -> bytes:
1703
- buf = check_not_none(self._buf)
2059
+ buf = check.not_none(self._buf)
1704
2060
  if not buf.tell():
1705
2061
  return chunk
1706
2062
 
@@ -1822,7 +2178,7 @@ class IncrementalWriteBuffer:
1822
2178
  ) -> None:
1823
2179
  super().__init__()
1824
2180
 
1825
- check_not_empty(data)
2181
+ check.not_empty(data)
1826
2182
  self._len = len(data)
1827
2183
  self._write_size = write_size
1828
2184
 
@@ -1837,11 +2193,11 @@ class IncrementalWriteBuffer:
1837
2193
  return self._len - self._pos
1838
2194
 
1839
2195
  def write(self, fn: ta.Callable[[bytes], int]) -> int:
1840
- lst = check_not_empty(self._lst)
2196
+ lst = check.not_empty(self._lst)
1841
2197
 
1842
2198
  t = 0
1843
2199
  for i, d in enumerate(lst): # noqa
1844
- n = fn(check_not_empty(d))
2200
+ n = fn(check.not_empty(d))
1845
2201
  if not n:
1846
2202
  break
1847
2203
  t += n
@@ -1867,7 +2223,7 @@ class ExitStacked:
1867
2223
  _exit_stack: ta.Optional[contextlib.ExitStack] = None
1868
2224
 
1869
2225
  def __enter__(self: ExitStackedT) -> ExitStackedT:
1870
- check_state(self._exit_stack is None)
2226
+ check.state(self._exit_stack is None)
1871
2227
  es = self._exit_stack = contextlib.ExitStack()
1872
2228
  es.__enter__()
1873
2229
  return self
@@ -1882,7 +2238,7 @@ class ExitStacked:
1882
2238
  pass
1883
2239
 
1884
2240
  def _enter_context(self, cm: ta.ContextManager[T]) -> T:
1885
- es = check_not_none(self._exit_stack)
2241
+ es = check.not_none(self._exit_stack)
1886
2242
  return es.enter_context(cm)
1887
2243
 
1888
2244
 
@@ -2225,10 +2581,10 @@ class ProxyObjMarshaler(ObjMarshaler):
2225
2581
  m: ta.Optional[ObjMarshaler] = None
2226
2582
 
2227
2583
  def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2228
- return check_not_none(self.m).marshal(o, ctx)
2584
+ return check.not_none(self.m).marshal(o, ctx)
2229
2585
 
2230
2586
  def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2231
- return check_not_none(self.m).unmarshal(o, ctx)
2587
+ return check.not_none(self.m).unmarshal(o, ctx)
2232
2588
 
2233
2589
 
2234
2590
  @dc.dataclass(frozen=True)
@@ -2387,19 +2743,19 @@ class DatetimeObjMarshaler(ObjMarshaler):
2387
2743
 
2388
2744
  class DecimalObjMarshaler(ObjMarshaler):
2389
2745
  def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2390
- return str(check_isinstance(o, decimal.Decimal))
2746
+ return str(check.isinstance(o, decimal.Decimal))
2391
2747
 
2392
2748
  def unmarshal(self, v: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2393
- return decimal.Decimal(check_isinstance(v, str))
2749
+ return decimal.Decimal(check.isinstance(v, str))
2394
2750
 
2395
2751
 
2396
2752
  class FractionObjMarshaler(ObjMarshaler):
2397
2753
  def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2398
- fr = check_isinstance(o, fractions.Fraction)
2754
+ fr = check.isinstance(o, fractions.Fraction)
2399
2755
  return [fr.numerator, fr.denominator]
2400
2756
 
2401
2757
  def unmarshal(self, v: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
2402
- num, denom = check_isinstance(v, list)
2758
+ num, denom = check.isinstance(v, list)
2403
2759
  return fractions.Fraction(num, denom)
2404
2760
 
2405
2761
 
@@ -2775,8 +3131,8 @@ class AwsLogMessageBuilder:
2775
3131
  ) -> None:
2776
3132
  super().__init__()
2777
3133
 
2778
- self._log_group_name = check_non_empty_str(log_group_name)
2779
- self._log_stream_name = check_non_empty_str(log_stream_name)
3134
+ self._log_group_name = check.non_empty_str(log_group_name)
3135
+ self._log_stream_name = check.non_empty_str(log_stream_name)
2780
3136
 
2781
3137
  if url is None:
2782
3138
  url = self.DEFAULT_URL.format(region_name=region_name)
@@ -2850,7 +3206,7 @@ class AwsLogMessageBuilder:
2850
3206
 
2851
3207
  post = AwsLogMessageBuilder.Post(
2852
3208
  url=self._url,
2853
- headers={k: check_single(v) for k, v in sig_req.headers.items()},
3209
+ headers={k: check.single(v) for k, v in sig_req.headers.items()},
2854
3210
  data=sig_req.payload,
2855
3211
  )
2856
3212
 
@@ -2918,7 +3274,7 @@ def build_config_named_children(
2918
3274
  lst: ta.List[ConfigMapping] = []
2919
3275
  if isinstance(o, ta.Mapping):
2920
3276
  for k, v in o.items():
2921
- check_isinstance(v, ta.Mapping)
3277
+ check.isinstance(v, ta.Mapping)
2922
3278
  if name_key in v:
2923
3279
  n = v[name_key]
2924
3280
  if k != n:
@@ -2928,7 +3284,7 @@ def build_config_named_children(
2928
3284
  lst.append({name_key: k, **v})
2929
3285
 
2930
3286
  else:
2931
- check_not_isinstance(o, str)
3287
+ check.not_isinstance(o, str)
2932
3288
  lst.extend(o)
2933
3289
 
2934
3290
  seen = set()
@@ -3010,7 +3366,7 @@ class JournalctlMessageBuilder:
3010
3366
  def feed(self, data: bytes) -> ta.Sequence[JournalctlMessage]:
3011
3367
  ret: ta.List[JournalctlMessage] = []
3012
3368
  for line in self._buf.feed(data):
3013
- ret.append(self._make_message(check_isinstance(line, bytes)))
3369
+ ret.append(self._make_message(check.isinstance(line, bytes)))
3014
3370
  return ret
3015
3371
 
3016
3372
 
@@ -3948,7 +4304,7 @@ class JournalctlTailerWorker(ThreadWorker):
3948
4304
  stdout=subprocess.PIPE,
3949
4305
  ) as self._proc:
3950
4306
  try:
3951
- stdout = check_not_none(self._proc.stdout)
4307
+ stdout = check.not_none(self._proc.stdout)
3952
4308
 
3953
4309
  fd = stdout.fileno()
3954
4310
  fl = fcntl.fcntl(fd, fcntl.F_GETFL)
@@ -4080,15 +4436,15 @@ class JournalctlToAwsDriver(ExitStacked):
4080
4436
  return None
4081
4437
 
4082
4438
  return AwsSigner.Credentials(
4083
- access_key_id=check_non_empty_str(self._config.aws_access_key_id),
4084
- secret_access_key=check_non_empty_str(self._config.aws_secret_access_key),
4439
+ access_key_id=check.non_empty_str(self._config.aws_access_key_id),
4440
+ secret_access_key=check.non_empty_str(self._config.aws_secret_access_key),
4085
4441
  )
4086
4442
 
4087
4443
  @cached_nullary
4088
4444
  def _aws_log_message_builder(self) -> AwsLogMessageBuilder:
4089
4445
  return AwsLogMessageBuilder(
4090
4446
  log_group_name=self._config.aws_log_group_name,
4091
- log_stream_name=check_non_empty_str(self._config.aws_log_stream_name),
4447
+ log_stream_name=check.non_empty_str(self._config.aws_log_stream_name),
4092
4448
  region_name=self._config.aws_region_name,
4093
4449
  credentials=self._aws_credentials(),
4094
4450
  )