omlish 0.0.0.dev82__py3-none-any.whl → 0.0.0.dev83__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- omlish/.manifests.json +3 -3
- omlish/__about__.py +2 -2
- omlish/formats/json/cli/__init__.py +0 -0
- omlish/formats/json/{cli.py → cli/cli.py} +23 -51
- omlish/formats/json/cli/formats.py +64 -0
- omlish/formats/xml.py +63 -0
- {omlish-0.0.0.dev82.dist-info → omlish-0.0.0.dev83.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev82.dist-info → omlish-0.0.0.dev83.dist-info}/RECORD +13 -10
- /omlish/formats/json/{__main__.py → cli/__main__.py} +0 -0
- {omlish-0.0.0.dev82.dist-info → omlish-0.0.0.dev83.dist-info}/LICENSE +0 -0
- {omlish-0.0.0.dev82.dist-info → omlish-0.0.0.dev83.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev82.dist-info → omlish-0.0.0.dev83.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev82.dist-info → omlish-0.0.0.dev83.dist-info}/top_level.txt +0 -0
omlish/.manifests.json
CHANGED
@@ -36,14 +36,14 @@
|
|
36
36
|
}
|
37
37
|
},
|
38
38
|
{
|
39
|
-
"module": ".formats.json.__main__",
|
39
|
+
"module": ".formats.json.cli.__main__",
|
40
40
|
"attr": "_CLI_MODULE",
|
41
|
-
"file": "omlish/formats/json/__main__.py",
|
41
|
+
"file": "omlish/formats/json/cli/__main__.py",
|
42
42
|
"line": 1,
|
43
43
|
"value": {
|
44
44
|
"$omdev.cli.types.CliModule": {
|
45
45
|
"cmd_name": "json",
|
46
|
-
"mod_name": "omlish.formats.json.__main__"
|
46
|
+
"mod_name": "omlish.formats.json.cli.__main__"
|
47
47
|
}
|
48
48
|
}
|
49
49
|
},
|
omlish/__about__.py
CHANGED
File without changes
|
@@ -1,13 +1,6 @@
|
|
1
|
-
"""
|
2
|
-
TODO:
|
3
|
-
- xml - [{"att", {"el", {"cdata", ...
|
4
|
-
- csv - dict if headers, array if not
|
5
|
-
"""
|
6
1
|
import argparse
|
7
2
|
import codecs
|
8
3
|
import contextlib
|
9
|
-
import dataclasses as dc
|
10
|
-
import enum
|
11
4
|
import io
|
12
5
|
import json
|
13
6
|
import os
|
@@ -15,33 +8,25 @@ import subprocess
|
|
15
8
|
import sys
|
16
9
|
import typing as ta
|
17
10
|
|
18
|
-
from
|
19
|
-
from
|
20
|
-
from
|
21
|
-
from
|
22
|
-
from
|
23
|
-
from
|
24
|
-
from
|
25
|
-
from
|
11
|
+
from .... import check
|
12
|
+
from .... import lang
|
13
|
+
from .... import term
|
14
|
+
from ..render import JsonRenderer
|
15
|
+
from ..stream.build import JsonObjectBuilder
|
16
|
+
from ..stream.lex import JsonStreamLexer
|
17
|
+
from ..stream.parse import JsonStreamParser
|
18
|
+
from ..stream.render import StreamJsonRenderer
|
19
|
+
from .formats import FORMATS_BY_NAME
|
20
|
+
from .formats import Formats
|
26
21
|
|
27
22
|
|
28
23
|
if ta.TYPE_CHECKING:
|
29
|
-
import
|
30
|
-
import tomllib
|
31
|
-
|
32
|
-
import yaml
|
33
|
-
|
34
|
-
from .. import dotenv
|
35
|
-
from .. import props
|
36
|
-
|
24
|
+
from ....specs import jmespath
|
37
25
|
else:
|
38
|
-
|
39
|
-
tomllib = lang.proxy_import('tomllib')
|
26
|
+
jmespath = lang.proxy_import('....specs.jmespath', __package__)
|
40
27
|
|
41
|
-
yaml = lang.proxy_import('yaml')
|
42
28
|
|
43
|
-
|
44
|
-
props = lang.proxy_import('..props', __package__)
|
29
|
+
##
|
45
30
|
|
46
31
|
|
47
32
|
def term_color(o: ta.Any, state: JsonRenderer.State) -> tuple[str, str]:
|
@@ -53,29 +38,6 @@ def term_color(o: ta.Any, state: JsonRenderer.State) -> tuple[str, str]:
|
|
53
38
|
return '', ''
|
54
39
|
|
55
40
|
|
56
|
-
@dc.dataclass(frozen=True)
|
57
|
-
class Format:
|
58
|
-
names: ta.Sequence[str]
|
59
|
-
load: ta.Callable[[ta.TextIO], ta.Any]
|
60
|
-
|
61
|
-
|
62
|
-
class Formats(enum.Enum):
|
63
|
-
JSON = Format(['json'], json.load)
|
64
|
-
YAML = Format(['yaml', 'yml'], lambda f: yaml.safe_load(f))
|
65
|
-
TOML = Format(['toml'], lambda f: tomllib.loads(f.read()))
|
66
|
-
ENV = Format(['env', 'dotenv'], lambda f: dotenv.dotenv_values(stream=f))
|
67
|
-
PROPS = Format(['properties', 'props'], lambda f: dict(props.Properties().load(f.read())))
|
68
|
-
PY = Format(['py', 'python', 'repr'], lambda f: ast.literal_eval(f.read()))
|
69
|
-
|
70
|
-
|
71
|
-
FORMATS_BY_NAME: ta.Mapping[str, Format] = {
|
72
|
-
n: f
|
73
|
-
for e in Formats
|
74
|
-
for f in [e.value]
|
75
|
-
for n in f.names
|
76
|
-
}
|
77
|
-
|
78
|
-
|
79
41
|
def _main() -> None:
|
80
42
|
parser = argparse.ArgumentParser()
|
81
43
|
|
@@ -87,6 +49,8 @@ def _main() -> None:
|
|
87
49
|
|
88
50
|
parser.add_argument('-f', '--format')
|
89
51
|
|
52
|
+
parser.add_argument('-x', '--jmespath-expr')
|
53
|
+
|
90
54
|
parser.add_argument('-z', '--compact', action='store_true')
|
91
55
|
parser.add_argument('-p', '--pretty', action='store_true')
|
92
56
|
parser.add_argument('-i', '--indent')
|
@@ -119,7 +83,15 @@ def _main() -> None:
|
|
119
83
|
sort_keys=args.sort_keys,
|
120
84
|
)
|
121
85
|
|
86
|
+
if args.jmespath_expr is not None:
|
87
|
+
jp_expr = jmespath.compile(args.jmespath_expr)
|
88
|
+
else:
|
89
|
+
jp_expr = None
|
90
|
+
|
122
91
|
def render_one(v: ta.Any) -> str:
|
92
|
+
if jp_expr is not None:
|
93
|
+
v = jp_expr.search(v)
|
94
|
+
|
123
95
|
if args.color:
|
124
96
|
return JsonRenderer.render_str(
|
125
97
|
v,
|
@@ -0,0 +1,64 @@
|
|
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
|
+
YAML = Format(['yaml', 'yml'], lambda f: yaml.safe_load(f))
|
48
|
+
TOML = Format(['toml'], lambda f: tomllib.loads(f.read()))
|
49
|
+
ENV = Format(['env', 'dotenv'], lambda f: dotenv.dotenv_values(stream=f))
|
50
|
+
PROPS = Format(['properties', 'props'], lambda f: dict(props.Properties().load(f.read())))
|
51
|
+
PY = Format(['py', 'python', 'repr'], lambda f: ast.literal_eval(f.read()))
|
52
|
+
XML = Format(['xml'], lambda f: xml.build_simple_element(xml.parse_tree(f.read()).getroot()).as_dict())
|
53
|
+
CSV = Format(['csv'], lambda f: list(csv.DictReader(f)))
|
54
|
+
TSV = Format(['tsv'], lambda f: list(csv.DictReader(f, delimiter='\t')))
|
55
|
+
FLAT_CSV = Format(['fcsv'], lambda f: list(csv.reader(f)))
|
56
|
+
FLAT_TSV = Format(['ftsv'], lambda f: list(csv.reader(f, delimiter='\t')))
|
57
|
+
|
58
|
+
|
59
|
+
FORMATS_BY_NAME: ta.Mapping[str, Format] = {
|
60
|
+
n: f
|
61
|
+
for e in Formats
|
62
|
+
for f in [e.value]
|
63
|
+
for n in f.names
|
64
|
+
}
|
omlish/formats/xml.py
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
"""
|
2
|
+
TODO:
|
3
|
+
- lxml abstraction
|
4
|
+
- stuff from ommlx/wiki
|
5
|
+
"""
|
6
|
+
import typing as ta
|
7
|
+
|
8
|
+
from .. import dataclasses as dc
|
9
|
+
from .. import lang
|
10
|
+
|
11
|
+
|
12
|
+
if ta.TYPE_CHECKING:
|
13
|
+
import xml.etree.ElementTree as ET
|
14
|
+
else:
|
15
|
+
ET = lang.proxy_import('xml.etree.ElementTree')
|
16
|
+
|
17
|
+
|
18
|
+
##
|
19
|
+
|
20
|
+
|
21
|
+
@dc.dataclass(frozen=True)
|
22
|
+
class SimpleElement:
|
23
|
+
tag: str
|
24
|
+
attributes: ta.Mapping[str, str] | None = dc.xfield(default=None, repr_fn=dc.truthy_repr)
|
25
|
+
body: ta.Sequence[ta.Union['SimpleElement', str]] | None = dc.xfield(default=None, repr_fn=dc.truthy_repr)
|
26
|
+
|
27
|
+
def as_dict(self) -> dict[str, ta.Any]:
|
28
|
+
dct: dict[str, ta.Any] = {'tag': self.tag}
|
29
|
+
if self.attributes:
|
30
|
+
dct['attributes'] = self.attributes
|
31
|
+
if self.body:
|
32
|
+
dct['body'] = [
|
33
|
+
c.as_dict() if isinstance(c, SimpleElement) else c
|
34
|
+
for c in self.body
|
35
|
+
]
|
36
|
+
return dct
|
37
|
+
|
38
|
+
|
39
|
+
def build_simple_element(element: 'ET.Element') -> SimpleElement:
|
40
|
+
atts = {}
|
41
|
+
for name, value in element.attrib.items():
|
42
|
+
atts[name] = value # noqa
|
43
|
+
|
44
|
+
body: list[SimpleElement | str] = []
|
45
|
+
|
46
|
+
if element.text and (s := element.text.strip()):
|
47
|
+
body.append(s)
|
48
|
+
|
49
|
+
for child in element:
|
50
|
+
body.append(build_simple_element(child))
|
51
|
+
|
52
|
+
if child.tail and (s := child.tail.strip()):
|
53
|
+
body.append(s)
|
54
|
+
|
55
|
+
return SimpleElement(
|
56
|
+
element.tag,
|
57
|
+
atts,
|
58
|
+
body,
|
59
|
+
)
|
60
|
+
|
61
|
+
|
62
|
+
def parse_tree(s: str) -> 'ET.ElementTree':
|
63
|
+
return ET.ElementTree(ET.fromstring(s.strip())) # noqa
|
@@ -1,5 +1,5 @@
|
|
1
|
-
omlish/.manifests.json,sha256=
|
2
|
-
omlish/__about__.py,sha256=
|
1
|
+
omlish/.manifests.json,sha256=hTFp9tvE72BxKloIq1s1SS0LRQlIsvMtO69Sbc47rKg,1704
|
2
|
+
omlish/__about__.py,sha256=ekzbyJ-nihCL3SJ4lJ_uq-a-V1a5SLP_kMNo0ugzCOw,3370
|
3
3
|
omlish/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
omlish/argparse.py,sha256=Dc73G8lyoQBLvXhMYUbzQUh4SJu_OTvKUXjSUxq_ang,7499
|
5
5
|
omlish/c3.py,sha256=4vogWgwPb8TbNS2KkZxpoWbwjj7MuHG2lQG-hdtkvjI,8062
|
@@ -181,10 +181,9 @@ omlish/docker/manifests.py,sha256=LR4FpOGNUT3bZQ-gTjB6r_-1C3YiG30QvevZjrsVUQM,70
|
|
181
181
|
omlish/formats/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
182
182
|
omlish/formats/dotenv.py,sha256=UjZl3gac-0U24sDjCCGMcCqO1UCWG2Zs8PZ4JdAg2YE,17348
|
183
183
|
omlish/formats/props.py,sha256=JwFJbKblqzqnzXf7YKFzQSDfcAXzkKsfoYvad6FPy98,18945
|
184
|
+
omlish/formats/xml.py,sha256=FYNUliVZproz4cA3nOTqj0ShfPMQ7rEIeMEP4umDNho,1511
|
184
185
|
omlish/formats/yaml.py,sha256=wTW8ECG9jyA7qIFUqKZUro4KAKpN4IvcW_qhlrKveXM,6836
|
185
186
|
omlish/formats/json/__init__.py,sha256=xqW2APLGvCTO9dVTOlroR_AdrA5bCkdmUnbTkYHhJ7U,379
|
186
|
-
omlish/formats/json/__main__.py,sha256=1wxxKZVkj_u7HCcewwMIbGuZj_Wph95yrUbm474Op9M,188
|
187
|
-
omlish/formats/json/cli.py,sha256=HimX6N-VWnBh6MhyxjXKHw_VNn7tUkelRflpjWv3X3I,6210
|
188
187
|
omlish/formats/json/consts.py,sha256=u-x-qXqZvK0tWk3l3TrCTjk4mSjKmZ_ATdmd1hwHNAY,263
|
189
188
|
omlish/formats/json/encoding.py,sha256=O4iIWle7W_-RwpOvJNlqOfkbnDyiQHexV5Za4hlrFzw,497
|
190
189
|
omlish/formats/json/json.py,sha256=Mdqv2vdMi7gp96eV0BIYH5UdWpjWfsh-tSMZeywG-08,331
|
@@ -196,6 +195,10 @@ omlish/formats/json/backends/jiter.py,sha256=8qv_XWGpcupPtVm6Z_egHio_iY1Kk8eqkvX
|
|
196
195
|
omlish/formats/json/backends/orjson.py,sha256=wR8pMGFtkhZGHcNVk7vNYUnv8lUapdK89p6QpETIs9w,3778
|
197
196
|
omlish/formats/json/backends/std.py,sha256=PM00Kh9ZR2XzollHMEvdo35Eml1N-zFfRW-LOCV5ftM,3085
|
198
197
|
omlish/formats/json/backends/ujson.py,sha256=BNJCU4kluGHdqTUKLJEuHhE2m2TmqR7HEN289S0Eokg,2278
|
198
|
+
omlish/formats/json/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
199
|
+
omlish/formats/json/cli/__main__.py,sha256=1wxxKZVkj_u7HCcewwMIbGuZj_Wph95yrUbm474Op9M,188
|
200
|
+
omlish/formats/json/cli/cli.py,sha256=GkdNokklRuDWiXAIai1wijSBFVJlpdlNLTQ3Lyucos0,5493
|
201
|
+
omlish/formats/json/cli/formats.py,sha256=tqEZKby4HeafGcaUs-m8B-2ZV12dRo40rzL-V99cp00,1714
|
199
202
|
omlish/formats/json/stream/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
200
203
|
omlish/formats/json/stream/build.py,sha256=2Bikvvcaqad85J3kvmD6I5Dqp8NstyP6Gb2COeN-lxs,2780
|
201
204
|
omlish/formats/json/stream/lex.py,sha256=hMnsZld72XE7GCWdjbUANRxrruuBSSQeCm8wypMiMv0,6172
|
@@ -450,9 +453,9 @@ omlish/text/delimit.py,sha256=ubPXcXQmtbOVrUsNh5gH1mDq5H-n1y2R4cPL5_DQf68,4928
|
|
450
453
|
omlish/text/glyphsplit.py,sha256=Ug-dPRO7x-OrNNr8g1y6DotSZ2KH0S-VcOmUobwa4B0,3296
|
451
454
|
omlish/text/indent.py,sha256=6Jj6TFY9unaPa4xPzrnZemJ-fHsV53IamP93XGjSUHs,1274
|
452
455
|
omlish/text/parts.py,sha256=7vPF1aTZdvLVYJ4EwBZVzRSy8XB3YqPd7JwEnNGGAOo,6495
|
453
|
-
omlish-0.0.0.
|
454
|
-
omlish-0.0.0.
|
455
|
-
omlish-0.0.0.
|
456
|
-
omlish-0.0.0.
|
457
|
-
omlish-0.0.0.
|
458
|
-
omlish-0.0.0.
|
456
|
+
omlish-0.0.0.dev83.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
457
|
+
omlish-0.0.0.dev83.dist-info/METADATA,sha256=3V-8-n6HgqRRGC2ot30034BVPmmVkrX9-QfCfx7sLSQ,4047
|
458
|
+
omlish-0.0.0.dev83.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
459
|
+
omlish-0.0.0.dev83.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
460
|
+
omlish-0.0.0.dev83.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
461
|
+
omlish-0.0.0.dev83.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|