omlish 0.0.0.dev132__py3-none-any.whl → 0.0.0.dev177__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. omlish/.manifests.json +265 -7
  2. omlish/__about__.py +7 -5
  3. omlish/antlr/_runtime/__init__.py +0 -22
  4. omlish/antlr/_runtime/_all.py +24 -0
  5. omlish/antlr/_runtime/atn/ParserATNSimulator.py +1 -1
  6. omlish/antlr/_runtime/dfa/DFASerializer.py +1 -1
  7. omlish/antlr/_runtime/error/DiagnosticErrorListener.py +2 -1
  8. omlish/antlr/_runtime/xpath/XPath.py +7 -1
  9. omlish/antlr/_runtime/xpath/XPathLexer.py +1 -1
  10. omlish/antlr/delimit.py +106 -0
  11. omlish/antlr/dot.py +31 -0
  12. omlish/antlr/errors.py +11 -0
  13. omlish/antlr/input.py +96 -0
  14. omlish/antlr/parsing.py +19 -0
  15. omlish/antlr/runtime.py +102 -0
  16. omlish/antlr/utils.py +38 -0
  17. omlish/argparse/all.py +45 -0
  18. omlish/{argparse.py → argparse/cli.py} +112 -107
  19. omlish/asyncs/__init__.py +0 -35
  20. omlish/asyncs/all.py +35 -0
  21. omlish/asyncs/asyncio/all.py +7 -0
  22. omlish/asyncs/asyncio/channels.py +40 -0
  23. omlish/asyncs/asyncio/streams.py +45 -0
  24. omlish/asyncs/asyncio/subprocesses.py +238 -0
  25. omlish/asyncs/asyncio/timeouts.py +16 -0
  26. omlish/asyncs/bluelet/LICENSE +6 -0
  27. omlish/asyncs/bluelet/all.py +67 -0
  28. omlish/asyncs/bluelet/api.py +23 -0
  29. omlish/asyncs/bluelet/core.py +178 -0
  30. omlish/asyncs/bluelet/events.py +78 -0
  31. omlish/asyncs/bluelet/files.py +80 -0
  32. omlish/asyncs/bluelet/runner.py +416 -0
  33. omlish/asyncs/bluelet/sockets.py +214 -0
  34. omlish/bootstrap/sys.py +3 -3
  35. omlish/cached.py +2 -2
  36. omlish/check.py +49 -460
  37. omlish/codecs/__init__.py +72 -0
  38. omlish/codecs/base.py +106 -0
  39. omlish/codecs/bytes.py +119 -0
  40. omlish/codecs/chain.py +23 -0
  41. omlish/codecs/funcs.py +39 -0
  42. omlish/codecs/registry.py +139 -0
  43. omlish/codecs/standard.py +4 -0
  44. omlish/codecs/text.py +217 -0
  45. omlish/collections/cache/impl.py +50 -57
  46. omlish/collections/coerce.py +1 -0
  47. omlish/collections/mappings.py +1 -1
  48. omlish/configs/flattening.py +1 -1
  49. omlish/defs.py +1 -1
  50. omlish/diag/_pycharm/runhack.py +8 -2
  51. omlish/diag/procfs.py +8 -8
  52. omlish/docker/__init__.py +0 -36
  53. omlish/docker/all.py +31 -0
  54. omlish/docker/consts.py +4 -0
  55. omlish/{lite/docker.py → docker/detect.py} +18 -0
  56. omlish/docker/{helpers.py → timebomb.py} +0 -21
  57. omlish/formats/cbor.py +31 -0
  58. omlish/formats/cloudpickle.py +31 -0
  59. omlish/formats/codecs.py +93 -0
  60. omlish/formats/json/codecs.py +29 -0
  61. omlish/formats/json/delimted.py +4 -0
  62. omlish/formats/json/stream/errors.py +2 -0
  63. omlish/formats/json/stream/lex.py +12 -6
  64. omlish/formats/json/stream/parse.py +38 -22
  65. omlish/formats/json5.py +31 -0
  66. omlish/formats/pickle.py +31 -0
  67. omlish/formats/repr.py +25 -0
  68. omlish/formats/toml.py +17 -0
  69. omlish/formats/yaml.py +25 -0
  70. omlish/funcs/__init__.py +0 -0
  71. omlish/{genmachine.py → funcs/genmachine.py} +5 -4
  72. omlish/{matchfns.py → funcs/match.py} +1 -1
  73. omlish/funcs/pairs.py +215 -0
  74. omlish/http/__init__.py +0 -48
  75. omlish/http/all.py +48 -0
  76. omlish/http/coro/__init__.py +0 -0
  77. omlish/{lite/fdio/corohttp.py → http/coro/fdio.py} +21 -19
  78. omlish/{lite/http/coroserver.py → http/coro/server.py} +20 -21
  79. omlish/{lite/http → http}/handlers.py +3 -2
  80. omlish/{lite/http → http}/parsing.py +1 -0
  81. omlish/http/sessions.py +1 -1
  82. omlish/{lite/http → http}/versions.py +1 -0
  83. omlish/inject/managed.py +2 -2
  84. omlish/io/__init__.py +0 -3
  85. omlish/{lite/io.py → io/buffers.py} +8 -9
  86. omlish/io/compress/__init__.py +9 -0
  87. omlish/io/compress/abc.py +104 -0
  88. omlish/io/compress/adapters.py +148 -0
  89. omlish/io/compress/base.py +24 -0
  90. omlish/io/compress/brotli.py +47 -0
  91. omlish/io/compress/bz2.py +61 -0
  92. omlish/io/compress/codecs.py +78 -0
  93. omlish/io/compress/gzip.py +350 -0
  94. omlish/io/compress/lz4.py +91 -0
  95. omlish/io/compress/lzma.py +81 -0
  96. omlish/io/compress/snappy.py +34 -0
  97. omlish/io/compress/zlib.py +74 -0
  98. omlish/io/compress/zstd.py +44 -0
  99. omlish/io/fdio/__init__.py +1 -0
  100. omlish/{lite → io}/fdio/handlers.py +5 -5
  101. omlish/{lite → io}/fdio/kqueue.py +8 -8
  102. omlish/{lite → io}/fdio/manager.py +7 -7
  103. omlish/{lite → io}/fdio/pollers.py +13 -13
  104. omlish/io/generators/__init__.py +56 -0
  105. omlish/io/generators/consts.py +1 -0
  106. omlish/io/generators/direct.py +13 -0
  107. omlish/io/generators/readers.py +189 -0
  108. omlish/io/generators/stepped.py +191 -0
  109. omlish/io/pyio.py +5 -2
  110. omlish/iterators/__init__.py +24 -0
  111. omlish/iterators/iterators.py +132 -0
  112. omlish/iterators/recipes.py +18 -0
  113. omlish/iterators/tools.py +96 -0
  114. omlish/iterators/unique.py +67 -0
  115. omlish/lang/__init__.py +13 -1
  116. omlish/lang/functions.py +11 -2
  117. omlish/lang/generators.py +243 -0
  118. omlish/lang/iterables.py +46 -49
  119. omlish/lang/maybes.py +4 -4
  120. omlish/lite/cached.py +39 -6
  121. omlish/lite/check.py +438 -75
  122. omlish/lite/contextmanagers.py +17 -4
  123. omlish/lite/dataclasses.py +42 -0
  124. omlish/lite/inject.py +28 -45
  125. omlish/lite/logs.py +0 -270
  126. omlish/lite/marshal.py +309 -144
  127. omlish/lite/pycharm.py +47 -0
  128. omlish/lite/reflect.py +33 -0
  129. omlish/lite/resources.py +8 -0
  130. omlish/lite/runtime.py +4 -4
  131. omlish/lite/shlex.py +12 -0
  132. omlish/lite/socketserver.py +2 -2
  133. omlish/lite/strings.py +31 -0
  134. omlish/logs/__init__.py +0 -32
  135. omlish/logs/{_abc.py → abc.py} +0 -1
  136. omlish/logs/all.py +37 -0
  137. omlish/logs/{formatters.py → color.py} +1 -2
  138. omlish/logs/configs.py +7 -38
  139. omlish/logs/filters.py +10 -0
  140. omlish/logs/handlers.py +4 -1
  141. omlish/logs/json.py +56 -0
  142. omlish/logs/proxy.py +99 -0
  143. omlish/logs/standard.py +128 -0
  144. omlish/logs/utils.py +2 -2
  145. omlish/manifests/__init__.py +2 -0
  146. omlish/manifests/load.py +209 -0
  147. omlish/manifests/types.py +17 -0
  148. omlish/marshal/base.py +1 -1
  149. omlish/marshal/factories.py +1 -1
  150. omlish/marshal/forbidden.py +1 -1
  151. omlish/marshal/iterables.py +1 -1
  152. omlish/marshal/literals.py +50 -0
  153. omlish/marshal/mappings.py +1 -1
  154. omlish/marshal/maybes.py +1 -1
  155. omlish/marshal/standard.py +5 -1
  156. omlish/marshal/unions.py +1 -1
  157. omlish/os/__init__.py +0 -0
  158. omlish/os/atomics.py +205 -0
  159. omlish/os/deathsig.py +23 -0
  160. omlish/{os.py → os/files.py} +0 -9
  161. omlish/{lite → os}/journald.py +2 -1
  162. omlish/os/linux.py +484 -0
  163. omlish/os/paths.py +36 -0
  164. omlish/{lite → os}/pidfile.py +1 -0
  165. omlish/os/sizes.py +9 -0
  166. omlish/reflect/__init__.py +3 -0
  167. omlish/reflect/subst.py +2 -1
  168. omlish/reflect/types.py +126 -44
  169. omlish/secrets/pwhash.py +1 -1
  170. omlish/secrets/subprocesses.py +3 -1
  171. omlish/specs/jsonrpc/marshal.py +1 -1
  172. omlish/specs/openapi/marshal.py +1 -1
  173. omlish/sql/alchemy/asyncs.py +1 -1
  174. omlish/sql/queries/__init__.py +9 -1
  175. omlish/sql/queries/building.py +3 -0
  176. omlish/sql/queries/exprs.py +10 -27
  177. omlish/sql/queries/idents.py +48 -10
  178. omlish/sql/queries/names.py +80 -13
  179. omlish/sql/queries/params.py +64 -0
  180. omlish/sql/queries/rendering.py +1 -1
  181. omlish/subprocesses.py +340 -0
  182. omlish/term.py +29 -14
  183. omlish/testing/pytest/marks.py +2 -2
  184. omlish/testing/pytest/plugins/asyncs.py +6 -1
  185. omlish/testing/pytest/plugins/logging.py +1 -1
  186. omlish/testing/pytest/plugins/switches.py +1 -1
  187. {omlish-0.0.0.dev132.dist-info → omlish-0.0.0.dev177.dist-info}/METADATA +13 -11
  188. {omlish-0.0.0.dev132.dist-info → omlish-0.0.0.dev177.dist-info}/RECORD +200 -117
  189. omlish/fnpairs.py +0 -496
  190. omlish/formats/json/cli/__main__.py +0 -11
  191. omlish/formats/json/cli/cli.py +0 -298
  192. omlish/formats/json/cli/formats.py +0 -71
  193. omlish/formats/json/cli/io.py +0 -74
  194. omlish/formats/json/cli/parsing.py +0 -82
  195. omlish/formats/json/cli/processing.py +0 -48
  196. omlish/formats/json/cli/rendering.py +0 -92
  197. omlish/iterators.py +0 -300
  198. omlish/lite/subprocesses.py +0 -130
  199. /omlish/{formats/json/cli → argparse}/__init__.py +0 -0
  200. /omlish/{lite/fdio → asyncs/asyncio}/__init__.py +0 -0
  201. /omlish/asyncs/{asyncio.py → asyncio/asyncio.py} +0 -0
  202. /omlish/{lite/http → asyncs/bluelet}/__init__.py +0 -0
  203. /omlish/collections/{_abc.py → abc.py} +0 -0
  204. /omlish/{fnpipes.py → funcs/pipes.py} +0 -0
  205. /omlish/io/{_abc.py → abc.py} +0 -0
  206. /omlish/sql/{_abc.py → abc.py} +0 -0
  207. {omlish-0.0.0.dev132.dist-info → omlish-0.0.0.dev177.dist-info}/LICENSE +0 -0
  208. {omlish-0.0.0.dev132.dist-info → omlish-0.0.0.dev177.dist-info}/WHEEL +0 -0
  209. {omlish-0.0.0.dev132.dist-info → omlish-0.0.0.dev177.dist-info}/entry_points.txt +0 -0
  210. {omlish-0.0.0.dev132.dist-info → omlish-0.0.0.dev177.dist-info}/top_level.txt +0 -0
