omlish 0.0.0.dev133__py3-none-any.whl → 0.0.0.dev177__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/.manifests.json +265 -7
- omlish/__about__.py +5 -3
- omlish/antlr/_runtime/__init__.py +0 -22
- omlish/antlr/_runtime/_all.py +24 -0
- omlish/antlr/_runtime/atn/ParserATNSimulator.py +1 -1
- omlish/antlr/_runtime/dfa/DFASerializer.py +1 -1
- omlish/antlr/_runtime/error/DiagnosticErrorListener.py +2 -1
- omlish/antlr/_runtime/xpath/XPath.py +7 -1
- omlish/antlr/_runtime/xpath/XPathLexer.py +1 -1
- omlish/antlr/delimit.py +106 -0
- omlish/antlr/dot.py +31 -0
- omlish/antlr/errors.py +11 -0
- omlish/antlr/input.py +96 -0
- omlish/antlr/parsing.py +19 -0
- omlish/antlr/runtime.py +102 -0
- omlish/antlr/utils.py +38 -0
- omlish/argparse/all.py +45 -0
- omlish/{argparse.py → argparse/cli.py} +112 -107
- omlish/asyncs/__init__.py +0 -35
- omlish/asyncs/all.py +35 -0
- omlish/asyncs/asyncio/all.py +7 -0
- omlish/asyncs/asyncio/channels.py +40 -0
- omlish/asyncs/asyncio/streams.py +45 -0
- omlish/asyncs/asyncio/subprocesses.py +238 -0
- omlish/asyncs/asyncio/timeouts.py +16 -0
- omlish/asyncs/bluelet/LICENSE +6 -0
- omlish/asyncs/bluelet/all.py +67 -0
- omlish/asyncs/bluelet/api.py +23 -0
- omlish/asyncs/bluelet/core.py +178 -0
- omlish/asyncs/bluelet/events.py +78 -0
- omlish/asyncs/bluelet/files.py +80 -0
- omlish/asyncs/bluelet/runner.py +416 -0
- omlish/asyncs/bluelet/sockets.py +214 -0
- omlish/bootstrap/sys.py +3 -3
- omlish/cached.py +2 -2
- omlish/check.py +49 -460
- omlish/codecs/__init__.py +72 -0
- omlish/codecs/base.py +106 -0
- omlish/codecs/bytes.py +119 -0
- omlish/codecs/chain.py +23 -0
- omlish/codecs/funcs.py +39 -0
- omlish/codecs/registry.py +139 -0
- omlish/codecs/standard.py +4 -0
- omlish/codecs/text.py +217 -0
- omlish/collections/cache/impl.py +50 -57
- omlish/collections/coerce.py +1 -0
- omlish/collections/mappings.py +1 -1
- omlish/configs/flattening.py +1 -1
- omlish/defs.py +1 -1
- omlish/diag/_pycharm/runhack.py +8 -2
- omlish/diag/procfs.py +8 -8
- omlish/docker/__init__.py +0 -36
- omlish/docker/all.py +31 -0
- omlish/docker/consts.py +4 -0
- omlish/{lite/docker.py → docker/detect.py} +18 -0
- omlish/docker/{helpers.py → timebomb.py} +0 -21
- omlish/formats/cbor.py +31 -0
- omlish/formats/cloudpickle.py +31 -0
- omlish/formats/codecs.py +93 -0
- omlish/formats/json/codecs.py +29 -0
- omlish/formats/json/delimted.py +4 -0
- omlish/formats/json/stream/errors.py +2 -0
- omlish/formats/json/stream/lex.py +12 -6
- omlish/formats/json/stream/parse.py +38 -22
- omlish/formats/json5.py +31 -0
- omlish/formats/pickle.py +31 -0
- omlish/formats/repr.py +25 -0
- omlish/formats/toml.py +17 -0
- omlish/formats/yaml.py +25 -0
- omlish/funcs/__init__.py +0 -0
- omlish/{genmachine.py → funcs/genmachine.py} +5 -4
- omlish/{matchfns.py → funcs/match.py} +1 -1
- omlish/funcs/pairs.py +215 -0
- omlish/http/__init__.py +0 -48
- omlish/http/all.py +48 -0
- omlish/http/coro/__init__.py +0 -0
- omlish/{lite/fdio/corohttp.py → http/coro/fdio.py} +21 -19
- omlish/{lite/http/coroserver.py → http/coro/server.py} +20 -21
- omlish/{lite/http → http}/handlers.py +3 -2
- omlish/{lite/http → http}/parsing.py +1 -0
- omlish/http/sessions.py +1 -1
- omlish/{lite/http → http}/versions.py +1 -0
- omlish/inject/managed.py +2 -2
- omlish/io/__init__.py +0 -3
- omlish/{lite/io.py → io/buffers.py} +8 -9
- omlish/io/compress/__init__.py +9 -0
- omlish/io/compress/abc.py +104 -0
- omlish/io/compress/adapters.py +148 -0
- omlish/io/compress/base.py +24 -0
- omlish/io/compress/brotli.py +47 -0
- omlish/io/compress/bz2.py +61 -0
- omlish/io/compress/codecs.py +78 -0
- omlish/io/compress/gzip.py +350 -0
- omlish/io/compress/lz4.py +91 -0
- omlish/io/compress/lzma.py +81 -0
- omlish/io/compress/snappy.py +34 -0
- omlish/io/compress/zlib.py +74 -0
- omlish/io/compress/zstd.py +44 -0
- omlish/io/fdio/__init__.py +1 -0
- omlish/{lite → io}/fdio/handlers.py +5 -5
- omlish/{lite → io}/fdio/kqueue.py +8 -8
- omlish/{lite → io}/fdio/manager.py +7 -7
- omlish/{lite → io}/fdio/pollers.py +13 -13
- omlish/io/generators/__init__.py +56 -0
- omlish/io/generators/consts.py +1 -0
- omlish/io/generators/direct.py +13 -0
- omlish/io/generators/readers.py +189 -0
- omlish/io/generators/stepped.py +191 -0
- omlish/io/pyio.py +5 -2
- omlish/iterators/__init__.py +24 -0
- omlish/iterators/iterators.py +132 -0
- omlish/iterators/recipes.py +18 -0
- omlish/iterators/tools.py +96 -0
- omlish/iterators/unique.py +67 -0
- omlish/lang/__init__.py +13 -1
- omlish/lang/functions.py +11 -2
- omlish/lang/generators.py +243 -0
- omlish/lang/iterables.py +46 -49
- omlish/lang/maybes.py +4 -4
- omlish/lite/cached.py +39 -6
- omlish/lite/check.py +438 -75
- omlish/lite/contextmanagers.py +17 -4
- omlish/lite/dataclasses.py +42 -0
- omlish/lite/inject.py +28 -45
- omlish/lite/logs.py +0 -270
- omlish/lite/marshal.py +309 -144
- omlish/lite/pycharm.py +47 -0
- omlish/lite/reflect.py +33 -0
- omlish/lite/resources.py +8 -0
- omlish/lite/runtime.py +4 -4
- omlish/lite/shlex.py +12 -0
- omlish/lite/socketserver.py +2 -2
- omlish/lite/strings.py +31 -0
- omlish/logs/__init__.py +0 -32
- omlish/logs/{_abc.py → abc.py} +0 -1
- omlish/logs/all.py +37 -0
- omlish/logs/{formatters.py → color.py} +1 -2
- omlish/logs/configs.py +7 -38
- omlish/logs/filters.py +10 -0
- omlish/logs/handlers.py +4 -1
- omlish/logs/json.py +56 -0
- omlish/logs/proxy.py +99 -0
- omlish/logs/standard.py +128 -0
- omlish/logs/utils.py +2 -2
- omlish/manifests/__init__.py +2 -0
- omlish/manifests/load.py +209 -0
- omlish/manifests/types.py +17 -0
- omlish/marshal/base.py +1 -1
- omlish/marshal/factories.py +1 -1
- omlish/marshal/forbidden.py +1 -1
- omlish/marshal/iterables.py +1 -1
- omlish/marshal/literals.py +50 -0
- omlish/marshal/mappings.py +1 -1
- omlish/marshal/maybes.py +1 -1
- omlish/marshal/standard.py +5 -1
- omlish/marshal/unions.py +1 -1
- omlish/os/__init__.py +0 -0
- omlish/os/atomics.py +205 -0
- omlish/os/deathsig.py +23 -0
- omlish/{os.py → os/files.py} +0 -9
- omlish/{lite → os}/journald.py +2 -1
- omlish/os/linux.py +484 -0
- omlish/os/paths.py +36 -0
- omlish/{lite → os}/pidfile.py +1 -0
- omlish/os/sizes.py +9 -0
- omlish/reflect/__init__.py +3 -0
- omlish/reflect/subst.py +2 -1
- omlish/reflect/types.py +126 -44
- omlish/secrets/pwhash.py +1 -1
- omlish/secrets/subprocesses.py +3 -1
- omlish/specs/jsonrpc/marshal.py +1 -1
- omlish/specs/openapi/marshal.py +1 -1
- omlish/sql/alchemy/asyncs.py +1 -1
- omlish/sql/queries/__init__.py +9 -1
- omlish/sql/queries/building.py +3 -0
- omlish/sql/queries/exprs.py +10 -27
- omlish/sql/queries/idents.py +48 -10
- omlish/sql/queries/names.py +80 -13
- omlish/sql/queries/params.py +64 -0
- omlish/sql/queries/rendering.py +1 -1
- omlish/subprocesses.py +340 -0
- omlish/term.py +29 -14
- omlish/testing/pytest/marks.py +2 -2
- omlish/testing/pytest/plugins/asyncs.py +6 -1
- omlish/testing/pytest/plugins/logging.py +1 -1
- omlish/testing/pytest/plugins/switches.py +1 -1
- {omlish-0.0.0.dev133.dist-info → omlish-0.0.0.dev177.dist-info}/METADATA +7 -5
- {omlish-0.0.0.dev133.dist-info → omlish-0.0.0.dev177.dist-info}/RECORD +200 -117
- omlish/fnpairs.py +0 -496
- omlish/formats/json/cli/__main__.py +0 -11
- omlish/formats/json/cli/cli.py +0 -298
- omlish/formats/json/cli/formats.py +0 -71
- omlish/formats/json/cli/io.py +0 -74
- omlish/formats/json/cli/parsing.py +0 -82
- omlish/formats/json/cli/processing.py +0 -48
- omlish/formats/json/cli/rendering.py +0 -92
- omlish/iterators.py +0 -300
- omlish/lite/subprocesses.py +0 -130
- /omlish/{formats/json/cli → argparse}/__init__.py +0 -0
- /omlish/{lite/fdio → asyncs/asyncio}/__init__.py +0 -0
- /omlish/asyncs/{asyncio.py → asyncio/asyncio.py} +0 -0
- /omlish/{lite/http → asyncs/bluelet}/__init__.py +0 -0
- /omlish/collections/{_abc.py → abc.py} +0 -0
- /omlish/{fnpipes.py → funcs/pipes.py} +0 -0
- /omlish/io/{_abc.py → abc.py} +0 -0
- /omlish/sql/{_abc.py → abc.py} +0 -0
- {omlish-0.0.0.dev133.dist-info → omlish-0.0.0.dev177.dist-info}/LICENSE +0 -0
- {omlish-0.0.0.dev133.dist-info → omlish-0.0.0.dev177.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev133.dist-info → omlish-0.0.0.dev177.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev133.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)
|