omlish 0.0.0.dev206__py3-none-any.whl → 0.0.0.dev208__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/__about__.py CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev206'
2
- __revision__ = 'fbe9fb697323f864d4e3a5eb2a999356f5e34f60'
1
+ __version__ = '0.0.0.dev208'
2
+ __revision__ = '0a5b99ece5c5a7d95c3ba0892f22ea9061ddad24'
3
3
 
4
4
 
5
5
  #
omlish/formats/xml.py CHANGED
@@ -5,6 +5,7 @@ TODO:
5
5
  """
6
6
  import typing as ta
7
7
 
8
+ from .. import cached
8
9
  from .. import dataclasses as dc
9
10
  from .. import lang
10
11
 
@@ -67,17 +68,51 @@ class SimpleElement:
67
68
  attrs: ta.Mapping[str, str] | None = dc.xfield(default=None, repr_fn=dc.truthy_repr)
68
69
  body: ta.Sequence[ta.Union['SimpleElement', str]] | None = dc.xfield(default=None, repr_fn=dc.truthy_repr)
69
70
 
70
- def as_dict(self) -> dict[str, ta.Any]:
71
+ #
72
+
73
+ @cached.property
74
+ def has_children(self) -> bool:
75
+ return any(isinstance(c, SimpleElement) for c in self.body or ())
76
+
77
+ @cached.property
78
+ def children(self) -> ta.Sequence['SimpleElement']:
79
+ return [c for c in self.body or () if isinstance(c, SimpleElement)]
80
+
81
+ @cached.property
82
+ def text(self) -> str:
83
+ return ''.join(c for c in self.body or () if isinstance(c, str))
84
+
85
+ #
86
+
87
+ def se_dict(self) -> dict[str, ta.Any]:
71
88
  dct: dict[str, ta.Any] = {'tag': self.tag}
72
89
  if self.attrs:
73
90
  dct['attrs'] = self.attrs
74
91
  if self.body:
75
92
  dct['body'] = [
76
- c.as_dict() if isinstance(c, SimpleElement) else c
93
+ c.se_dict() if isinstance(c, SimpleElement) else c
77
94
  for c in self.body
78
95
  ]
79
96
  return dct
80
97
 
98
+ #
99
+
100
+ def multidict(self) -> dict[str, list[ta.Any]]:
101
+ dct: dict[str, list[ta.Any]] = {}
102
+
103
+ for ce in self.children:
104
+ try:
105
+ cl = dct[ce.tag]
106
+ except KeyError:
107
+ dct[ce.tag] = cl = []
108
+
109
+ if ce.has_children:
110
+ cl.append(ce.multidict())
111
+ elif ce.body:
112
+ cl.append(ce.text)
113
+
114
+ return dct
115
+
81
116
 
82
117
  def build_simple_element(
83
118
  element: 'ET.Element',
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: omlish
3
- Version: 0.0.0.dev206
3
+ Version: 0.0.0.dev208
4
4
  Summary: omlish
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -1,5 +1,5 @@
1
1
  omlish/.manifests.json,sha256=dyIpveH7Z8OnQp2pTn6NVv7LCDXVrozJWAzbk8PBavg,7950
2
- omlish/__about__.py,sha256=HkupIc8CpzVWpOlDHjAm9pefevlmAr3JF8jUolA3iF4,3409
2
+ omlish/__about__.py,sha256=22uMA2RLBxbw-IZsPLk4nnvlh3wHoCRD06wQw3bBZIQ,3409
3
3
  omlish/__init__.py,sha256=SsyiITTuK0v74XpKV8dqNaCmjOlan1JZKrHQv5rWKPA,253
4
4
  omlish/c3.py,sha256=ubu7lHwss5V4UznbejAI0qXhXahrU01MysuHOZI9C4U,8116
5
5
  omlish/cached.py,sha256=UI-XTFBwA6YXWJJJeBn-WkwBkfzDjLBBaZf4nIJA9y0,510
@@ -228,7 +228,7 @@ omlish/formats/json5.py,sha256=odpZIShlUpv19aACWe58SoMPcv0AHKIa6zSMjlKgaMI,515
228
228
  omlish/formats/pickle.py,sha256=jdp4E9WH9qVPBE3sSqbqDtUo18RbTSIiSpSzJ-IEVZw,529
229
229
  omlish/formats/props.py,sha256=auCv-Jx79KGlWfyG1-Qo0ou-Ex0W_mF3r_lDFdsVkWI,18920
230
230
  omlish/formats/repr.py,sha256=kYrNs4o-ji8nOdp6u_L3aMgBMWN1ZAZJSAWgQQfStSQ,414
231
- omlish/formats/xml.py,sha256=rKXN1RDJV-jliM4fZ2NtmsujB5cAGQBMzRHRHEnH9Ko,2661
231
+ omlish/formats/xml.py,sha256=VJfqHR60dhAtjeG8WXFMozFqesTBSGvv264d67eDFXc,3514
232
232
  omlish/formats/yaml.py,sha256=ffOwGnLA6chdiFyaS7X0TBMGmHG9AoGudzKVWfQ1UOs,7389
233
233
  omlish/formats/ini/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
234
234
  omlish/formats/ini/codec.py,sha256=omuFg0kiDksv8rRlWd_v32ebzEcKlgmiPgGID3bRi2M,631
@@ -609,9 +609,9 @@ omlish/text/indent.py,sha256=YjtJEBYWuk8--b9JU_T6q4yxV85_TR7VEVr5ViRCFwk,1336
609
609
  omlish/text/minja.py,sha256=jZC-fp3Xuhx48ppqsf2Sf1pHbC0t8XBB7UpUUoOk2Qw,5751
610
610
  omlish/text/parts.py,sha256=7vPF1aTZdvLVYJ4EwBZVzRSy8XB3YqPd7JwEnNGGAOo,6495
611
611
  omlish/text/random.py,sha256=jNWpqiaKjKyTdMXC-pWAsSC10AAP-cmRRPVhm59ZWLk,194
612
- omlish-0.0.0.dev206.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
613
- omlish-0.0.0.dev206.dist-info/METADATA,sha256=UGV5-pANwtpbaBPJMYzB7MGk-5ZDkEngcGS3p1Fcnl8,4264
614
- omlish-0.0.0.dev206.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
615
- omlish-0.0.0.dev206.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
616
- omlish-0.0.0.dev206.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
617
- omlish-0.0.0.dev206.dist-info/RECORD,,
612
+ omlish-0.0.0.dev208.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
613
+ omlish-0.0.0.dev208.dist-info/METADATA,sha256=56HyCquMSUilt7VYCVusiCr6AXg2OuCrQwdxK4YXVbc,4264
614
+ omlish-0.0.0.dev208.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
615
+ omlish-0.0.0.dev208.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
616
+ omlish-0.0.0.dev208.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
617
+ omlish-0.0.0.dev208.dist-info/RECORD,,