omlish 0.0.0.dev161__py3-none-any.whl → 0.0.0.dev163__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- omlish/.manifests.json +228 -0
- omlish/__about__.py +2 -2
- omlish/asyncs/bluelet/LICENSE +6 -0
- omlish/asyncs/bluelet/__init__.py +0 -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/codecs/__init__.py +69 -0
- omlish/codecs/base.py +102 -0
- omlish/codecs/bytes.py +119 -0
- omlish/codecs/chain.py +23 -0
- omlish/codecs/funcs.py +28 -0
- omlish/codecs/registry.py +139 -0
- omlish/codecs/standard.py +4 -0
- omlish/codecs/text.py +217 -0
- omlish/formats/cbor.py +31 -0
- omlish/formats/codecs.py +93 -0
- omlish/formats/json/codecs.py +33 -0
- omlish/formats/json5.py +31 -0
- omlish/formats/pickle.py +31 -0
- omlish/formats/toml.py +17 -0
- omlish/formats/yaml.py +18 -0
- omlish/io/compress/brotli.py +15 -1
- omlish/io/compress/bz2.py +14 -0
- omlish/io/compress/codecs.py +58 -0
- omlish/io/compress/gzip.py +11 -0
- omlish/io/compress/lz4.py +14 -0
- omlish/io/compress/lzma.py +14 -0
- omlish/io/compress/snappy.py +14 -0
- omlish/io/compress/zlib.py +14 -0
- omlish/io/compress/zstd.py +14 -0
- omlish/lang/__init__.py +1 -0
- omlish/lang/functions.py +11 -0
- omlish/lite/inject.py +16 -29
- omlish/manifests/load.py +44 -6
- {omlish-0.0.0.dev161.dist-info → omlish-0.0.0.dev163.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev161.dist-info → omlish-0.0.0.dev163.dist-info}/RECORD +45 -21
- {omlish-0.0.0.dev161.dist-info → omlish-0.0.0.dev163.dist-info}/LICENSE +0 -0
- {omlish-0.0.0.dev161.dist-info → omlish-0.0.0.dev163.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev161.dist-info → omlish-0.0.0.dev163.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev161.dist-info → omlish-0.0.0.dev163.dist-info}/top_level.txt +0 -0
omlish/formats/codecs.py
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
import typing as ta
|
2
|
+
|
3
|
+
from .. import codecs
|
4
|
+
from .. import reflect as rfl
|
5
|
+
|
6
|
+
|
7
|
+
ObjectCodecT = ta.TypeVar('ObjectCodecT', bound='ObjectCodec')
|
8
|
+
|
9
|
+
|
10
|
+
##
|
11
|
+
|
12
|
+
|
13
|
+
class ObjectCodec(codecs.Codec):
|
14
|
+
pass
|
15
|
+
|
16
|
+
|
17
|
+
def make_object_codec(
|
18
|
+
cls: type[ObjectCodecT],
|
19
|
+
name: str,
|
20
|
+
dumps: ta.Callable,
|
21
|
+
loads: ta.Callable,
|
22
|
+
*,
|
23
|
+
input: rfl.Type = rfl.type_(ta.Any), # noqa
|
24
|
+
aliases: ta.Collection[str] | None = None,
|
25
|
+
) -> ObjectCodecT:
|
26
|
+
return cls(
|
27
|
+
name=name,
|
28
|
+
aliases=aliases,
|
29
|
+
|
30
|
+
input=input,
|
31
|
+
output=bytes,
|
32
|
+
|
33
|
+
new=lambda: codecs.FnPairEagerCodec.of(dumps, loads),
|
34
|
+
)
|
35
|
+
|
36
|
+
|
37
|
+
##
|
38
|
+
|
39
|
+
|
40
|
+
class BytesObjectCodec(ObjectCodec):
|
41
|
+
pass
|
42
|
+
|
43
|
+
|
44
|
+
def make_bytes_object_codec(
|
45
|
+
name: str,
|
46
|
+
dumps: ta.Callable[[ta.Any], bytes],
|
47
|
+
loads: ta.Callable[[bytes], ta.Any],
|
48
|
+
**kwargs: ta.Any,
|
49
|
+
) -> BytesObjectCodec:
|
50
|
+
return make_object_codec(
|
51
|
+
BytesObjectCodec,
|
52
|
+
name,
|
53
|
+
dumps,
|
54
|
+
loads,
|
55
|
+
**kwargs,
|
56
|
+
)
|
57
|
+
|
58
|
+
|
59
|
+
##
|
60
|
+
|
61
|
+
|
62
|
+
class StrObjectCodec(ObjectCodec):
|
63
|
+
pass
|
64
|
+
|
65
|
+
|
66
|
+
def make_str_object_codec(
|
67
|
+
name: str,
|
68
|
+
dumps: ta.Callable[[ta.Any], str],
|
69
|
+
loads: ta.Callable[[str], ta.Any],
|
70
|
+
**kwargs: ta.Any,
|
71
|
+
) -> StrObjectCodec:
|
72
|
+
return make_object_codec(
|
73
|
+
StrObjectCodec,
|
74
|
+
name,
|
75
|
+
dumps,
|
76
|
+
loads,
|
77
|
+
**kwargs,
|
78
|
+
)
|
79
|
+
|
80
|
+
|
81
|
+
##
|
82
|
+
|
83
|
+
|
84
|
+
def make_object_lazy_loaded_codec(
|
85
|
+
mod_name: str,
|
86
|
+
attr_name: str,
|
87
|
+
codec: ObjectCodec,
|
88
|
+
) -> codecs.LazyLoadedCodec:
|
89
|
+
return codecs.LazyLoadedCodec.new(
|
90
|
+
mod_name,
|
91
|
+
attr_name,
|
92
|
+
codec,
|
93
|
+
)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
from ..codecs import make_object_lazy_loaded_codec
|
2
|
+
from ..codecs import make_str_object_codec
|
3
|
+
from .json import dumps
|
4
|
+
from .json import dumps_compact
|
5
|
+
from .json import dumps_pretty
|
6
|
+
from .json import loads
|
7
|
+
|
8
|
+
|
9
|
+
##
|
10
|
+
|
11
|
+
|
12
|
+
JSON_CODEC = make_str_object_codec('json', dumps, loads)
|
13
|
+
|
14
|
+
# @omlish-manifest
|
15
|
+
_JSON_LAZY_CODEC = make_object_lazy_loaded_codec(__name__, 'JSON_CODEC', JSON_CODEC)
|
16
|
+
|
17
|
+
|
18
|
+
#
|
19
|
+
|
20
|
+
|
21
|
+
JSON_COMPACT_CODEC = make_str_object_codec('json-compact', dumps_compact, loads)
|
22
|
+
|
23
|
+
# @omlish-manifest
|
24
|
+
_JSON_COMPACT_LAZY_CODEC = make_object_lazy_loaded_codec(__name__, 'JSON_COMPACT_CODEC', JSON_COMPACT_CODEC)
|
25
|
+
|
26
|
+
|
27
|
+
#
|
28
|
+
|
29
|
+
|
30
|
+
JSON_PRETTY_CODEC = make_str_object_codec('json-pretty', dumps_pretty, loads)
|
31
|
+
|
32
|
+
# @omlish-manifest
|
33
|
+
_JSON_PRETTY_LAZY_CODEC = make_object_lazy_loaded_codec(__name__, 'JSON_PRETTY_CODEC', JSON_PRETTY_CODEC)
|
omlish/formats/json5.py
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
import typing as ta
|
2
|
+
|
3
|
+
from .. import lang
|
4
|
+
from .codecs import make_object_lazy_loaded_codec
|
5
|
+
from .codecs import make_str_object_codec
|
6
|
+
|
7
|
+
|
8
|
+
if ta.TYPE_CHECKING:
|
9
|
+
import json5
|
10
|
+
else:
|
11
|
+
json5 = lang.proxy_import('json5')
|
12
|
+
|
13
|
+
|
14
|
+
##
|
15
|
+
|
16
|
+
|
17
|
+
def dumps(obj: ta.Any) -> str:
|
18
|
+
return json5.dumps(obj)
|
19
|
+
|
20
|
+
|
21
|
+
def loads(s: str) -> ta.Any:
|
22
|
+
return json5.loads(s)
|
23
|
+
|
24
|
+
|
25
|
+
##
|
26
|
+
|
27
|
+
|
28
|
+
JSON5_CODEC = make_str_object_codec('json5', dumps, loads)
|
29
|
+
|
30
|
+
# @omlish-manifest
|
31
|
+
_JSON5_LAZY_CODEC = make_object_lazy_loaded_codec(__name__, 'JSON5_CODEC', JSON5_CODEC)
|
omlish/formats/pickle.py
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
import typing as ta
|
2
|
+
|
3
|
+
from .. import lang
|
4
|
+
from .codecs import make_bytes_object_codec
|
5
|
+
from .codecs import make_object_lazy_loaded_codec
|
6
|
+
|
7
|
+
|
8
|
+
if ta.TYPE_CHECKING:
|
9
|
+
import pickle
|
10
|
+
else:
|
11
|
+
pickle = lang.proxy_import('pickle')
|
12
|
+
|
13
|
+
|
14
|
+
##
|
15
|
+
|
16
|
+
|
17
|
+
def dump(obj: ta.Any) -> bytes:
|
18
|
+
return pickle.dumps(obj)
|
19
|
+
|
20
|
+
|
21
|
+
def load(s: bytes) -> ta.Any:
|
22
|
+
return pickle.loads(s)
|
23
|
+
|
24
|
+
|
25
|
+
##
|
26
|
+
|
27
|
+
|
28
|
+
PICKLE_CODEC = make_bytes_object_codec('pickle', dump, load)
|
29
|
+
|
30
|
+
# @omlish-manifest
|
31
|
+
_PICKLE_LAZY_CODEC = make_object_lazy_loaded_codec(__name__, 'PICKLE_CODEC', PICKLE_CODEC)
|
omlish/formats/toml.py
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
import tomllib
|
2
|
+
|
3
|
+
from .codecs import make_object_lazy_loaded_codec
|
4
|
+
from .codecs import make_str_object_codec
|
5
|
+
|
6
|
+
|
7
|
+
##
|
8
|
+
|
9
|
+
|
10
|
+
def _dumps(obj):
|
11
|
+
raise TypeError('Unsupported')
|
12
|
+
|
13
|
+
|
14
|
+
TOML_CODEC = make_str_object_codec('toml', _dumps, tomllib.loads)
|
15
|
+
|
16
|
+
# @omlish-manifest
|
17
|
+
_TOML_LAZY_CODEC = make_object_lazy_loaded_codec(__name__, 'TOML_CODEC', TOML_CODEC)
|
omlish/formats/yaml.py
CHANGED
@@ -14,6 +14,8 @@ import typing as ta
|
|
14
14
|
from .. import check
|
15
15
|
from .. import dataclasses as dc
|
16
16
|
from .. import lang
|
17
|
+
from .codecs import make_object_lazy_loaded_codec
|
18
|
+
from .codecs import make_str_object_codec
|
17
19
|
|
18
20
|
|
19
21
|
if ta.TYPE_CHECKING:
|
@@ -239,3 +241,19 @@ def full_load(stream): # noqa
|
|
239
241
|
|
240
242
|
def full_load_all(stream): # noqa # noqa
|
241
243
|
return load_all(stream, yaml.FullLoader)
|
244
|
+
|
245
|
+
|
246
|
+
##
|
247
|
+
|
248
|
+
|
249
|
+
def dump(obj, **kwargs):
|
250
|
+
return yaml.dump(obj, **kwargs)
|
251
|
+
|
252
|
+
|
253
|
+
##
|
254
|
+
|
255
|
+
|
256
|
+
YAML_CODEC = make_str_object_codec('yaml', dump, safe_load, aliases=['yml'])
|
257
|
+
|
258
|
+
# @omlish-manifest
|
259
|
+
_YAML_LAZY_CODEC = make_object_lazy_loaded_codec(__name__, 'YAML_CODEC', YAML_CODEC)
|
omlish/io/compress/brotli.py
CHANGED
@@ -3,6 +3,8 @@ import typing as ta
|
|
3
3
|
|
4
4
|
from ... import lang
|
5
5
|
from .base import Compression
|
6
|
+
from .codecs import make_compression_codec
|
7
|
+
from .codecs import make_compression_lazy_loaded_codec
|
6
8
|
|
7
9
|
|
8
10
|
if ta.TYPE_CHECKING:
|
@@ -11,8 +13,11 @@ else:
|
|
11
13
|
brotli = lang.proxy_import('brotli')
|
12
14
|
|
13
15
|
|
16
|
+
##
|
17
|
+
|
18
|
+
|
14
19
|
@dc.dataclass(frozen=True, kw_only=True)
|
15
|
-
class
|
20
|
+
class BrotliCompression(Compression):
|
16
21
|
mode: int | None = None
|
17
22
|
quality: int | None = None
|
18
23
|
lgwin: int | None = None
|
@@ -31,3 +36,12 @@ class SnappyCompression(Compression):
|
|
31
36
|
return brotli.decompress(
|
32
37
|
d,
|
33
38
|
)
|
39
|
+
|
40
|
+
|
41
|
+
##
|
42
|
+
|
43
|
+
|
44
|
+
BROTLI_CODEC = make_compression_codec('brotli', BrotliCompression)
|
45
|
+
|
46
|
+
# @omlish-manifest
|
47
|
+
_BROTLI_LAZY_CODEC = make_compression_lazy_loaded_codec(__name__, 'BROTLI_CODEC', BROTLI_CODEC)
|
omlish/io/compress/bz2.py
CHANGED
@@ -9,6 +9,8 @@ from .adapters import CompressorObjectIncrementalAdapter
|
|
9
9
|
from .adapters import DecompressorObjectIncrementalAdapter
|
10
10
|
from .base import Compression
|
11
11
|
from .base import IncrementalCompression
|
12
|
+
from .codecs import make_compression_codec
|
13
|
+
from .codecs import make_compression_lazy_loaded_codec
|
12
14
|
|
13
15
|
|
14
16
|
if ta.TYPE_CHECKING:
|
@@ -17,6 +19,9 @@ else:
|
|
17
19
|
bz2 = lang.proxy_import('bz2')
|
18
20
|
|
19
21
|
|
22
|
+
##
|
23
|
+
|
24
|
+
|
20
25
|
@dc.dataclass(frozen=True, kw_only=True)
|
21
26
|
class Bz2Compression(Compression, IncrementalCompression):
|
22
27
|
level: int = 9
|
@@ -45,3 +50,12 @@ class Bz2Compression(Compression, IncrementalCompression):
|
|
45
50
|
bz2.BZ2Decompressor, # type: ignore
|
46
51
|
trailing_error=OSError,
|
47
52
|
)()
|
53
|
+
|
54
|
+
|
55
|
+
##
|
56
|
+
|
57
|
+
|
58
|
+
BZ2_CODEC = make_compression_codec('bz2', Bz2Compression)
|
59
|
+
|
60
|
+
# @omlish-manifest
|
61
|
+
_BZ2_LAZY_CODEC = make_compression_lazy_loaded_codec(__name__, 'BZ2_CODEC', BZ2_CODEC)
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import dataclasses as dc
|
2
|
+
import typing as ta
|
3
|
+
|
4
|
+
from ... import codecs
|
5
|
+
from .base import Compression
|
6
|
+
|
7
|
+
|
8
|
+
##
|
9
|
+
|
10
|
+
|
11
|
+
@dc.dataclass(frozen=True)
|
12
|
+
class CompressionEagerCodec(codecs.EagerCodec[bytes, bytes]):
|
13
|
+
compression: Compression
|
14
|
+
|
15
|
+
def encode(self, i: bytes) -> bytes:
|
16
|
+
return self.compression.compress(i)
|
17
|
+
|
18
|
+
def decode(self, o: bytes) -> bytes:
|
19
|
+
return self.compression.decompress(o)
|
20
|
+
|
21
|
+
|
22
|
+
##
|
23
|
+
|
24
|
+
|
25
|
+
class CompressionCodec(codecs.Codec):
|
26
|
+
pass
|
27
|
+
|
28
|
+
|
29
|
+
def make_compression_codec(
|
30
|
+
name: str,
|
31
|
+
cls: type[Compression],
|
32
|
+
*,
|
33
|
+
aliases: ta.Collection[str] | None = None,
|
34
|
+
) -> CompressionCodec:
|
35
|
+
return CompressionCodec(
|
36
|
+
name=name,
|
37
|
+
aliases=aliases,
|
38
|
+
|
39
|
+
input=bytes,
|
40
|
+
output=bytes,
|
41
|
+
|
42
|
+
new=lambda *args, **kwargs: CompressionEagerCodec(cls(*args, **kwargs)),
|
43
|
+
)
|
44
|
+
|
45
|
+
|
46
|
+
##
|
47
|
+
|
48
|
+
|
49
|
+
def make_compression_lazy_loaded_codec(
|
50
|
+
mod_name: str,
|
51
|
+
attr_name: str,
|
52
|
+
codec: CompressionCodec,
|
53
|
+
) -> codecs.LazyLoadedCodec:
|
54
|
+
return codecs.LazyLoadedCodec.new(
|
55
|
+
mod_name,
|
56
|
+
attr_name,
|
57
|
+
codec,
|
58
|
+
)
|
omlish/io/compress/gzip.py
CHANGED
@@ -48,6 +48,8 @@ from ..generators import BytesSteppedReaderGenerator
|
|
48
48
|
from ..generators.readers import PrependableBytesGeneratorReader
|
49
49
|
from .base import Compression
|
50
50
|
from .base import IncrementalCompression
|
51
|
+
from .codecs import make_compression_codec
|
52
|
+
from .codecs import make_compression_lazy_loaded_codec
|
51
53
|
|
52
54
|
|
53
55
|
if ta.TYPE_CHECKING:
|
@@ -337,3 +339,12 @@ class IncrementalGzipDecompressor:
|
|
337
339
|
stream_size += len(uncompress)
|
338
340
|
pos += len(uncompress)
|
339
341
|
check.none((yield uncompress))
|
342
|
+
|
343
|
+
|
344
|
+
##
|
345
|
+
|
346
|
+
|
347
|
+
GZIP_CODEC = make_compression_codec('gzip', GzipCompression, aliases=['gz'])
|
348
|
+
|
349
|
+
# @omlish-manifest
|
350
|
+
_GZIP_LAZY_CODEC = make_compression_lazy_loaded_codec(__name__, 'GZIP_CODEC', GZIP_CODEC)
|
omlish/io/compress/lz4.py
CHANGED
@@ -6,6 +6,8 @@ from ... import lang
|
|
6
6
|
from ..generators import BytesSteppedGenerator
|
7
7
|
from .base import Compression
|
8
8
|
from .base import IncrementalCompression
|
9
|
+
from .codecs import make_compression_codec
|
10
|
+
from .codecs import make_compression_lazy_loaded_codec
|
9
11
|
|
10
12
|
|
11
13
|
if ta.TYPE_CHECKING:
|
@@ -14,6 +16,9 @@ else:
|
|
14
16
|
lz4_frame = lang.proxy_import('lz4.frame')
|
15
17
|
|
16
18
|
|
19
|
+
##
|
20
|
+
|
21
|
+
|
17
22
|
@dc.dataclass(frozen=True, kw_only=True)
|
18
23
|
class Lz4Compression(Compression, IncrementalCompression):
|
19
24
|
level: int = 0
|
@@ -75,3 +80,12 @@ class Lz4Compression(Compression, IncrementalCompression):
|
|
75
80
|
return
|
76
81
|
if (o := decompressor.decompress(i)):
|
77
82
|
yield o
|
83
|
+
|
84
|
+
|
85
|
+
##
|
86
|
+
|
87
|
+
|
88
|
+
LZ4_CODEC = make_compression_codec('lz4', Lz4Compression)
|
89
|
+
|
90
|
+
# @omlish-manifest
|
91
|
+
_LZ4_LAZY_CODEC = make_compression_lazy_loaded_codec(__name__, 'LZ4_CODEC', LZ4_CODEC)
|
omlish/io/compress/lzma.py
CHANGED
@@ -9,6 +9,8 @@ from .adapters import CompressorObjectIncrementalAdapter
|
|
9
9
|
from .adapters import DecompressorObjectIncrementalAdapter
|
10
10
|
from .base import Compression
|
11
11
|
from .base import IncrementalCompression
|
12
|
+
from .codecs import make_compression_codec
|
13
|
+
from .codecs import make_compression_lazy_loaded_codec
|
12
14
|
|
13
15
|
|
14
16
|
if ta.TYPE_CHECKING:
|
@@ -17,6 +19,9 @@ else:
|
|
17
19
|
lzma = lang.proxy_import('lzma')
|
18
20
|
|
19
21
|
|
22
|
+
##
|
23
|
+
|
24
|
+
|
20
25
|
@dc.dataclass(frozen=True, kw_only=True)
|
21
26
|
class LzmaCompression(Compression, IncrementalCompression):
|
22
27
|
format: int | None = None
|
@@ -65,3 +70,12 @@ class LzmaCompression(Compression, IncrementalCompression):
|
|
65
70
|
),
|
66
71
|
trailing_error=lzma.LZMAError,
|
67
72
|
)()
|
73
|
+
|
74
|
+
|
75
|
+
##
|
76
|
+
|
77
|
+
|
78
|
+
LZMA_CODEC = make_compression_codec('lzma', LzmaCompression)
|
79
|
+
|
80
|
+
# @omlish-manifest
|
81
|
+
_LZMA_LAZY_CODEC = make_compression_lazy_loaded_codec(__name__, 'LZMA_CODEC', LZMA_CODEC)
|
omlish/io/compress/snappy.py
CHANGED
@@ -3,6 +3,8 @@ import typing as ta
|
|
3
3
|
|
4
4
|
from ... import lang
|
5
5
|
from .base import Compression
|
6
|
+
from .codecs import make_compression_codec
|
7
|
+
from .codecs import make_compression_lazy_loaded_codec
|
6
8
|
|
7
9
|
|
8
10
|
if ta.TYPE_CHECKING:
|
@@ -11,6 +13,9 @@ else:
|
|
11
13
|
snappy = lang.proxy_import('snappy')
|
12
14
|
|
13
15
|
|
16
|
+
##
|
17
|
+
|
18
|
+
|
14
19
|
@dc.dataclass(frozen=True)
|
15
20
|
class SnappyCompression(Compression):
|
16
21
|
def compress(self, d: bytes) -> bytes:
|
@@ -18,3 +23,12 @@ class SnappyCompression(Compression):
|
|
18
23
|
|
19
24
|
def decompress(self, d: bytes) -> bytes:
|
20
25
|
return snappy.decompress(d)
|
26
|
+
|
27
|
+
|
28
|
+
##
|
29
|
+
|
30
|
+
|
31
|
+
SNAPPY_CODEC = make_compression_codec('snappy', SnappyCompression)
|
32
|
+
|
33
|
+
# @omlish-manifest
|
34
|
+
_SNAPPY_LAZY_CODEC = make_compression_lazy_loaded_codec(__name__, 'SNAPPY_CODEC', SNAPPY_CODEC)
|
omlish/io/compress/zlib.py
CHANGED
@@ -9,6 +9,8 @@ from .adapters import CompressorObjectIncrementalAdapter
|
|
9
9
|
from .adapters import DecompressorObjectIncrementalAdapter
|
10
10
|
from .base import Compression
|
11
11
|
from .base import IncrementalCompression
|
12
|
+
from .codecs import make_compression_codec
|
13
|
+
from .codecs import make_compression_lazy_loaded_codec
|
12
14
|
|
13
15
|
|
14
16
|
if ta.TYPE_CHECKING:
|
@@ -17,6 +19,9 @@ else:
|
|
17
19
|
zlib = lang.proxy_import('zlib')
|
18
20
|
|
19
21
|
|
22
|
+
##
|
23
|
+
|
24
|
+
|
20
25
|
@dc.dataclass(frozen=True, kw_only=True)
|
21
26
|
class ZlibCompression(Compression, IncrementalCompression):
|
22
27
|
level: int = 9
|
@@ -58,3 +63,12 @@ class ZlibCompression(Compression, IncrementalCompression):
|
|
58
63
|
),
|
59
64
|
trailing_error=OSError,
|
60
65
|
)()
|
66
|
+
|
67
|
+
|
68
|
+
##
|
69
|
+
|
70
|
+
|
71
|
+
ZLIB_CODEC = make_compression_codec('zlib', ZlibCompression)
|
72
|
+
|
73
|
+
# @omlish-manifest
|
74
|
+
_ZLIB_LAZY_CODEC = make_compression_lazy_loaded_codec(__name__, 'ZLIB_CODEC', ZLIB_CODEC)
|
omlish/io/compress/zstd.py
CHANGED
@@ -3,6 +3,8 @@ import typing as ta
|
|
3
3
|
|
4
4
|
from ... import lang
|
5
5
|
from .base import Compression
|
6
|
+
from .codecs import make_compression_codec
|
7
|
+
from .codecs import make_compression_lazy_loaded_codec
|
6
8
|
|
7
9
|
|
8
10
|
if ta.TYPE_CHECKING:
|
@@ -11,6 +13,9 @@ else:
|
|
11
13
|
zstandard = lang.proxy_import('zstandard')
|
12
14
|
|
13
15
|
|
16
|
+
##
|
17
|
+
|
18
|
+
|
14
19
|
@dc.dataclass(frozen=True, kw_only=True)
|
15
20
|
class ZstdCompression(Compression):
|
16
21
|
level: int | None = None
|
@@ -28,3 +33,12 @@ class ZstdCompression(Compression):
|
|
28
33
|
d,
|
29
34
|
max_output_size=self.max_output_size,
|
30
35
|
)
|
36
|
+
|
37
|
+
|
38
|
+
##
|
39
|
+
|
40
|
+
|
41
|
+
ZSTD_CODEC = make_compression_codec('zstd', ZstdCompression)
|
42
|
+
|
43
|
+
# @omlish-manifest
|
44
|
+
_ZSTD_LAZY_CODEC = make_compression_lazy_loaded_codec(__name__, 'ZSTD_CODEC', ZSTD_CODEC)
|
omlish/lang/__init__.py
CHANGED
omlish/lang/functions.py
CHANGED
@@ -4,6 +4,7 @@ import time
|
|
4
4
|
import typing as ta
|
5
5
|
|
6
6
|
|
7
|
+
F = ta.TypeVar('F')
|
7
8
|
T = ta.TypeVar('T')
|
8
9
|
P = ta.ParamSpec('P')
|
9
10
|
CallableT = ta.TypeVar('CallableT', bound=ta.Callable)
|
@@ -81,6 +82,16 @@ def identity(obj: T) -> T:
|
|
81
82
|
return obj
|
82
83
|
|
83
84
|
|
85
|
+
def opt_fn(fn: ta.Callable[[F], T]) -> ta.Callable[[F | None], T | None]:
|
86
|
+
@functools.wraps(fn)
|
87
|
+
def inner(v: F | None) -> T | None:
|
88
|
+
if v is not None:
|
89
|
+
return fn(v)
|
90
|
+
else:
|
91
|
+
return None
|
92
|
+
return inner
|
93
|
+
|
94
|
+
|
84
95
|
class constant(ta.Generic[T]): # noqa
|
85
96
|
def __init__(self, obj: T) -> None:
|
86
97
|
super().__init__()
|
omlish/lite/inject.py
CHANGED
@@ -610,7 +610,7 @@ class InjectorBinder:
|
|
610
610
|
def __new__(cls, *args, **kwargs): # noqa
|
611
611
|
raise TypeError
|
612
612
|
|
613
|
-
_FN_TYPES: ta.Tuple[type, ...] = (
|
613
|
+
_FN_TYPES: ta.ClassVar[ta.Tuple[type, ...]] = (
|
614
614
|
types.FunctionType,
|
615
615
|
types.MethodType,
|
616
616
|
|
@@ -632,7 +632,7 @@ class InjectorBinder:
|
|
632
632
|
cls._FN_TYPES = (*cls._FN_TYPES, icls)
|
633
633
|
return icls
|
634
634
|
|
635
|
-
_BANNED_BIND_TYPES: ta.Tuple[type, ...] = (
|
635
|
+
_BANNED_BIND_TYPES: ta.ClassVar[ta.Tuple[type, ...]] = (
|
636
636
|
InjectorProvider,
|
637
637
|
)
|
638
638
|
|
@@ -811,45 +811,35 @@ def bind_injector_eager_key(key: ta.Any) -> InjectorBinding:
|
|
811
811
|
##
|
812
812
|
|
813
813
|
|
814
|
-
class
|
815
|
-
def __new__(cls, *args, **kwargs): # noqa
|
816
|
-
raise TypeError
|
817
|
-
|
814
|
+
class InjectionApi:
|
818
815
|
# keys
|
819
816
|
|
820
|
-
|
821
|
-
def as_key(cls, o: ta.Any) -> InjectorKey:
|
817
|
+
def as_key(self, o: ta.Any) -> InjectorKey:
|
822
818
|
return as_injector_key(o)
|
823
819
|
|
824
|
-
|
825
|
-
def array(cls, o: ta.Any) -> InjectorKey:
|
820
|
+
def array(self, o: ta.Any) -> InjectorKey:
|
826
821
|
return dc.replace(as_injector_key(o), array=True)
|
827
822
|
|
828
|
-
|
829
|
-
def tag(cls, o: ta.Any, t: ta.Any) -> InjectorKey:
|
823
|
+
def tag(self, o: ta.Any, t: ta.Any) -> InjectorKey:
|
830
824
|
return dc.replace(as_injector_key(o), tag=t)
|
831
825
|
|
832
826
|
# bindings
|
833
827
|
|
834
|
-
|
835
|
-
def as_bindings(cls, *args: InjectorBindingOrBindings) -> InjectorBindings:
|
828
|
+
def as_bindings(self, *args: InjectorBindingOrBindings) -> InjectorBindings:
|
836
829
|
return as_injector_bindings(*args)
|
837
830
|
|
838
|
-
|
839
|
-
def override(cls, p: InjectorBindings, *args: InjectorBindingOrBindings) -> InjectorBindings:
|
831
|
+
def override(self, p: InjectorBindings, *args: InjectorBindingOrBindings) -> InjectorBindings:
|
840
832
|
return injector_override(p, *args)
|
841
833
|
|
842
834
|
# injector
|
843
835
|
|
844
|
-
|
845
|
-
def create_injector(cls, *args: InjectorBindingOrBindings, parent: ta.Optional[Injector] = None) -> Injector:
|
836
|
+
def create_injector(self, *args: InjectorBindingOrBindings, parent: ta.Optional[Injector] = None) -> Injector:
|
846
837
|
return _Injector(as_injector_bindings(*args), parent)
|
847
838
|
|
848
839
|
# binder
|
849
840
|
|
850
|
-
@classmethod
|
851
841
|
def bind(
|
852
|
-
|
842
|
+
self,
|
853
843
|
obj: ta.Any,
|
854
844
|
*,
|
855
845
|
key: ta.Any = None,
|
@@ -884,32 +874,29 @@ class Injection:
|
|
884
874
|
|
885
875
|
# helpers
|
886
876
|
|
887
|
-
@classmethod
|
888
877
|
def bind_factory(
|
889
|
-
|
878
|
+
self,
|
890
879
|
fn: ta.Callable[..., T],
|
891
880
|
cls_: U,
|
892
881
|
ann: ta.Any = None,
|
893
882
|
) -> InjectorBindingOrBindings:
|
894
|
-
return
|
883
|
+
return self.bind(make_injector_factory(fn, cls_, ann))
|
895
884
|
|
896
|
-
@classmethod
|
897
885
|
def bind_array(
|
898
|
-
|
886
|
+
self,
|
899
887
|
obj: ta.Any = None,
|
900
888
|
*,
|
901
889
|
tag: ta.Any = None,
|
902
890
|
) -> InjectorBindingOrBindings:
|
903
891
|
return bind_injector_array(obj, tag=tag)
|
904
892
|
|
905
|
-
@classmethod
|
906
893
|
def bind_array_type(
|
907
|
-
|
894
|
+
self,
|
908
895
|
ele: ta.Union[InjectorKey, InjectorKeyCls],
|
909
896
|
cls_: U,
|
910
897
|
ann: ta.Any = None,
|
911
898
|
) -> InjectorBindingOrBindings:
|
912
|
-
return
|
899
|
+
return self.bind(make_injector_array_type(ele, cls_, ann))
|
913
900
|
|
914
901
|
|
915
|
-
inj =
|
902
|
+
inj = InjectionApi()
|