omlish 0.0.0.dev135__py3-none-any.whl → 0.0.0.dev136__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- omlish/.manifests.json +0 -12
- omlish/__about__.py +2 -2
- omlish/formats/json/stream/lex.py +1 -1
- omlish/formats/json/stream/parse.py +1 -1
- omlish/{matchfns.py → funcs/match.py} +1 -1
- omlish/{fnpairs.py → funcs/pairs.py} +3 -3
- omlish/http/sessions.py +1 -1
- 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/mappings.py +1 -1
- omlish/marshal/maybes.py +1 -1
- omlish/marshal/standard.py +1 -1
- omlish/marshal/unions.py +1 -1
- 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-0.0.0.dev135.dist-info → omlish-0.0.0.dev136.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev135.dist-info → omlish-0.0.0.dev136.dist-info}/RECORD +28 -35
- 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/{formats/json/cli → funcs}/__init__.py +0 -0
- /omlish/{genmachine.py → funcs/genmachine.py} +0 -0
- /omlish/{fnpipes.py → funcs/pipes.py} +0 -0
- {omlish-0.0.0.dev135.dist-info → omlish-0.0.0.dev136.dist-info}/LICENSE +0 -0
- {omlish-0.0.0.dev135.dist-info → omlish-0.0.0.dev136.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev135.dist-info → omlish-0.0.0.dev136.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev135.dist-info → omlish-0.0.0.dev136.dist-info}/top_level.txt +0 -0
omlish/.manifests.json
CHANGED
@@ -23,18 +23,6 @@
|
|
23
23
|
}
|
24
24
|
}
|
25
25
|
},
|
26
|
-
{
|
27
|
-
"module": ".formats.json.cli.__main__",
|
28
|
-
"attr": "_CLI_MODULE",
|
29
|
-
"file": "omlish/formats/json/cli/__main__.py",
|
30
|
-
"line": 1,
|
31
|
-
"value": {
|
32
|
-
"$omdev.cli.types.CliModule": {
|
33
|
-
"cmd_name": "json",
|
34
|
-
"mod_name": "omlish.formats.json.cli.__main__"
|
35
|
-
}
|
36
|
-
}
|
37
|
-
},
|
38
26
|
{
|
39
27
|
"module": ".secrets.pwgen",
|
40
28
|
"attr": "_CLI_MODULE",
|
omlish/__about__.py
CHANGED
@@ -20,7 +20,7 @@ import codecs
|
|
20
20
|
import dataclasses as dc
|
21
21
|
import typing as ta
|
22
22
|
|
23
|
-
from
|
23
|
+
from .. import lang
|
24
24
|
|
25
25
|
|
26
26
|
if ta.TYPE_CHECKING:
|
@@ -39,7 +39,7 @@ if ta.TYPE_CHECKING:
|
|
39
39
|
import yaml as _yaml
|
40
40
|
import zstandard as _zstandard
|
41
41
|
|
42
|
-
from
|
42
|
+
from ..formats import json as _json
|
43
43
|
|
44
44
|
else:
|
45
45
|
_bz2 = lang.proxy_import('bz2')
|
@@ -57,7 +57,7 @@ else:
|
|
57
57
|
_yaml = lang.proxy_import('yaml')
|
58
58
|
_zstandard = lang.proxy_import('zstandard')
|
59
59
|
|
60
|
-
_json = lang.proxy_import('
|
60
|
+
_json = lang.proxy_import('..formats.json', __package__)
|
61
61
|
|
62
62
|
|
63
63
|
##
|
omlish/http/sessions.py
CHANGED
@@ -8,9 +8,9 @@ import time
|
|
8
8
|
import typing as ta
|
9
9
|
import zlib
|
10
10
|
|
11
|
-
from .. import fnpairs as fpa
|
12
11
|
from .. import lang
|
13
12
|
from .. import secrets as sec
|
13
|
+
from ..funcs import pairs as fpa
|
14
14
|
from .cookies import dump_cookie
|
15
15
|
from .cookies import parse_cookie
|
16
16
|
from .json import JSON_TAGGER
|
omlish/marshal/base.py
CHANGED
@@ -89,8 +89,8 @@ from .. import check
|
|
89
89
|
from .. import collections as col
|
90
90
|
from .. import dataclasses as dc
|
91
91
|
from .. import lang
|
92
|
-
from .. import matchfns as mfs
|
93
92
|
from .. import reflect as rfl
|
93
|
+
from ..funcs import match as mfs
|
94
94
|
from .exceptions import UnhandledTypeError
|
95
95
|
from .factories import RecursiveTypeFactory
|
96
96
|
from .factories import TypeCacheFactory
|
omlish/marshal/factories.py
CHANGED
omlish/marshal/forbidden.py
CHANGED
omlish/marshal/iterables.py
CHANGED
@@ -8,8 +8,8 @@ import functools
|
|
8
8
|
import typing as ta
|
9
9
|
|
10
10
|
from .. import check
|
11
|
-
from .. import matchfns as mfs
|
12
11
|
from .. import reflect as rfl
|
12
|
+
from ..funcs import match as mfs
|
13
13
|
from .base import MarshalContext
|
14
14
|
from .base import Marshaler
|
15
15
|
from .base import MarshalerFactoryMatchClass
|
omlish/marshal/mappings.py
CHANGED
@@ -3,8 +3,8 @@ import dataclasses as dc
|
|
3
3
|
import typing as ta
|
4
4
|
|
5
5
|
from .. import check
|
6
|
-
from .. import matchfns as mfs
|
7
6
|
from .. import reflect as rfl
|
7
|
+
from ..funcs import match as mfs
|
8
8
|
from .base import MarshalContext
|
9
9
|
from .base import Marshaler
|
10
10
|
from .base import MarshalerFactoryMatchClass
|
omlish/marshal/maybes.py
CHANGED
@@ -7,8 +7,8 @@ import typing as ta
|
|
7
7
|
|
8
8
|
from .. import check
|
9
9
|
from .. import lang
|
10
|
-
from .. import matchfns as mfs
|
11
10
|
from .. import reflect as rfl
|
11
|
+
from ..funcs import match as mfs
|
12
12
|
from .base import MarshalContext
|
13
13
|
from .base import Marshaler
|
14
14
|
from .base import MarshalerFactoryMatchClass
|
omlish/marshal/standard.py
CHANGED
omlish/marshal/unions.py
CHANGED
@@ -4,8 +4,8 @@ from .. import cached
|
|
4
4
|
from .. import check
|
5
5
|
from .. import dataclasses as dc
|
6
6
|
from .. import lang
|
7
|
-
from .. import matchfns as mfs
|
8
7
|
from .. import reflect as rfl
|
8
|
+
from ..funcs import match as mfs
|
9
9
|
from .base import MarshalContext
|
10
10
|
from .base import Marshaler
|
11
11
|
from .base import MarshalerFactory
|
omlish/secrets/pwhash.py
CHANGED
omlish/secrets/subprocesses.py
CHANGED
@@ -32,7 +32,9 @@ def pipe_fd_subprocess_file_input(buf: bytes) -> ta.Iterator[SubprocessFileInput
|
|
32
32
|
try:
|
33
33
|
if hasattr(fcntl, 'F_SETPIPE_SZ'):
|
34
34
|
fcntl.fcntl(wfd, fcntl.F_SETPIPE_SZ, max(len(buf), 0x1000))
|
35
|
-
os.write(wfd, buf)
|
35
|
+
n = os.write(wfd, buf)
|
36
|
+
if n != len(buf):
|
37
|
+
raise OSError(f'Failed to write data to pipe: {n=} {len(buf)=}')
|
36
38
|
os.close(wfd)
|
37
39
|
closed_wfd = True
|
38
40
|
yield SubprocessFileInput(f'/dev/fd/{rfd}', [rfd])
|
omlish/specs/jsonrpc/marshal.py
CHANGED
omlish/specs/openapi/marshal.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
omlish/.manifests.json,sha256=
|
2
|
-
omlish/__about__.py,sha256=
|
1
|
+
omlish/.manifests.json,sha256=RX24SRc6DCEg77PUVnaXOKCWa5TF_c9RQJdGIf7gl9c,1135
|
2
|
+
omlish/__about__.py,sha256=CWnfySakfsMZZD27TmuHHIWSs20C8yL_8HidsVhkFwM,3379
|
3
3
|
omlish/__init__.py,sha256=SsyiITTuK0v74XpKV8dqNaCmjOlan1JZKrHQv5rWKPA,253
|
4
4
|
omlish/argparse.py,sha256=cqKGAqcxuxv_s62z0gq29L9KAvg_3-_rFvXKjVpRJjo,8126
|
5
5
|
omlish/c3.py,sha256=ubu7lHwss5V4UznbejAI0qXhXahrU01MysuHOZI9C4U,8116
|
@@ -8,12 +8,8 @@ omlish/check.py,sha256=Li5xmecEyWKMzlwWyd6xDHpq3F4lE6IFOPBWdylCnpU,10540
|
|
8
8
|
omlish/datetimes.py,sha256=HajeM1kBvwlTa-uR1TTZHmZ3zTPnnUr1uGGQhiO1XQ0,2152
|
9
9
|
omlish/defs.py,sha256=T3bq_7h_tO3nDB5RAFBn7DkdeQgqheXzkFColbOHZko,4890
|
10
10
|
omlish/dynamic.py,sha256=35C_cCX_Vq2HrHzGk5T-zbrMvmUdiIiwDzDNixczoDo,6541
|
11
|
-
omlish/fnpairs.py,sha256=3ZPV5DRTWSFA8_DYKL4iXT-E4483QdfUfshs-X_UVIs,10603
|
12
|
-
omlish/fnpipes.py,sha256=E7Sz8Aj8ke_vCs5AMNwg1I36kRdHVGTnzxVQaDyn43U,2490
|
13
|
-
omlish/genmachine.py,sha256=RlU-y_dt2nRdvoo7Z3HsUELlBn3KuyI4qUnqLVbChRI,2450
|
14
11
|
omlish/iterators.py,sha256=GGLC7RIT86uXMjhIIIqnff_Iu5SI_b9rXYywYGFyzmo,7292
|
15
12
|
omlish/libc.py,sha256=8r7Ejyhttk9ruCfBkxNTrlzir5WPbDE2vmY7VPlceMA,15362
|
16
|
-
omlish/matchfns.py,sha256=I1IlQGfEyk_AcFSy6ulVS3utC-uwyZM2YfUXYHc9Bw0,6152
|
17
13
|
omlish/multiprocessing.py,sha256=QZT4C7I-uThCAjaEY3xgUYb-5GagUlnE4etN01LDyU4,5186
|
18
14
|
omlish/os.py,sha256=5nJ-a9JKSMoaZVZ1eOa5BAbfL7o7CF7ue_PyJwufnwY,1460
|
19
15
|
omlish/runmodule.py,sha256=PWvuAaJ9wQQn6bx9ftEL3_d04DyotNn8dR_twm2pgw0,700
|
@@ -196,19 +192,16 @@ omlish/formats/json/backends/jiter.py,sha256=8qv_XWGpcupPtVm6Z_egHio_iY1Kk8eqkvX
|
|
196
192
|
omlish/formats/json/backends/orjson.py,sha256=wR8pMGFtkhZGHcNVk7vNYUnv8lUapdK89p6QpETIs9w,3778
|
197
193
|
omlish/formats/json/backends/std.py,sha256=PM00Kh9ZR2XzollHMEvdo35Eml1N-zFfRW-LOCV5ftM,3085
|
198
194
|
omlish/formats/json/backends/ujson.py,sha256=BNJCU4kluGHdqTUKLJEuHhE2m2TmqR7HEN289S0Eokg,2278
|
199
|
-
omlish/formats/json/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
200
|
-
omlish/formats/json/cli/__main__.py,sha256=1wxxKZVkj_u7HCcewwMIbGuZj_Wph95yrUbm474Op9M,188
|
201
|
-
omlish/formats/json/cli/cli.py,sha256=dRtkX9cqXmff0RnYXAyXX324zbi2z0cg2Efp_5BOx0k,9575
|
202
|
-
omlish/formats/json/cli/formats.py,sha256=FUZ0ptn3n0ljei2_o0t5UtmZkMB3_5p1pE-hgDD3-ak,1721
|
203
|
-
omlish/formats/json/cli/io.py,sha256=IoJ5asjS_gUan5TcrGgS0KpJaiSE5YQgEGljFMCcDto,1427
|
204
|
-
omlish/formats/json/cli/parsing.py,sha256=GfD6Om9FDaTJ662qROKSftSdp95tbw22Ids_vkMJV7U,2100
|
205
|
-
omlish/formats/json/cli/processing.py,sha256=UXHA_5El1qSDjPlJBBfREzHA_T2GNmP6nD1X99GNqOM,1214
|
206
|
-
omlish/formats/json/cli/rendering.py,sha256=cmnGAUqY0vKlMYHMBydIBgbs23Isdobf1F8cRk8o9f0,2182
|
207
195
|
omlish/formats/json/stream/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
208
196
|
omlish/formats/json/stream/build.py,sha256=MSxgreWSfI5CzNAdgQrArZ0yWqDsaHl-shI_jmjLDms,2505
|
209
|
-
omlish/formats/json/stream/lex.py,sha256=
|
210
|
-
omlish/formats/json/stream/parse.py,sha256=
|
197
|
+
omlish/formats/json/stream/lex.py,sha256=_JYBFnAyHsw_3hu8I0rvZqSSkRCU1BvQzgO81KfqRBg,6489
|
198
|
+
omlish/formats/json/stream/parse.py,sha256=s21PgiuNTcqc_i9QS1ggmEp8Qwp_hOqtosr5d0zpg_o,5204
|
211
199
|
omlish/formats/json/stream/render.py,sha256=NtmDsN92xZi5dkgSSuMeMXMAiJblmjz1arB4Ft7vBhc,3715
|
200
|
+
omlish/funcs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
201
|
+
omlish/funcs/genmachine.py,sha256=RlU-y_dt2nRdvoo7Z3HsUELlBn3KuyI4qUnqLVbChRI,2450
|
202
|
+
omlish/funcs/match.py,sha256=gMLZn1enNiFvQaWrQubY300M1BrmdKWzeePihBS7Ywc,6153
|
203
|
+
omlish/funcs/pairs.py,sha256=OzAwnALkRJXVpD47UvBZHKzQfHtFNry_EgjTcC7vgLU,10606
|
204
|
+
omlish/funcs/pipes.py,sha256=E7Sz8Aj8ke_vCs5AMNwg1I36kRdHVGTnzxVQaDyn43U,2490
|
212
205
|
omlish/graphs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
213
206
|
omlish/graphs/dags.py,sha256=zp55lYgUdRCxmADwiGDHeehMJczZFA_tzdWqy77icOk,3047
|
214
207
|
omlish/graphs/domination.py,sha256=oCGoWzWTxLwow0LDyGjjEf2AjFiOiDz4WaBtczwSbsQ,7576
|
@@ -229,7 +222,7 @@ omlish/http/headers.py,sha256=ZMmjrEiYjzo0YTGyK0YsvjdwUazktGqzVVYorY4fd44,5081
|
|
229
222
|
omlish/http/json.py,sha256=9XwAsl4966Mxrv-1ytyCqhcE6lbBJw-0_tFZzGszgHE,7440
|
230
223
|
omlish/http/jwt.py,sha256=6Rigk1WrJ059DY4jDIKnxjnChWb7aFdermj2AI2DSvk,4346
|
231
224
|
omlish/http/multipart.py,sha256=R9ycpHsXRcmh0uoc43aYb7BdWL-8kSQHe7J-M81aQZM,2240
|
232
|
-
omlish/http/sessions.py,sha256=
|
225
|
+
omlish/http/sessions.py,sha256=WVRTy2KjehwQiYTPn7r44gZ4Pqg8sDC_9-wiYON0344,4796
|
233
226
|
omlish/http/sse.py,sha256=MDs9RvxQXoQliImcc6qK1ERajEYM7Q1l8xmr-9ceNBc,2315
|
234
227
|
omlish/http/wsgi.py,sha256=czZsVUX-l2YTlMrUjKN49wRoP4rVpS0qpeBn4O5BoMY,948
|
235
228
|
omlish/inject/__init__.py,sha256=n0RC9UDGsBQQ39cST39-XJqJPq2M0tnnh9yJubW9azo,1891
|
@@ -339,19 +332,19 @@ omlish/logs/noisy.py,sha256=Ubc-eTH6ZbGYsLfUUi69JAotwuUwzb-SJBeGo_0dIZI,348
|
|
339
332
|
omlish/logs/utils.py,sha256=MgGovbP0zUrZ3FGD3qYNQWn-l0jy0Y0bStcQvv5BOmQ,391
|
340
333
|
omlish/marshal/__init__.py,sha256=iVA7n31L08Bdub6HKPvYOXVvDhk2CMA6rPeKDL_u1to,2298
|
341
334
|
omlish/marshal/any.py,sha256=e82OyYK3Emm1P1ClnsnxP7fIWC2iNVyW0H5nK4mLmWM,779
|
342
|
-
omlish/marshal/base.py,sha256=
|
335
|
+
omlish/marshal/base.py,sha256=HEzfby-PgGzIhiRpBkFrkw5-hKacRSC5W_jwLjT8aYw,6740
|
343
336
|
omlish/marshal/base64.py,sha256=F-3ogJdcFCtWINRgJgWT0rErqgx6f4qahhcg8OrkqhE,1089
|
344
337
|
omlish/marshal/dataclasses.py,sha256=G6Uh8t4vvNBAx2BhzH8ksj8Hq_bo6npFphQhyF298VU,6892
|
345
338
|
omlish/marshal/datetimes.py,sha256=0ffg8cEvx9SMKIXZGD9b7MqpLfmgw0uKKdn6YTfoqok,3714
|
346
339
|
omlish/marshal/enums.py,sha256=CMAbx6RI2EcQoo7SoD-5q2l-3DFKreWMiOxs6mFpl_4,1472
|
347
340
|
omlish/marshal/exceptions.py,sha256=jwQWn4LcPnadT2KRI_1JJCOSkwWh0yHnYK9BmSkNN4U,302
|
348
|
-
omlish/marshal/factories.py,sha256=
|
349
|
-
omlish/marshal/forbidden.py,sha256=
|
341
|
+
omlish/marshal/factories.py,sha256=Q926jSVjaQLEmStnHLhm_c_vqEysN1LnDCwAsFLIzXw,2970
|
342
|
+
omlish/marshal/forbidden.py,sha256=NDe828hqCQw-AgxcEm8MiDZNxWoBwf3o7sTyvQsSsQ0,867
|
350
343
|
omlish/marshal/global_.py,sha256=K76wB1-pdg4VWgiqR7wyxRNYr-voJApexYW2nV-R4DM,1127
|
351
344
|
omlish/marshal/helpers.py,sha256=-SOgYJmrURILHpPK6Wu3cCvhj8RJrqfJxuKhh9UMs7o,1102
|
352
|
-
omlish/marshal/iterables.py,sha256=
|
353
|
-
omlish/marshal/mappings.py,sha256=
|
354
|
-
omlish/marshal/maybes.py,sha256=
|
345
|
+
omlish/marshal/iterables.py,sha256=H9FoCB5RlJW0SVSi3SBD6sxOXN9XRTOUkHRwCYSqRb8,2632
|
346
|
+
omlish/marshal/mappings.py,sha256=XcNOaV708ZHeuIrWiFHC6F1O6U9NyyTKUurvXwIryJo,2789
|
347
|
+
omlish/marshal/maybes.py,sha256=i-gOQJ-7tdt6sOazAeyCh4N71SK3jWv-BKlkx-fZm-s,2200
|
355
348
|
omlish/marshal/namedtuples.py,sha256=H0icxcE5FrqgfI9dRc8LlXJy430g_yuILTCVD0Zvfd0,2799
|
356
349
|
omlish/marshal/naming.py,sha256=lIklR_Od4x1ghltAgOzqcKhHs-leeSv2YmFhCHO7GIs,613
|
357
350
|
omlish/marshal/newtypes.py,sha256=fRpXLoCpoiaqcvl7v92I1_Qt7udn4vsPc1P3UfcBu-8,841
|
@@ -362,8 +355,8 @@ omlish/marshal/optionals.py,sha256=r0XB5rqfasvgZJNrKYd6Unq2U4nHt3JURi26j0dYHlw,1
|
|
362
355
|
omlish/marshal/polymorphism.py,sha256=2SxrfneA9QdhNdxieEGFnHDHpUo3ftETA9dMbCbmbWY,6511
|
363
356
|
omlish/marshal/primitives.py,sha256=f_6m24Cb-FDGsZpYSas11nLt3xCCEUXugw3Hv4-aNhg,1291
|
364
357
|
omlish/marshal/registries.py,sha256=FvC6qXHCizNB2QmU_N3orxW7iqfGYkiUXYYdTRWS6HA,2353
|
365
|
-
omlish/marshal/standard.py,sha256=
|
366
|
-
omlish/marshal/unions.py,sha256=
|
358
|
+
omlish/marshal/standard.py,sha256=UMET8wkxf__ApIDuVcoCKsjNWwZejbICLeXhhmn56Nk,3321
|
359
|
+
omlish/marshal/unions.py,sha256=tT4W-mxuPi7s_kdl25_AUltsurYPO_0mQl2CiVmNonY,4357
|
367
360
|
omlish/marshal/utils.py,sha256=puKJpwPpuDlMOIrKMcLTRLJyMiL6n_Xs-p59AuDEymA,543
|
368
361
|
omlish/marshal/uuids.py,sha256=H4B7UX_EPNmP2tC8bubcKrPLTS4aQu98huvbXQ3Zv2g,910
|
369
362
|
omlish/marshal/values.py,sha256=ssHiWdg_L6M17kAn8GiGdPW7UeQOm3RDikWkvwblf5I,263
|
@@ -381,9 +374,9 @@ omlish/secrets/crypto.py,sha256=6CsLy0UEqCrBK8Xx_3-iFF6SKtu2GlEqUQ8-MliY3tk,3709
|
|
381
374
|
omlish/secrets/marshal.py,sha256=U9uSRTWzZmumfNZeh_dROwVdGrARsp155TylRbjilP8,2048
|
382
375
|
omlish/secrets/openssl.py,sha256=wxA_wIlxtuOUy71ABxAJgavh-UI_taOfm-A0dVlmSwM,6219
|
383
376
|
omlish/secrets/pwgen.py,sha256=v-5ztnOTHTAWXLGR-3H6HkMj2nPIZBMbo5xWR3q0rDY,1707
|
384
|
-
omlish/secrets/pwhash.py,sha256=
|
377
|
+
omlish/secrets/pwhash.py,sha256=Goktn-swmC6PXqfRBnDrH_Lr42vjckT712UyErPjzkw,4102
|
385
378
|
omlish/secrets/secrets.py,sha256=cnDGBoPknVxsCN04_gqcJT_7Ebk3iO3VPkRZ2oMjkMw,7868
|
386
|
-
omlish/secrets/subprocesses.py,sha256=
|
379
|
+
omlish/secrets/subprocesses.py,sha256=ffjfbgPbEE_Pwb_87vG4yYR2CGZy3I31mHNCo_0JtHw,1212
|
387
380
|
omlish/specs/__init__.py,sha256=zZwF8yXTEkSstYtORkDhVLK-_hWU8WOJCuBpognb_NY,118
|
388
381
|
omlish/specs/jmespath/LICENSE,sha256=IH-ZZlZkS8XMkf_ubNVD1aYHQ2l_wd0tmHtXrCcYpRU,1113
|
389
382
|
omlish/specs/jmespath/__init__.py,sha256=9tsrquw1kXe1KAhTP3WeL0GlGBiTguQVxsC-lUYTWP4,2087
|
@@ -398,7 +391,7 @@ omlish/specs/jmespath/scope.py,sha256=UyDsl9rv_c8DCjJBuVIA2ESu1jrgYvuwEKiaJDQKnT
|
|
398
391
|
omlish/specs/jmespath/visitor.py,sha256=yneRMO4qf3k2Mdcm2cPC0ozRgOaudzlxRVRGatztJzs,16569
|
399
392
|
omlish/specs/jsonrpc/__init__.py,sha256=E0EogYSKmbj1D-V57tBgPDTyVuD8HosHqVg0Vh1CVwM,416
|
400
393
|
omlish/specs/jsonrpc/errors.py,sha256=-Zgmlo6bV6J8w5f8h9axQgLquIFBHDgIwcpufEH5NsE,707
|
401
|
-
omlish/specs/jsonrpc/marshal.py,sha256=
|
394
|
+
omlish/specs/jsonrpc/marshal.py,sha256=hM1rPZddoha_87qcQtBWkyaZshCXlPoHPJg6J_nBi9k,1915
|
402
395
|
omlish/specs/jsonrpc/types.py,sha256=g19j2_FCVJDXFqAkQ5U4LICkL4Z7vEBMU0t_aOEqio4,2159
|
403
396
|
omlish/specs/jsonschema/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
404
397
|
omlish/specs/jsonschema/types.py,sha256=qoxExgKfrI-UZXdk3qcVZIEyp1WckFbb85_eGInEoAY,467
|
@@ -423,7 +416,7 @@ omlish/specs/jsonschema/schemas/draft202012/vocabularies/meta-data.json,sha256=j
|
|
423
416
|
omlish/specs/jsonschema/schemas/draft202012/vocabularies/unevaluated.json,sha256=Lb-8tzmUtnCwl2SSre4f_7RsIWgnhNL1pMpWH54tDLQ,506
|
424
417
|
omlish/specs/jsonschema/schemas/draft202012/vocabularies/validation.json,sha256=cBCjHlQfMtK-ch4t40jfdcmzaHaj7TBId_wKvaHTelg,2834
|
425
418
|
omlish/specs/openapi/__init__.py,sha256=zilQhafjvteRDF_TUIRgF293dBC6g-TJChmUb6T9VBQ,77
|
426
|
-
omlish/specs/openapi/marshal.py,sha256=
|
419
|
+
omlish/specs/openapi/marshal.py,sha256=Z-E2Knm04C81N8AA8cibCVSl2ImhSpHZVc7yAhmPx88,2135
|
427
420
|
omlish/specs/openapi/openapi.py,sha256=y4h04jeB7ORJSVrcy7apaBdpwLjIyscv1Ub5SderH2c,12682
|
428
421
|
omlish/sql/__init__.py,sha256=TpZLsEJKJzvJ0eMzuV8hwOJJbkxBCV1RZPUMLAVB6io,173
|
429
422
|
omlish/sql/_abc.py,sha256=kiOitW_ZhTXrJanJ582wD7o9K69v6HXqDPkxuHEAxrc,1606
|
@@ -487,9 +480,9 @@ omlish/text/glyphsplit.py,sha256=Ug-dPRO7x-OrNNr8g1y6DotSZ2KH0S-VcOmUobwa4B0,329
|
|
487
480
|
omlish/text/indent.py,sha256=6Jj6TFY9unaPa4xPzrnZemJ-fHsV53IamP93XGjSUHs,1274
|
488
481
|
omlish/text/parts.py,sha256=7vPF1aTZdvLVYJ4EwBZVzRSy8XB3YqPd7JwEnNGGAOo,6495
|
489
482
|
omlish/text/random.py,sha256=jNWpqiaKjKyTdMXC-pWAsSC10AAP-cmRRPVhm59ZWLk,194
|
490
|
-
omlish-0.0.0.
|
491
|
-
omlish-0.0.0.
|
492
|
-
omlish-0.0.0.
|
493
|
-
omlish-0.0.0.
|
494
|
-
omlish-0.0.0.
|
495
|
-
omlish-0.0.0.
|
483
|
+
omlish-0.0.0.dev136.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
484
|
+
omlish-0.0.0.dev136.dist-info/METADATA,sha256=heiHEjvH_MYIlgwIfTWaObhQg178414yEPPo1_ZbNjU,4173
|
485
|
+
omlish-0.0.0.dev136.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
486
|
+
omlish-0.0.0.dev136.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
487
|
+
omlish-0.0.0.dev136.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
488
|
+
omlish-0.0.0.dev136.dist-info/RECORD,,
|
omlish/formats/json/cli/cli.py
DELETED
@@ -1,298 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
TODO:
|
3
|
-
- read from http
|
4
|
-
- jmespath output flat, unquoted strs like jq '.[]'
|
5
|
-
|
6
|
-
==
|
7
|
-
|
8
|
-
jq Command options:
|
9
|
-
-n, --null-input use `null` as the single input value;
|
10
|
-
-R, --raw-input read each line as string instead of JSON;
|
11
|
-
-s, --slurp read all inputs into an array and use it as the single input value;
|
12
|
-
-c, --compact-output compact instead of pretty-printed output;
|
13
|
-
-r, --raw-output output strings without escapes and quotes;
|
14
|
-
--raw-output0 implies -r and output NUL after each output;
|
15
|
-
-j, --join-output implies -r and output without newline after each output;
|
16
|
-
-a, --ascii-output output strings by only ASCII characters using escape sequences;
|
17
|
-
-S, --sort-keys sort keys of each object on output;
|
18
|
-
-C, --color-output colorize JSON output;
|
19
|
-
-M, --monochrome-output disable colored output;
|
20
|
-
--tab use tabs for indentation;
|
21
|
-
--indent n use n spaces for indentation (max 7 spaces);
|
22
|
-
--unbuffered flush output stream after each output;
|
23
|
-
--stream parse the input value in streaming fashion;
|
24
|
-
--stream-errors implies --stream and report parse error as an array;
|
25
|
-
--seq parse input/output as application/json-seq;
|
26
|
-
-f, --from-file file load filter from the file;
|
27
|
-
-L directory search modules from the directory;
|
28
|
-
--arg name value set $name to the string value;
|
29
|
-
--argjson name value set $name to the JSON value;
|
30
|
-
--slurpfile name file set $name to an array of JSON values read from the file;
|
31
|
-
--rawfile name file set $name to string contents of file;
|
32
|
-
--args consume remaining arguments as positional string values;
|
33
|
-
--jsonargs consume remaining arguments as positional JSON values;
|
34
|
-
-e, --exit-status set exit status code based on the output;
|
35
|
-
-V, --version show the version;
|
36
|
-
--build-configuration show jq's build configuration;
|
37
|
-
-h, --help show the help;
|
38
|
-
-- terminates argument processing;
|
39
|
-
"""
|
40
|
-
import argparse
|
41
|
-
import contextlib
|
42
|
-
import dataclasses as dc
|
43
|
-
import io
|
44
|
-
import os
|
45
|
-
import subprocess
|
46
|
-
import sys
|
47
|
-
import typing as ta
|
48
|
-
|
49
|
-
from .... import check
|
50
|
-
from .... import fnpipes as fp
|
51
|
-
from .... import lang
|
52
|
-
from .formats import FORMATS_BY_NAME
|
53
|
-
from .formats import Format
|
54
|
-
from .formats import Formats
|
55
|
-
from .parsing import DelimitingParser
|
56
|
-
from .parsing import EagerParser
|
57
|
-
from .parsing import StreamBuilder
|
58
|
-
from .parsing import StreamParser
|
59
|
-
from .processing import ProcessingOptions
|
60
|
-
from .processing import Processor
|
61
|
-
from .rendering import EagerRenderer
|
62
|
-
from .rendering import RenderingOptions
|
63
|
-
from .rendering import StreamRenderer
|
64
|
-
|
65
|
-
|
66
|
-
T = ta.TypeVar('T')
|
67
|
-
U = ta.TypeVar('U')
|
68
|
-
|
69
|
-
|
70
|
-
def _build_args_parser() -> argparse.ArgumentParser:
|
71
|
-
parser = argparse.ArgumentParser()
|
72
|
-
|
73
|
-
parser.add_argument('file', nargs='?')
|
74
|
-
|
75
|
-
parser.add_argument('--stream', action='store_true')
|
76
|
-
parser.add_argument('--stream-build', action='store_true')
|
77
|
-
|
78
|
-
parser.add_argument('-l', '--lines', action='store_true')
|
79
|
-
|
80
|
-
parser.add_argument('--read-buffer-size', type=int, default=0x4000)
|
81
|
-
|
82
|
-
parser.add_argument('-f', '--format')
|
83
|
-
|
84
|
-
parser.add_argument('-x', '--jmespath-expr')
|
85
|
-
parser.add_argument('-F', '--flat', action='store_true')
|
86
|
-
|
87
|
-
parser.add_argument('-z', '--compact', action='store_true')
|
88
|
-
parser.add_argument('-p', '--pretty', action='store_true')
|
89
|
-
parser.add_argument('-i', '--indent')
|
90
|
-
parser.add_argument('-s', '--sort-keys', action='store_true')
|
91
|
-
parser.add_argument('-R', '--raw', action='store_true')
|
92
|
-
parser.add_argument('-U', '--unicode', action='store_true')
|
93
|
-
parser.add_argument('-c', '--color', action='store_true')
|
94
|
-
|
95
|
-
parser.add_argument('-L', '--less', action='store_true')
|
96
|
-
|
97
|
-
return parser
|
98
|
-
|
99
|
-
|
100
|
-
def _parse_args(args: ta.Any = None) -> ta.Any:
|
101
|
-
return _build_args_parser().parse_args(args)
|
102
|
-
|
103
|
-
|
104
|
-
@dc.dataclass(frozen=True, kw_only=True)
|
105
|
-
class RunConfiguration:
|
106
|
-
format: Format
|
107
|
-
processing: ProcessingOptions
|
108
|
-
rendering: RenderingOptions
|
109
|
-
|
110
|
-
|
111
|
-
def _process_args(args: ta.Any) -> RunConfiguration:
|
112
|
-
fmt_name = args.format
|
113
|
-
if fmt_name is None:
|
114
|
-
if args.file is not None:
|
115
|
-
ext = args.file.rpartition('.')[2]
|
116
|
-
if ext in FORMATS_BY_NAME:
|
117
|
-
fmt_name = ext
|
118
|
-
if fmt_name is None:
|
119
|
-
fmt_name = 'json'
|
120
|
-
format = FORMATS_BY_NAME[fmt_name] # noqa
|
121
|
-
|
122
|
-
if args.stream:
|
123
|
-
check.arg(format is Formats.JSON.value)
|
124
|
-
|
125
|
-
#
|
126
|
-
|
127
|
-
processing = ProcessingOptions(
|
128
|
-
jmespath_expr=args.jmespath_expr,
|
129
|
-
flat=args.flat,
|
130
|
-
)
|
131
|
-
|
132
|
-
#
|
133
|
-
|
134
|
-
separators = None
|
135
|
-
if args.compact:
|
136
|
-
separators = (',', ':')
|
137
|
-
|
138
|
-
indent = None
|
139
|
-
if args.pretty:
|
140
|
-
indent = 2
|
141
|
-
if args.indent:
|
142
|
-
try:
|
143
|
-
indent = int(args.indent)
|
144
|
-
except ValueError:
|
145
|
-
indent = args.indent
|
146
|
-
|
147
|
-
rendering = RenderingOptions(
|
148
|
-
indent=indent,
|
149
|
-
separators=separators,
|
150
|
-
sort_keys=args.sort_keys,
|
151
|
-
raw=args.raw,
|
152
|
-
unicode=args.unicode,
|
153
|
-
color=args.color,
|
154
|
-
)
|
155
|
-
|
156
|
-
#
|
157
|
-
|
158
|
-
return RunConfiguration(
|
159
|
-
format=format,
|
160
|
-
processing=processing,
|
161
|
-
rendering=rendering,
|
162
|
-
)
|
163
|
-
|
164
|
-
|
165
|
-
def _main() -> None:
|
166
|
-
args = _parse_args()
|
167
|
-
|
168
|
-
#
|
169
|
-
|
170
|
-
cfg = _process_args(args)
|
171
|
-
|
172
|
-
#
|
173
|
-
|
174
|
-
with contextlib.ExitStack() as es:
|
175
|
-
if args.file is None:
|
176
|
-
in_file = sys.stdin.buffer
|
177
|
-
|
178
|
-
else:
|
179
|
-
in_file = es.enter_context(open(args.file, 'rb'))
|
180
|
-
|
181
|
-
def yield_input() -> ta.Generator[bytes, None, None]:
|
182
|
-
fd = check.isinstance(in_file.fileno(), int)
|
183
|
-
|
184
|
-
while True:
|
185
|
-
buf = os.read(fd, args.read_buffer_size)
|
186
|
-
|
187
|
-
yield buf
|
188
|
-
|
189
|
-
if not buf:
|
190
|
-
break
|
191
|
-
|
192
|
-
#
|
193
|
-
|
194
|
-
if args.less:
|
195
|
-
less = subprocess.Popen(
|
196
|
-
[
|
197
|
-
'less',
|
198
|
-
*(['-R'] if cfg.rendering.color else []),
|
199
|
-
],
|
200
|
-
stdin=subprocess.PIPE,
|
201
|
-
encoding='utf-8',
|
202
|
-
)
|
203
|
-
out = check.not_none(less.stdin)
|
204
|
-
|
205
|
-
def close_less() -> None:
|
206
|
-
out.close()
|
207
|
-
less.wait()
|
208
|
-
|
209
|
-
es.enter_context(lang.defer(close_less)) # noqa
|
210
|
-
|
211
|
-
else:
|
212
|
-
out = sys.stdout
|
213
|
-
|
214
|
-
#
|
215
|
-
|
216
|
-
parser: ta.Any
|
217
|
-
renderer: ta.Any
|
218
|
-
|
219
|
-
if args.stream:
|
220
|
-
with contextlib.ExitStack() as es2:
|
221
|
-
parser = es2.enter_context(StreamParser())
|
222
|
-
|
223
|
-
def flush_output(
|
224
|
-
fn: ta.Callable[[T], ta.Iterable[U]],
|
225
|
-
i: T,
|
226
|
-
) -> ta.Generator[U, None, None]:
|
227
|
-
n = 0
|
228
|
-
for o in fn(i):
|
229
|
-
yield o
|
230
|
-
n += 1
|
231
|
-
if n:
|
232
|
-
out.flush()
|
233
|
-
|
234
|
-
pipeline: ta.Any
|
235
|
-
|
236
|
-
if args.stream_build:
|
237
|
-
builder: StreamBuilder = es2.enter_context(StreamBuilder())
|
238
|
-
processor = Processor(cfg.processing)
|
239
|
-
renderer = EagerRenderer(cfg.rendering)
|
240
|
-
trailing_newline = False
|
241
|
-
|
242
|
-
def append_newlines(
|
243
|
-
fn: ta.Callable[[T], ta.Iterable[str]],
|
244
|
-
i: T,
|
245
|
-
) -> ta.Generator[str, None, None]:
|
246
|
-
yield from fn(i)
|
247
|
-
yield '\n'
|
248
|
-
|
249
|
-
pipeline = lambda v: (renderer.render(v),) # Any -> [str] # noqa
|
250
|
-
pipeline = fp.bind(append_newlines, pipeline) # Any -> [str]
|
251
|
-
pipeline = fp.bind(lang.flatmap, pipeline) # [Any] -> [str]
|
252
|
-
pipeline = fp.pipe(fp.bind(lang.flatmap, processor.process), pipeline) # [Any] -> [str]
|
253
|
-
pipeline = fp.pipe(fp.bind(lang.flatmap, builder.build), pipeline) # [JsonStreamParserEvent] -> [str] # noqa
|
254
|
-
pipeline = fp.pipe(parser.parse, pipeline) # bytes -> [str]
|
255
|
-
|
256
|
-
else:
|
257
|
-
renderer = StreamRenderer(cfg.rendering)
|
258
|
-
trailing_newline = True
|
259
|
-
|
260
|
-
pipeline = renderer.render # JsonStreamParserEvent -> [str]
|
261
|
-
pipeline = fp.bind(lang.flatmap, pipeline) # [JsonStreamParserEvent] -> [str]
|
262
|
-
pipeline = fp.pipe(parser.parse, pipeline) # bytes -> [str]
|
263
|
-
|
264
|
-
pipeline = fp.bind(flush_output, pipeline) # bytes -> [str]
|
265
|
-
|
266
|
-
for buf in yield_input():
|
267
|
-
for s in pipeline(buf):
|
268
|
-
print(s, file=out, end='')
|
269
|
-
|
270
|
-
if trailing_newline:
|
271
|
-
print(file=out)
|
272
|
-
|
273
|
-
elif args.lines:
|
274
|
-
parser = DelimitingParser(cfg.format)
|
275
|
-
processor = Processor(cfg.processing)
|
276
|
-
renderer = EagerRenderer(cfg.rendering)
|
277
|
-
|
278
|
-
for buf in yield_input():
|
279
|
-
for v in parser.parse(buf):
|
280
|
-
for e in processor.process(v):
|
281
|
-
s = renderer.render(e)
|
282
|
-
print(s, file=out)
|
283
|
-
|
284
|
-
else:
|
285
|
-
parser = EagerParser(cfg.format)
|
286
|
-
processor = Processor(cfg.processing)
|
287
|
-
renderer = EagerRenderer(cfg.rendering)
|
288
|
-
|
289
|
-
with io.TextIOWrapper(in_file) as tf:
|
290
|
-
v = parser.parse(tf)
|
291
|
-
|
292
|
-
for e in processor.process(v):
|
293
|
-
s = renderer.render(e)
|
294
|
-
print(s, file=out)
|
295
|
-
|
296
|
-
|
297
|
-
if __name__ == '__main__':
|
298
|
-
_main()
|
@@ -1,71 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
TODO:
|
3
|
-
- options lol - csv header, newline, etc
|
4
|
-
"""
|
5
|
-
import dataclasses as dc
|
6
|
-
import enum
|
7
|
-
import json
|
8
|
-
import typing as ta
|
9
|
-
|
10
|
-
from .... import lang
|
11
|
-
|
12
|
-
|
13
|
-
if ta.TYPE_CHECKING:
|
14
|
-
import ast
|
15
|
-
import csv
|
16
|
-
import tomllib
|
17
|
-
|
18
|
-
import yaml
|
19
|
-
|
20
|
-
from ... import dotenv
|
21
|
-
from ... import props
|
22
|
-
from ... import xml
|
23
|
-
|
24
|
-
else:
|
25
|
-
ast = lang.proxy_import('ast')
|
26
|
-
csv = lang.proxy_import('csv')
|
27
|
-
tomllib = lang.proxy_import('tomllib')
|
28
|
-
|
29
|
-
yaml = lang.proxy_import('yaml')
|
30
|
-
|
31
|
-
dotenv = lang.proxy_import('...dotenv', __package__)
|
32
|
-
props = lang.proxy_import('...props', __package__)
|
33
|
-
xml = lang.proxy_import('...xml', __package__)
|
34
|
-
|
35
|
-
|
36
|
-
##
|
37
|
-
|
38
|
-
|
39
|
-
@dc.dataclass(frozen=True)
|
40
|
-
class Format:
|
41
|
-
names: ta.Sequence[str]
|
42
|
-
load: ta.Callable[[ta.TextIO], ta.Any]
|
43
|
-
|
44
|
-
|
45
|
-
class Formats(enum.Enum):
|
46
|
-
JSON = Format(['json'], json.load)
|
47
|
-
|
48
|
-
YAML = Format(['yaml', 'yml'], lambda f: yaml.safe_load(f))
|
49
|
-
|
50
|
-
TOML = Format(['toml'], lambda f: tomllib.loads(f.read()))
|
51
|
-
|
52
|
-
ENV = Format(['env', 'dotenv'], lambda f: dotenv.dotenv_values(stream=f))
|
53
|
-
|
54
|
-
PROPS = Format(['properties', 'props'], lambda f: dict(props.Properties().load(f.read())))
|
55
|
-
|
56
|
-
PY = Format(['py', 'python', 'repr'], lambda f: ast.literal_eval(f.read()))
|
57
|
-
|
58
|
-
XML = Format(['xml'], lambda f: xml.build_simple_element(xml.parse_tree(f.read()).getroot()).as_dict())
|
59
|
-
|
60
|
-
CSV = Format(['csv'], lambda f: list(csv.DictReader(f)))
|
61
|
-
TSV = Format(['tsv'], lambda f: list(csv.DictReader(f, delimiter='\t')))
|
62
|
-
FLAT_CSV = Format(['fcsv'], lambda f: list(csv.reader(f)))
|
63
|
-
FLAT_TSV = Format(['ftsv'], lambda f: list(csv.reader(f, delimiter='\t')))
|
64
|
-
|
65
|
-
|
66
|
-
FORMATS_BY_NAME: ta.Mapping[str, Format] = {
|
67
|
-
n: f
|
68
|
-
for e in Formats
|
69
|
-
for f in [e.value]
|
70
|
-
for n in f.names
|
71
|
-
}
|
omlish/formats/json/cli/io.py
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# """
|
2
|
-
# TODO:
|
3
|
-
# - -I/-Ogz, lz4, etc
|
4
|
-
# - fnpairs? or not yet just do it
|
5
|
-
# """
|
6
|
-
# import abc
|
7
|
-
# import contextlib
|
8
|
-
# import dataclasses as dc
|
9
|
-
# import gzip
|
10
|
-
# import os
|
11
|
-
# import typing as ta
|
12
|
-
#
|
13
|
-
# from .... import lang
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# if ta.TYPE_CHECKING:
|
17
|
-
# import bz2 as _bz2
|
18
|
-
# import gzip as _gzip
|
19
|
-
# import lzma as _lzma
|
20
|
-
# else:
|
21
|
-
# _bz2 = lang.proxy_import('bz2')
|
22
|
-
# _gzip = lang.proxy_import('gzip')
|
23
|
-
# _lzma = lang.proxy_import('lzma')
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# ##
|
27
|
-
#
|
28
|
-
#
|
29
|
-
# class BaseIo(lang.Abstract):
|
30
|
-
# def close(self) -> None:
|
31
|
-
# raise NotImplementedError
|
32
|
-
#
|
33
|
-
# def fileno(self) -> int | None:
|
34
|
-
# return None
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# class Input(BaseIo):
|
38
|
-
# @abc.abstractmethod
|
39
|
-
# def read(self, sz: int | None = None) -> bytes:
|
40
|
-
# raise NotImplementedError
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# class Output(BaseIo):
|
44
|
-
# @abc.abstractmethod
|
45
|
-
# def write(self, data: bytes) -> int:
|
46
|
-
# raise NotImplementedError
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# #
|
50
|
-
#
|
51
|
-
#
|
52
|
-
# DEFAULT_READ_SZ = 0x4000
|
53
|
-
#
|
54
|
-
#
|
55
|
-
# @dc.dataclass(frozen=True)
|
56
|
-
# class FdIo(Input, Output):
|
57
|
-
# fd: int
|
58
|
-
#
|
59
|
-
# default_read_sz: int = DEFAULT_READ_SZ
|
60
|
-
#
|
61
|
-
# def read(self, sz: int | None = None) -> bytes:
|
62
|
-
# return os.read(self.fd, sz or self.default_read_sz)
|
63
|
-
#
|
64
|
-
# def write(self, data: bytes) -> int:
|
65
|
-
# return os.write(self.fd, data)
|
66
|
-
#
|
67
|
-
#
|
68
|
-
# ##
|
69
|
-
#
|
70
|
-
#
|
71
|
-
# @contextlib.contextmanager
|
72
|
-
# def gzip_io_codec(f: ta.IO, mode: str) -> ta.ContextManager[ta.IO]:
|
73
|
-
# with gzip.open(f, mode) as o:
|
74
|
-
# yield o
|
@@ -1,82 +0,0 @@
|
|
1
|
-
import codecs
|
2
|
-
import io
|
3
|
-
import typing as ta
|
4
|
-
|
5
|
-
from .... import check
|
6
|
-
from .... import lang
|
7
|
-
from ....lite.io import DelimitingBuffer
|
8
|
-
from ..stream.build import JsonObjectBuilder
|
9
|
-
from ..stream.lex import JsonStreamLexer
|
10
|
-
from ..stream.parse import JsonStreamParser
|
11
|
-
from ..stream.parse import JsonStreamParserEvent
|
12
|
-
from .formats import Format
|
13
|
-
|
14
|
-
|
15
|
-
##
|
16
|
-
|
17
|
-
|
18
|
-
class EagerParser:
|
19
|
-
def __init__(self, fmt: Format) -> None:
|
20
|
-
super().__init__()
|
21
|
-
|
22
|
-
self._fmt = fmt
|
23
|
-
|
24
|
-
def parse(self, f: ta.TextIO) -> ta.Generator[ta.Any, None, None]:
|
25
|
-
return self._fmt.load(f)
|
26
|
-
|
27
|
-
|
28
|
-
##
|
29
|
-
|
30
|
-
|
31
|
-
class DelimitingParser:
|
32
|
-
def __init__(
|
33
|
-
self,
|
34
|
-
fmt: Format,
|
35
|
-
*,
|
36
|
-
delimiters: ta.Iterable[int] = b'\n',
|
37
|
-
) -> None:
|
38
|
-
super().__init__()
|
39
|
-
|
40
|
-
self._fmt = fmt
|
41
|
-
|
42
|
-
self._db = DelimitingBuffer(delimiters)
|
43
|
-
|
44
|
-
def parse(self, b: bytes) -> ta.Generator[ta.Any, None, None]:
|
45
|
-
for chunk in self._db.feed(b):
|
46
|
-
s = check.isinstance(chunk, bytes).decode('utf-8')
|
47
|
-
v = self._fmt.load(io.StringIO(s))
|
48
|
-
yield v
|
49
|
-
|
50
|
-
|
51
|
-
##
|
52
|
-
|
53
|
-
|
54
|
-
class StreamBuilder(lang.ExitStacked):
|
55
|
-
_builder: JsonObjectBuilder | None = None
|
56
|
-
|
57
|
-
def __enter__(self) -> ta.Self:
|
58
|
-
super().__enter__()
|
59
|
-
self._builder = self._enter_context(JsonObjectBuilder())
|
60
|
-
return self
|
61
|
-
|
62
|
-
def build(self, e: JsonStreamParserEvent) -> ta.Generator[ta.Any, None, None]:
|
63
|
-
yield from check.not_none(self._builder)(e)
|
64
|
-
|
65
|
-
|
66
|
-
class StreamParser(lang.ExitStacked):
|
67
|
-
_decoder: codecs.IncrementalDecoder
|
68
|
-
_lex: JsonStreamLexer
|
69
|
-
_parse: JsonStreamParser
|
70
|
-
|
71
|
-
def __enter__(self) -> ta.Self:
|
72
|
-
super().__enter__()
|
73
|
-
self._decoder = codecs.getincrementaldecoder('utf-8')()
|
74
|
-
self._lex = self._enter_context(JsonStreamLexer())
|
75
|
-
self._parse = self._enter_context(JsonStreamParser())
|
76
|
-
return self
|
77
|
-
|
78
|
-
def parse(self, b: bytes) -> ta.Generator[JsonStreamParserEvent, None, None]:
|
79
|
-
for s in self._decoder.decode(b, not b):
|
80
|
-
for c in s:
|
81
|
-
for t in self._lex(c):
|
82
|
-
yield from self._parse(t)
|
@@ -1,48 +0,0 @@
|
|
1
|
-
import dataclasses as dc
|
2
|
-
import typing as ta
|
3
|
-
|
4
|
-
from .... import lang
|
5
|
-
|
6
|
-
|
7
|
-
if ta.TYPE_CHECKING:
|
8
|
-
from ....specs import jmespath
|
9
|
-
else:
|
10
|
-
jmespath = lang.proxy_import('....specs.jmespath', __package__)
|
11
|
-
|
12
|
-
|
13
|
-
##
|
14
|
-
|
15
|
-
|
16
|
-
@dc.dataclass(frozen=True, kw_only=True)
|
17
|
-
class ProcessingOptions:
|
18
|
-
jmespath_expr: ta.Any | None = None
|
19
|
-
flat: bool = False
|
20
|
-
|
21
|
-
|
22
|
-
class Processor:
|
23
|
-
def __init__(self, opts: ProcessingOptions) -> None:
|
24
|
-
super().__init__()
|
25
|
-
|
26
|
-
self._opts = opts
|
27
|
-
|
28
|
-
jmespath_expr = opts.jmespath_expr
|
29
|
-
if isinstance(jmespath_expr, str):
|
30
|
-
jmespath_expr = jmespath.compile(jmespath_expr)
|
31
|
-
self._jmespath_expr: ta.Any | None = jmespath_expr
|
32
|
-
|
33
|
-
def process(self, v: ta.Any) -> ta.Iterable[ta.Any]:
|
34
|
-
if self._jmespath_expr is not None:
|
35
|
-
v = self._jmespath_expr.search(v)
|
36
|
-
|
37
|
-
if self._opts.flat:
|
38
|
-
if (
|
39
|
-
not isinstance(v, ta.Iterable) or # noqa
|
40
|
-
isinstance(v, ta.Mapping) or
|
41
|
-
isinstance(v, lang.BUILTIN_SCALAR_ITERABLE_TYPES)
|
42
|
-
):
|
43
|
-
raise TypeError(f'Flat output must be flat collections, got {type(v)}', v)
|
44
|
-
|
45
|
-
yield from v
|
46
|
-
|
47
|
-
else:
|
48
|
-
yield v
|
@@ -1,92 +0,0 @@
|
|
1
|
-
import dataclasses as dc
|
2
|
-
import json
|
3
|
-
import typing as ta
|
4
|
-
|
5
|
-
from .... import lang
|
6
|
-
from .... import term
|
7
|
-
from ..render import JsonRenderer
|
8
|
-
from ..stream.parse import JsonStreamParserEvent
|
9
|
-
from ..stream.render import StreamJsonRenderer
|
10
|
-
|
11
|
-
|
12
|
-
##
|
13
|
-
|
14
|
-
|
15
|
-
@dc.dataclass(frozen=True, kw_only=True)
|
16
|
-
class RenderingOptions:
|
17
|
-
indent: int | str | None = None
|
18
|
-
separators: tuple[str, str] | None = None
|
19
|
-
sort_keys: bool = False
|
20
|
-
raw: bool = False
|
21
|
-
unicode: bool = False
|
22
|
-
color: bool = False
|
23
|
-
|
24
|
-
|
25
|
-
def make_render_kwargs(opts: RenderingOptions) -> ta.Mapping[str, ta.Any]:
|
26
|
-
return dict(
|
27
|
-
indent=opts.indent,
|
28
|
-
separators=opts.separators,
|
29
|
-
sort_keys=opts.sort_keys,
|
30
|
-
ensure_ascii=not opts.unicode,
|
31
|
-
)
|
32
|
-
|
33
|
-
|
34
|
-
class Renderer(lang.Abstract):
|
35
|
-
def __init__(self, opts: RenderingOptions) -> None:
|
36
|
-
super().__init__()
|
37
|
-
self._opts = opts
|
38
|
-
self._kw = make_render_kwargs(opts)
|
39
|
-
|
40
|
-
|
41
|
-
##
|
42
|
-
|
43
|
-
|
44
|
-
def term_color(o: ta.Any, state: JsonRenderer.State) -> tuple[str, str]:
|
45
|
-
if state is JsonRenderer.State.KEY:
|
46
|
-
return term.SGR(term.SGRs.FG.BRIGHT_BLUE), term.SGR(term.SGRs.RESET)
|
47
|
-
elif isinstance(o, str):
|
48
|
-
return term.SGR(term.SGRs.FG.GREEN), term.SGR(term.SGRs.RESET)
|
49
|
-
else:
|
50
|
-
return '', ''
|
51
|
-
|
52
|
-
|
53
|
-
##
|
54
|
-
|
55
|
-
|
56
|
-
class EagerRenderer(Renderer):
|
57
|
-
def render(self, v: ta.Any) -> str:
|
58
|
-
if self._opts.raw:
|
59
|
-
if not isinstance(v, str):
|
60
|
-
raise TypeError(f'Raw output must be strings, got {type(v)}', v)
|
61
|
-
|
62
|
-
return v
|
63
|
-
|
64
|
-
elif self._opts.color:
|
65
|
-
return JsonRenderer.render_str(
|
66
|
-
v,
|
67
|
-
**self._kw,
|
68
|
-
style=term_color,
|
69
|
-
)
|
70
|
-
|
71
|
-
else:
|
72
|
-
return json.dumps(
|
73
|
-
v,
|
74
|
-
**self._kw,
|
75
|
-
)
|
76
|
-
|
77
|
-
|
78
|
-
##
|
79
|
-
|
80
|
-
|
81
|
-
class StreamRenderer(Renderer):
|
82
|
-
def __init__(self, opts: RenderingOptions) -> None:
|
83
|
-
super().__init__(opts)
|
84
|
-
|
85
|
-
self._renderer = StreamJsonRenderer(
|
86
|
-
style=term_color if self._opts.color else None,
|
87
|
-
delimiter='\n',
|
88
|
-
**self._kw,
|
89
|
-
)
|
90
|
-
|
91
|
-
def render(self, e: JsonStreamParserEvent) -> ta.Generator[str, None, None]:
|
92
|
-
return self._renderer.render((e,))
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|