luckylucy.utils.xml 1.85rc1__py2.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.
luckylucy/utils/xml.py ADDED
@@ -0,0 +1,43 @@
1
+ # -*- coding: utf-8 -*-
2
+ # /// script
3
+ # requires-python = ">=2.7"
4
+ # dependencies = []
5
+ #
6
+ # [tool.luckylucy]
7
+ # module = true
8
+ # ///
9
+ from collections import defaultdict
10
+
11
+ __author__ = 'luckydonald'
12
+
13
+
14
+ def etree_to_dict(t):
15
+ """
16
+ Function to modify a xml.etree.ElementTree thingy to be a dict.
17
+ Attributes will be accessible via ["@attribute"],
18
+ and get the text (aka. content) inside via ["#text"]
19
+
20
+ TESTED ONLY FOR PYTHON 3! (but should be working in Python 2...)
21
+ :param t:
22
+ :return:
23
+ """
24
+ # THANKS http://stackoverflow.com/a/10077069
25
+
26
+ d = {t.tag: {} if t.attrib else None}
27
+ children = list(t)
28
+ if children:
29
+ dd = defaultdict(list)
30
+ for dc in map(etree_to_dict, children):
31
+ for k, v in dc.items():
32
+ dd[k].append(v)
33
+ d = {t.tag: {k: v[0] if len(v) == 1 else v for k, v in dd.items()}} # .items() is bad for python 2
34
+ if t.attrib:
35
+ d[t.tag].update(('@' + k, v) for k, v in t.attrib.items()) # .items() is bad for python 2
36
+ if t.text:
37
+ text = t.text.strip()
38
+ if children or t.attrib:
39
+ if text:
40
+ d[t.tag]['#text'] = text
41
+ else:
42
+ d[t.tag] = text
43
+ return d
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.5
2
+ Name: luckylucy.utils.xml
3
+ Version: 1.85.pre1
4
+ Summary: A collection of utilities I use across different projects (luckylucy.utils.xml)
5
+ Project-URL: Homepage, https://github.com/luckydonald/luckylucy.utils
6
+ Project-URL: Changelog, https://github.com/luckydonald/luckylucy.utils/blob/HEAD/CHANGELOG.md
7
+ Author-email: luckylucy <luckylucy.utils._.code@luckydonald.de>
8
+ License-Expression: GPL-2.0-or-later
9
+ Requires-Python: >=2.7
10
+ Description-Content-Type: text/markdown
11
+
12
+ # luckylucy.utils.xml 1.85.pre1
13
+
14
+ A collection of utilities I use across different projects, part of [luckylucy.utils](https://github.com/luckydonald/luckylucy.utils).
15
+
16
+ - [Changes in 1.85.pre1](https://github.com/luckydonald/luckylucy.utils/releases/tag/v1.85.pre1)
17
+ - [Changelog](https://github.com/luckydonald/luckylucy.utils/blob/HEAD/CHANGELOG.md)
@@ -0,0 +1,4 @@
1
+ luckylucy/utils/xml.py,sha256=Y0wPkawNoZPrF0YWqNtpuDT-LsODvKID3Jb0yMfHe-c,1206
2
+ luckylucy_utils_xml-1.85rc1.dist-info/METADATA,sha256=eyg80l6rQ2kCaiA-A2zGAbi2yU7vpLBtMJx148gKn-Y,835
3
+ luckylucy_utils_xml-1.85rc1.dist-info/WHEEL,sha256=K_1GFnQyJknHy845BKcqIEBshHiHkrbA-n3al-vZCiY,105
4
+ luckylucy_utils_xml-1.85rc1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any