omlish/fnpairs.py DELETED
@@ -1,496 +0,0 @@
1
- """
2
- TODO:
3
- - objects
4
- - csv
5
- - csvloader
6
- - wrapped (wait for usecase)
7
- - streams / incremental
8
- - fileobj -> fileobj?
9
- - swap zstandard for zstd
10
-
11
- Compression choice:
12
- - lzma if-available minimal-space
13
- - lz4 if-available write-once
14
- - zstd if-available
15
- - bz2 write-once (but no parallel decompress)
16
- - gz
17
- """
18
- import abc
19
- import codecs
20
- import dataclasses as dc
21
- import typing as ta
22
-
23
- from . import lang
24
-
25
-
26
- if ta.TYPE_CHECKING:
27
- import bz2 as _bz2
28
- import gzip as _gzip
29
- import lzma as _lzma
30
- import pickle as _pickle
31
- import struct as _struct
32
- import tomllib as _tomllib
33
-
34
- import cbor2 as _cbor2
35
- import cloudpickle as _cloudpickle
36
- import json5 as _json5
37
- import lz4.frame as _lz4_frame
38
- import snappy as _snappy
39
- import yaml as _yaml
40
- import zstandard as _zstandard
41
-
42
- from .formats import json as _json
43
-
44
- else:
45
- _bz2 = lang.proxy_import('bz2')
46
- _gzip = lang.proxy_import('gzip')
47
- _lzma = lang.proxy_import('lzma')
48
- _pickle = lang.proxy_import('pickle')
49
- _struct = lang.proxy_import('struct')
50
- _tomllib = lang.proxy_import('tomllib')
51
-
52
- _cbor2 = lang.proxy_import('cbor2')
53
- _cloudpickle = lang.proxy_import('cloudpickle')
54
- _json5 = lang.proxy_import('json5')
55
- _lz4_frame = lang.proxy_import('lz4.frame')
56
- _snappy = lang.proxy_import('snappy')
57
- _yaml = lang.proxy_import('yaml')
58
- _zstandard = lang.proxy_import('zstandard')
59
-
60
- _json = lang.proxy_import('.formats.json', __package__)
61
-
62
-
63
- ##
64
-
65
-
66
- F = ta.TypeVar('F')
67
- T = ta.TypeVar('T')
68
- U = ta.TypeVar('U')
69
-
70
-
71
- class FnPair(ta.Generic[F, T], abc.ABC):
72
- @abc.abstractmethod
73
- def forward(self, f: F) -> T:
74
- raise NotImplementedError
75
-
76
- @abc.abstractmethod
77
- def backward(self, t: T) -> F:
78
- raise NotImplementedError
79
-
80
- ##
81
-
82
- def __call__(self, f: F) -> T:
83
- return self.forward(f)
84
-
85
- def invert(self) -> 'FnPair[T, F]':
86
- if isinstance(self, Inverted):
87
- return self.fp
88
- return Inverted(self)
89
-
90
- def compose(self, nxt: 'FnPair[T, U]') -> 'FnPair[F, U]':
91
- return Composite((self, nxt))
92
-
93
-
94
- ##
95
-
96
-
97
- @lang.unabstract_class(['forward', 'backward'])
98
- @dc.dataclass(frozen=True)
99
- class Simple(FnPair[F, T]):
100
- forward: ta.Callable[[F], T] # type: ignore
101
- backward: ta.Callable[[T], F] # type: ignore
102
-
103
-
104
- of = Simple
105
-
106
- NOP: FnPair[ta.Any, ta.Any] = of(lang.identity, lang.identity)
107
-
108
-
109
- ##
110
-
111
-
112
- @dc.dataclass(frozen=True)
113
- class Inverted(FnPair[F, T]):
114
- fp: FnPair[T, F]
115
-
116
- def forward(self, f: F) -> T:
117
- return self.fp.backward(f)
118
-
119
- def backward(self, t: T) -> F:
120
- return self.fp.forward(t)
121
-
122
-
123
- ##
124
-
125
-
126
- @dc.dataclass(frozen=True)
127
- class Composite(FnPair[F, T]):
128
- children: ta.Sequence[FnPair]
129
-
130
- def forward(self, f: F) -> T:
131
- for c in self.children:
132
- f = c.forward(f)
133
- return ta.cast(T, f)
134
-
135
- def backward(self, t: T) -> F:
136
- for c in reversed(self.children):
137
- t = c.backward(t)
138
- return ta.cast(F, t)
139
-
140
-
141
- I0 = ta.TypeVar('I0')
142
- I1 = ta.TypeVar('I1')
143
- I2 = ta.TypeVar('I2')
144
- I3 = ta.TypeVar('I3')
145
- I4 = ta.TypeVar('I4')
146
-
147
-
148
- @ta.overload
149
- def compose(
150
- fp0: FnPair[F, I0],
151
- f01: FnPair[I0, T],
152
- ) -> FnPair[F, T]:
153
- ...
154
-
155
-
156
- @ta.overload
157
- def compose(
158
- fp0: FnPair[F, I0],
159
- f01: FnPair[I0, I1],
160
- fp2: FnPair[I1, T],
161
- ) -> FnPair[F, T]:
162
- ...
163
-
164
-
165
- @ta.overload
166
- def compose(
167
- fp0: FnPair[F, I0],
168
- f01: FnPair[I0, I1],
169
- fp2: FnPair[I1, I2],
170
- fp3: FnPair[I2, T],
171
- ) -> FnPair[F, T]:
172
- ...
173
-
174
-
175
- @ta.overload
176
- def compose(
177
- fp0: FnPair[F, I0],
178
- f01: FnPair[I0, I1],
179
- fp2: FnPair[I1, I2],
180
- fp3: FnPair[I2, I3],
181
- fp4: FnPair[I3, T],
182
- ) -> FnPair[F, T]:
183
- ...
184
-
185
-
186
- @ta.overload
187
- def compose(
188
- fp0: FnPair[F, I0],
189
- f01: FnPair[I0, I1],
190
- fp2: FnPair[I1, I2],
191
- fp3: FnPair[I2, I3],
192
- fp4: FnPair[I3, I4],
193
- fp5: FnPair[I4, T],
194
- ) -> FnPair[F, T]:
195
- ...
196
-
197
-
198
- @ta.overload
199
- def compose(*ps: FnPair) -> FnPair:
200
- ...
201
-
202
-
203
- def compose(*ps):
204
- if not ps:
205
- return NOP
206
- if len(ps) == 1:
207
- return ps[0]
208
- return Composite(ps)
209
-
210
-
211
- ##
212
-
213
-
214
- @dc.dataclass(frozen=True)
215
- class Text(FnPair[str, bytes]):
216
- ci: codecs.CodecInfo
217
- encode_errors: str = dc.field(default='strict', kw_only=True)
218
- decode_errors: str = dc.field(default='strict', kw_only=True)
219
-
220
- def forward(self, f: str) -> bytes:
221
- # Python ignores the returned length:
222
- # https://github.com/python/cpython/blob/7431c3799efbd06ed03ee70b64420f45e83b3667/Python/codecs.c#L424
223
- t, _ = self.ci.encode(f, self.encode_errors)
224
- return t
225
-
226
- def backward(self, t: bytes) -> str:
227
- f, _ = self.ci.decode(t, self.decode_errors)
228
- return f
229
-
230
-
231
- def text(name: str, *, encode_errors: str = 'strict', decode_errors: str = 'strict') -> Text:
232
- ci = codecs.lookup(name)
233
- if not ci._is_text_encoding: # noqa
234
- raise TypeError(f'must be text codec: {name}')
235
- return Text(ci, encode_errors=encode_errors, decode_errors=decode_errors)
236
-
237
-
238
- UTF8 = text('utf-8')
239
-
240
-
241
- #
242
-
243
-
244
- @dc.dataclass(frozen=True)
245
- class Optional(FnPair[F | None, T | None]):
246
- fp: FnPair[F, T]
247
-
248
- def forward(self, f: F | None) -> T | None:
249
- return None if f is None else self.fp.forward(f)
250
-
251
- def backward(self, t: T | None) -> F | None:
252
- return None if t is None else self.fp.backward(t)
253
-
254
-
255
- class Lines(FnPair[ta.Sequence[str], str]):
256
- def forward(self, f: ta.Sequence[str]) -> str:
257
- return '\n'.join(f)
258
-
259
- def backward(self, t: str) -> ta.Sequence[str]:
260
- return t.splitlines()
261
-
262
-
263
- ##
264
-
265
-
266
- _EXTENSION_REGISTRY: dict[str, type[FnPair]] = {}
267
-
268
-
269
- def _register_extension(*ss):
270
- def inner(cls):
271
- for s in ss:
272
- if s in _EXTENSION_REGISTRY:
273
- raise KeyError(s)
274
- _EXTENSION_REGISTRY[s] = cls
275
- return cls
276
- return inner
277
-
278
-
279
- def get_for_extension(ext: str) -> FnPair:
280
- return compose(*[_EXTENSION_REGISTRY[p]() for p in ext.split('.')])
281
-
282
-
283
- ##
284
-
285
-
286
- class Compression(FnPair[bytes, bytes], abc.ABC):
287
- pass
288
-
289
-
290
- @_register_extension('bz2')
291
- @dc.dataclass(frozen=True)
292
- class Bz2(Compression):
293
- compresslevel: int = 9
294
-
295
- def forward(self, f: bytes) -> bytes:
296
- return _bz2.compress(f, compresslevel=self.compresslevel)
297
-
298
- def backward(self, t: bytes) -> bytes:
299
- return _bz2.decompress(t)
300
-
301
-
302
- @_register_extension('gz')
303
- @dc.dataclass(frozen=True)
304
- class Gzip(Compression):
305
- compresslevel: int = 9
306
-
307
- def forward(self, f: bytes) -> bytes:
308
- return _gzip.compress(f, compresslevel=self.compresslevel)
309
-
310
- def backward(self, t: bytes) -> bytes:
311
- return _gzip.decompress(t)
312
-
313
-
314
- @_register_extension('lzma')
315
- class Lzma(Compression):
316
- def forward(self, f: bytes) -> bytes:
317
- return _lzma.compress(f)
318
-
319
- def backward(self, t: bytes) -> bytes:
320
- return _lzma.decompress(t)
321
-
322
-
323
- #
324
-
325
-
326
- @_register_extension('lz4')
327
- @dc.dataclass(frozen=True)
328
- class Lz4(Compression):
329
- compression_level: int = 0
330
-
331
- def forward(self, f: bytes) -> bytes:
332
- return _lz4_frame.compress(f, compression_level=self.compression_level)
333
-
334
- def backward(self, t: bytes) -> bytes:
335
- return _lz4_frame.decompress(t)
336
-
337
-
338
- @_register_extension('snappy')
339
- class Snappy(Compression):
340
- def forward(self, f: bytes) -> bytes:
341
- return _snappy.compress(f)
342
-
343
- def backward(self, t: bytes) -> bytes:
344
- return _snappy.decompress(t)
345
-
346
-
347
- @_register_extension('zstd')
348
- class Zstd(Compression):
349
- def forward(self, f: bytes) -> bytes:
350
- return _zstandard.compress(f)
351
-
352
- def backward(self, t: bytes) -> bytes:
353
- return _zstandard.decompress(t)
354
-
355
-
356
- ##
357
-
358
-
359
- @dc.dataclass(frozen=True)
360
- class Struct(FnPair[tuple, bytes]):
361
- fmt: str
362
-
363
- def forward(self, f: tuple) -> bytes:
364
- return _struct.pack(self.fmt, *f)
365
-
366
- def backward(self, t: bytes) -> tuple:
367
- return _struct.unpack(self.fmt, t)
368
-
369
-
370
- ##
371
-
372
-
373
- Object: ta.TypeAlias = FnPair[ta.Any, T]
374
- ObjectStr: ta.TypeAlias = Object[str]
375
- ObjectBytes: ta.TypeAlias = Object[bytes]
376
-
377
-
378
- class Object_(FnPair[ta.Any, T], lang.Abstract): # noqa
379
- pass
380
-
381
-
382
- class ObjectStr_(Object_[str], lang.Abstract): # noqa
383
- pass
384
-
385
-
386
- class ObjectBytes_(Object_[bytes], lang.Abstract): # noqa
387
- pass
388
-
389
-
390
- #
391
-
392
-
393
- @_register_extension('pkl')
394
- @dc.dataclass(frozen=True)
395
- class Pickle(ObjectBytes_):
396
- protocol: int | None = None
397
-
398
- def forward(self, f: ta.Any) -> bytes:
399
- return _pickle.dumps(f, protocol=self.protocol)
400
-
401
- def backward(self, t: bytes) -> ta.Any:
402
- return _pickle.loads(t)
403
-
404
-
405
- class _Json(ObjectStr_, lang.Abstract): # noqa
406
- def backward(self, t: str) -> ta.Any:
407
- return _json.loads(t)
408
-
409
-
410
- @_register_extension('json')
411
- class Json(_Json):
412
- def forward(self, f: ta.Any) -> str:
413
- return _json.dumps(f)
414
-
415
-
416
- class JsonPretty(_Json):
417
- def forward(self, f: ta.Any) -> str:
418
- return _json.dumps_pretty(f)
419
-
420
-
421
- class JsonCompact(_Json):
422
- def forward(self, f: ta.Any) -> str:
423
- return _json.dumps_compact(f)
424
-
425
-
426
- JSON = Json()
427
- PRETTY_JSON = JsonPretty()
428
- COMPACT_JSON = JsonCompact()
429
-
430
-
431
- @_register_extension('jsonl')
432
- class JsonLines(FnPair[ta.Sequence[ta.Any], str]):
433
- def forward(self, f: ta.Sequence[ta.Any]) -> str:
434
- return '\n'.join(_json.dumps(e) for e in f)
435
-
436
- def backward(self, t: str) -> ta.Sequence[ta.Any]:
437
- return [_json.loads(l) for l in t.splitlines()]
438
-
439
-
440
- @_register_extension('toml')
441
- class Toml(ObjectStr_):
442
- def forward(self, f: ta.Any) -> str:
443
- raise NotImplementedError
444
-
445
- def backward(self, t: str) -> ta.Any:
446
- return _tomllib.loads(t)
447
-
448
-
449
- #
450
-
451
-
452
- @_register_extension('cbor')
453
- class Cbor(ObjectBytes_):
454
- def forward(self, f: ta.Any) -> bytes:
455
- return _cbor2.dumps(f)
456
-
457
- def backward(self, t: bytes) -> ta.Any:
458
- return _cbor2.loads(t)
459
-
460
-
461
- @_register_extension('clpkl')
462
- @dc.dataclass(frozen=True)
463
- class Cloudpickle(ObjectBytes_):
464
- protocol: int | None = None
465
-
466
- def forward(self, f: ta.Any) -> bytes:
467
- return _cloudpickle.dumps(f, protocol=self.protocol)
468
-
469
- def backward(self, t: bytes) -> ta.Any:
470
- return _cloudpickle.loads(t)
471
-
472
-
473
- @_register_extension('json5')
474
- class Json5(ObjectStr_):
475
- def forward(self, f: ta.Any) -> str:
476
- return _json5.dumps(f)
477
-
478
- def backward(self, t: str) -> ta.Any:
479
- return _json5.loads(t)
480
-
481
-
482
- @_register_extension('yml', 'yaml')
483
- class Yaml(ObjectStr_):
484
- def forward(self, f: ta.Any) -> str:
485
- return _yaml.dump(f)
486
-
487
- def backward(self, t: str) -> ta.Any:
488
- return _yaml.safe_load(t)
489
-
490
-
491
- class YamlUnsafe(ObjectStr_):
492
- def forward(self, f: ta.Any) -> str:
493
- return _yaml.dump(f)
494
-
495
- def backward(self, t: str) -> ta.Any:
496
- return _yaml.load(t, _yaml.FullLoader)
@@ -1,11 +0,0 @@
1
- # @omlish-manifest
2
- _CLI_MODULE = {'$omdev.cli.types.CliModule': {
3
- 'cmd_name': 'json',
4
- 'mod_name': __name__,
5
- }}
6
-
7
-
8
- if __name__ == '__main__':
9
- from .cli import _main
10
-
11
- _main()