untangle 1.2.1__tar.gz → 1.3.1__tar.gz
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.
- untangle-1.3.1/PKG-INFO +97 -0
- untangle-1.3.1/README.md +80 -0
- untangle-1.3.1/pyproject.toml +32 -0
- untangle-1.3.1/pyproject.toml.orig +35 -0
- untangle-1.2.1/untangle.py → untangle-1.3.1/src/untangle/__init__.py +40 -52
- untangle-1.2.1/LICENSE +0 -23
- untangle-1.2.1/PKG-INFO +0 -82
- untangle-1.2.1/README.md +0 -64
- untangle-1.2.1/pyproject.toml +0 -23
- untangle-1.2.1/setup.py +0 -25
untangle-1.3.1/PKG-INFO
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: untangle
|
|
3
|
+
Version: 1.3.1
|
|
4
|
+
Summary: Converts XML to Python objects
|
|
5
|
+
Author: Christian Stefanescu
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
14
|
+
Requires-Dist: defusedxml==0.7.1
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# untangle
|
|
19
|
+
|
|
20
|
+
[](https://github.com/stchris/untangle/actions)
|
|
21
|
+
[](https://pypi.python.org/pypi/untangle)
|
|
22
|
+
|
|
23
|
+
[Documentation](http://readthedocs.org/docs/untangle/en/latest/)
|
|
24
|
+
|
|
25
|
+
* Converts XML to a Python object.
|
|
26
|
+
* Siblings with similar names are grouped into a list.
|
|
27
|
+
* Children can be accessed with `parent.child`, attributes with `element['attribute']`.
|
|
28
|
+
* You can call the `parse()` method with a filename, an URL or an XML string.
|
|
29
|
+
* Substitutes `-`, `.` and `:` with `_` `<foobar><foo-bar/></foobar>` can be accessed with `foobar.foo_bar`, `<foo.bar.baz/>` can be accessed with `foo_bar_baz` and `<foo:bar><foo:baz/></foo:bar>` can be accessed with `foo_bar.foo_baz`
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
With pip:
|
|
34
|
+
```bash
|
|
35
|
+
pip install untangle
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
(See and run <a href="https://github.com/stchris/untangle/blob/main/examples.py">examples.py</a> or this blog post: [Read XML painlessly](http://pythonadventures.wordpress.com/2011/10/30/read-xml-painlessly/) for more info)
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import untangle
|
|
44
|
+
|
|
45
|
+
obj = untangle.parse(resource)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`resource` can be:
|
|
49
|
+
|
|
50
|
+
* a URL
|
|
51
|
+
* a filename (a string or an `os.PathLike` object such as `pathlib.Path`)
|
|
52
|
+
* an XML string
|
|
53
|
+
|
|
54
|
+
Running the above code and passing this XML:
|
|
55
|
+
|
|
56
|
+
```xml
|
|
57
|
+
<?xml version="1.0"?>
|
|
58
|
+
<root>
|
|
59
|
+
<child name="child1"/>
|
|
60
|
+
</root>
|
|
61
|
+
```
|
|
62
|
+
allows it to be navigated from the `untangle`d object like this:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
obj.root.child["name"] # u'child1'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
`untangle` uses [uv](https://docs.astral.sh/uv/) for builds and virtualenv management:
|
|
71
|
+
```
|
|
72
|
+
$ uv sync
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Run tests:
|
|
76
|
+
```
|
|
77
|
+
$ uv run pytest
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Run linter:
|
|
81
|
+
```
|
|
82
|
+
$ uv run ruff check .
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Run formatter checks:
|
|
86
|
+
```
|
|
87
|
+
$ uv run ruff format --check
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Run type hint checks:
|
|
91
|
+
```
|
|
92
|
+
$ uv run ty check .
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Changelog
|
|
96
|
+
|
|
97
|
+
see CHANGELOG.md
|
untangle-1.3.1/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# untangle
|
|
2
|
+
|
|
3
|
+
[](https://github.com/stchris/untangle/actions)
|
|
4
|
+
[](https://pypi.python.org/pypi/untangle)
|
|
5
|
+
|
|
6
|
+
[Documentation](http://readthedocs.org/docs/untangle/en/latest/)
|
|
7
|
+
|
|
8
|
+
* Converts XML to a Python object.
|
|
9
|
+
* Siblings with similar names are grouped into a list.
|
|
10
|
+
* Children can be accessed with `parent.child`, attributes with `element['attribute']`.
|
|
11
|
+
* You can call the `parse()` method with a filename, an URL or an XML string.
|
|
12
|
+
* Substitutes `-`, `.` and `:` with `_` `<foobar><foo-bar/></foobar>` can be accessed with `foobar.foo_bar`, `<foo.bar.baz/>` can be accessed with `foo_bar_baz` and `<foo:bar><foo:baz/></foo:bar>` can be accessed with `foo_bar.foo_baz`
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
With pip:
|
|
17
|
+
```bash
|
|
18
|
+
pip install untangle
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
(See and run <a href="https://github.com/stchris/untangle/blob/main/examples.py">examples.py</a> or this blog post: [Read XML painlessly](http://pythonadventures.wordpress.com/2011/10/30/read-xml-painlessly/) for more info)
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import untangle
|
|
27
|
+
|
|
28
|
+
obj = untangle.parse(resource)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`resource` can be:
|
|
32
|
+
|
|
33
|
+
* a URL
|
|
34
|
+
* a filename (a string or an `os.PathLike` object such as `pathlib.Path`)
|
|
35
|
+
* an XML string
|
|
36
|
+
|
|
37
|
+
Running the above code and passing this XML:
|
|
38
|
+
|
|
39
|
+
```xml
|
|
40
|
+
<?xml version="1.0"?>
|
|
41
|
+
<root>
|
|
42
|
+
<child name="child1"/>
|
|
43
|
+
</root>
|
|
44
|
+
```
|
|
45
|
+
allows it to be navigated from the `untangle`d object like this:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
obj.root.child["name"] # u'child1'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Development
|
|
52
|
+
|
|
53
|
+
`untangle` uses [uv](https://docs.astral.sh/uv/) for builds and virtualenv management:
|
|
54
|
+
```
|
|
55
|
+
$ uv sync
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Run tests:
|
|
59
|
+
```
|
|
60
|
+
$ uv run pytest
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Run linter:
|
|
64
|
+
```
|
|
65
|
+
$ uv run ruff check .
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Run formatter checks:
|
|
69
|
+
```
|
|
70
|
+
$ uv run ruff format --check
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Run type hint checks:
|
|
74
|
+
```
|
|
75
|
+
$ uv run ty check .
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Changelog
|
|
79
|
+
|
|
80
|
+
see CHANGELOG.md
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "untangle"
|
|
3
|
+
version = "1.3.1"
|
|
4
|
+
description = "Converts XML to Python objects"
|
|
5
|
+
license = "MIT"
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
requires-python = ">=3.11"
|
|
8
|
+
classifiers = [
|
|
9
|
+
"Programming Language :: Python :: 3",
|
|
10
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
11
|
+
"Programming Language :: Python :: 3.11",
|
|
12
|
+
"Programming Language :: Python :: 3.12",
|
|
13
|
+
"Programming Language :: Python :: 3.13",
|
|
14
|
+
"Programming Language :: Python :: 3.14",
|
|
15
|
+
"Programming Language :: Python :: 3.15",
|
|
16
|
+
]
|
|
17
|
+
dependencies = ["defusedxml==0.7.1"]
|
|
18
|
+
|
|
19
|
+
[[project.authors]]
|
|
20
|
+
name = "Christian Stefanescu"
|
|
21
|
+
|
|
22
|
+
[dependency-groups]
|
|
23
|
+
dev = [
|
|
24
|
+
"pytest>=9.1.1",
|
|
25
|
+
"ruff>=0.16.8",
|
|
26
|
+
"ty>=0.0.83",
|
|
27
|
+
]
|
|
28
|
+
docs = ["sphinx>=8.1"]
|
|
29
|
+
|
|
30
|
+
[build-system]
|
|
31
|
+
requires = ["uv_build>=0.12.17,<0.14.0"]
|
|
32
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
authors = [{ name = "Christian Stefanescu" }]
|
|
3
|
+
name = "untangle"
|
|
4
|
+
version = "1.3.1"
|
|
5
|
+
description = "Converts XML to Python objects"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
requires-python = ">=3.11"
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Programming Language :: Python :: 3",
|
|
11
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
12
|
+
"Programming Language :: Python :: 3.11",
|
|
13
|
+
"Programming Language :: Python :: 3.12",
|
|
14
|
+
"Programming Language :: Python :: 3.13",
|
|
15
|
+
"Programming Language :: Python :: 3.14",
|
|
16
|
+
"Programming Language :: Python :: 3.15",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
dependencies = ["defusedxml==0.7.1"]
|
|
20
|
+
|
|
21
|
+
[dependency-groups]
|
|
22
|
+
dev = [
|
|
23
|
+
"pytest>=9.1.1",
|
|
24
|
+
"ruff>=0.16.8",
|
|
25
|
+
"ty>=0.0.83",
|
|
26
|
+
]
|
|
27
|
+
# uv forks the lock per interpreter: older Sphinx on 3.11, newer on 3.12+.
|
|
28
|
+
docs = [
|
|
29
|
+
"sphinx>=8.1",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[build-system]
|
|
33
|
+
requires = ["uv_build>=0.12.17,<0.14.0"]
|
|
34
|
+
build-backend = "uv_build"
|
|
35
|
+
|
|
@@ -1,44 +1,35 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
|
|
3
1
|
"""
|
|
4
|
-
|
|
2
|
+
untangle
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
Converts xml to python objects.
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
The only method you need to call is parse()
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
Partially inspired by xml2obj
|
|
9
|
+
(http://code.activestate.com/recipes/149368-xml2obj/)
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
Author: Christian Stefanescu (http://0chris.com)
|
|
12
|
+
License: MIT License - http://www.opensource.org/licenses/mit-license.php
|
|
15
13
|
"""
|
|
16
|
-
import os
|
|
17
|
-
import keyword
|
|
18
|
-
from defusedxml.sax import make_parser
|
|
19
|
-
from xml.sax import handler
|
|
20
|
-
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
import keyword
|
|
16
|
+
import os
|
|
17
|
+
import xml.sax
|
|
18
|
+
import xml.sax.handler
|
|
19
|
+
import xml.sax.xmlreader
|
|
20
|
+
from io import StringIO
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
return isinstance(x, StringTypes)
|
|
22
|
+
from defusedxml.sax import make_parser
|
|
31
23
|
|
|
32
|
-
except ImportError:
|
|
33
24
|
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
def is_string(x):
|
|
26
|
+
return isinstance(x, str)
|
|
36
27
|
|
|
37
28
|
|
|
38
|
-
__version__ = "1.
|
|
29
|
+
__version__ = "1.3.0"
|
|
39
30
|
|
|
40
31
|
|
|
41
|
-
class Element
|
|
32
|
+
class Element:
|
|
42
33
|
"""
|
|
43
34
|
Representation of an XML element.
|
|
44
35
|
"""
|
|
@@ -90,7 +81,7 @@ class Element(object):
|
|
|
90
81
|
self.__dict__[key] = matching_children
|
|
91
82
|
return matching_children
|
|
92
83
|
else:
|
|
93
|
-
raise AttributeError("'
|
|
84
|
+
raise AttributeError(f"'{self._name}' has no attribute '{key}'")
|
|
94
85
|
|
|
95
86
|
def __hasattribute__(self, name):
|
|
96
87
|
if name in self.__dict__:
|
|
@@ -101,19 +92,10 @@ class Element(object):
|
|
|
101
92
|
yield self
|
|
102
93
|
|
|
103
94
|
def __str__(self):
|
|
104
|
-
return "Element
|
|
105
|
-
self._name,
|
|
106
|
-
self._attributes,
|
|
107
|
-
self.children,
|
|
108
|
-
self.cdata,
|
|
109
|
-
)
|
|
95
|
+
return f"Element <{self._name}> with attributes {self._attributes}, children {self.children} and cdata {self.cdata}"
|
|
110
96
|
|
|
111
97
|
def __repr__(self):
|
|
112
|
-
return "Element(name =
|
|
113
|
-
self._name,
|
|
114
|
-
self._attributes,
|
|
115
|
-
self.cdata,
|
|
116
|
-
)
|
|
98
|
+
return f"Element(name = {self._name}, attributes = {self._attributes}, cdata = {self.cdata})"
|
|
117
99
|
|
|
118
100
|
def __bool__(self):
|
|
119
101
|
return self.is_root or self._name is not None
|
|
@@ -134,7 +116,7 @@ class Element(object):
|
|
|
134
116
|
return key in dir(self)
|
|
135
117
|
|
|
136
118
|
|
|
137
|
-
class Handler(handler.ContentHandler):
|
|
119
|
+
class Handler(xml.sax.handler.ContentHandler):
|
|
138
120
|
"""
|
|
139
121
|
SAX handler which creates the Python object structure out of ``Element``s
|
|
140
122
|
"""
|
|
@@ -144,7 +126,7 @@ class Handler(handler.ContentHandler):
|
|
|
144
126
|
self.root.is_root = True
|
|
145
127
|
self.elements = []
|
|
146
128
|
|
|
147
|
-
def startElement(self, name,
|
|
129
|
+
def startElement(self, name: str, attrs: xml.sax.xmlreader.AttributesImpl) -> None:
|
|
148
130
|
name = name.replace("-", "_")
|
|
149
131
|
name = name.replace(".", "_")
|
|
150
132
|
name = name.replace(":", "_")
|
|
@@ -153,10 +135,10 @@ class Handler(handler.ContentHandler):
|
|
|
153
135
|
if keyword.iskeyword(name):
|
|
154
136
|
name += "_"
|
|
155
137
|
|
|
156
|
-
|
|
157
|
-
for k, v in
|
|
158
|
-
|
|
159
|
-
element = Element(name,
|
|
138
|
+
attrs_dict = {}
|
|
139
|
+
for k, v in attrs.items():
|
|
140
|
+
attrs_dict[k] = v
|
|
141
|
+
element = Element(name, attrs_dict)
|
|
160
142
|
if len(self.elements) > 0:
|
|
161
143
|
self.elements[-1].add_child(element)
|
|
162
144
|
else:
|
|
@@ -166,15 +148,16 @@ class Handler(handler.ContentHandler):
|
|
|
166
148
|
def endElement(self, name):
|
|
167
149
|
self.elements.pop()
|
|
168
150
|
|
|
169
|
-
def characters(self,
|
|
170
|
-
self.elements
|
|
151
|
+
def characters(self, content: str) -> None:
|
|
152
|
+
if self.elements:
|
|
153
|
+
self.elements[-1].add_cdata(content)
|
|
171
154
|
|
|
172
155
|
|
|
173
156
|
def parse(filename, **parser_features):
|
|
174
157
|
"""
|
|
175
158
|
Interprets the given string as a filename, URL or XML data string,
|
|
176
159
|
parses it and returns a Python object which represents the given
|
|
177
|
-
document.
|
|
160
|
+
document. Path-like objects are read as filesystem paths.
|
|
178
161
|
|
|
179
162
|
Extra arguments to this function are treated as feature values that are
|
|
180
163
|
passed to ``parser.setFeature()``. For example, ``feature_external_ges=False``
|
|
@@ -183,6 +166,8 @@ def parse(filename, **parser_features):
|
|
|
183
166
|
|
|
184
167
|
Raises ``ValueError`` if the first argument is None / empty string.
|
|
185
168
|
|
|
169
|
+
Raises ``FileNotFoundError`` if a path-like argument does not exist.
|
|
170
|
+
|
|
186
171
|
Raises ``AttributeError`` if a requested xml.sax feature is not found in
|
|
187
172
|
``xml.sax.handler``.
|
|
188
173
|
|
|
@@ -198,10 +183,13 @@ def parse(filename, **parser_features):
|
|
|
198
183
|
raise ValueError("parse() takes a filename, URL or XML string")
|
|
199
184
|
parser = make_parser()
|
|
200
185
|
for feature, value in parser_features.items():
|
|
201
|
-
parser.setFeature(getattr(handler, feature), value)
|
|
186
|
+
parser.setFeature(getattr(xml.sax.handler, feature), value)
|
|
202
187
|
sax_handler = Handler()
|
|
203
188
|
parser.setContentHandler(sax_handler)
|
|
204
|
-
if
|
|
189
|
+
if isinstance(filename, os.PathLike):
|
|
190
|
+
with open(filename, "rb") as source:
|
|
191
|
+
parser.parse(source)
|
|
192
|
+
elif is_string(filename) and (os.path.exists(filename) or is_url(filename)):
|
|
205
193
|
parser.parse(filename)
|
|
206
194
|
else:
|
|
207
195
|
if hasattr(filename, "read"):
|
|
@@ -217,8 +205,8 @@ def is_url(string):
|
|
|
217
205
|
Checks if the given string starts with 'http(s)'.
|
|
218
206
|
"""
|
|
219
207
|
try:
|
|
220
|
-
return string.startswith("http://"
|
|
221
|
-
except AttributeError:
|
|
208
|
+
return string.startswith(("http://", "https://"))
|
|
209
|
+
except (AttributeError, TypeError):
|
|
222
210
|
return False
|
|
223
211
|
|
|
224
212
|
|
untangle-1.2.1/LICENSE
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2011
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person
|
|
4
|
-
obtaining a copy of this software and associated documentation
|
|
5
|
-
files (the "Software"), to deal in the Software without
|
|
6
|
-
restriction, including without limitation the rights to use,
|
|
7
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
copies of the Software, and to permit persons to whom the
|
|
9
|
-
Software is furnished to do so, subject to the following
|
|
10
|
-
conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be
|
|
13
|
-
included in all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
|
untangle-1.2.1/PKG-INFO
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: untangle
|
|
3
|
-
Version: 1.2.1
|
|
4
|
-
Summary: Converts XML to Python objects
|
|
5
|
-
License: MIT
|
|
6
|
-
Author: Christian Stefanescu
|
|
7
|
-
Author-email: hello@stchris.net
|
|
8
|
-
Requires-Python: >=3.7,<4.0
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
-
Requires-Dist: defusedxml (>=0.7.1,<0.8.0)
|
|
16
|
-
Description-Content-Type: text/markdown
|
|
17
|
-
|
|
18
|
-
untangle
|
|
19
|
-
========
|
|
20
|
-
|
|
21
|
-
[](https://github.com/stchris/untangle/actions)
|
|
22
|
-
[](https://pypi.python.org/pypi/untangle)
|
|
23
|
-
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
|
|
24
|
-
|
|
25
|
-
[Documentation](http://readthedocs.org/docs/untangle/en/latest/)
|
|
26
|
-
|
|
27
|
-
* Converts XML to a Python object.
|
|
28
|
-
* Siblings with similar names are grouped into a list.
|
|
29
|
-
* Children can be accessed with ``parent.child``, attributes with ``element['attribute']``.
|
|
30
|
-
* You can call the ``parse()`` method with a filename, an URL or an XML string.
|
|
31
|
-
* Substitutes ``-``, ``.`` and ``:`` with ``_`` ``<foobar><foo-bar/></foobar>`` can be accessed with ``foobar.foo_bar``, ``<foo.bar.baz/>`` can be accessed with ``foo_bar_baz`` and ``<foo:bar><foo:baz/></foo:bar>`` can be accessed with ``foo_bar.foo_baz``
|
|
32
|
-
* Works with Python 3.7 - 3.10
|
|
33
|
-
|
|
34
|
-
Installation
|
|
35
|
-
------------
|
|
36
|
-
|
|
37
|
-
With pip:
|
|
38
|
-
```
|
|
39
|
-
pip install untangle
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
With conda:
|
|
43
|
-
```
|
|
44
|
-
conda install -c conda-forge untangle
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Conda feedstock maintained by @htenkanen. Issues and questions about conda-forge packaging / installation can be done [here](https://github.com/conda-forge/untangle-feedstock/issues).
|
|
48
|
-
|
|
49
|
-
Usage
|
|
50
|
-
-----
|
|
51
|
-
(See and run <a href="https://github.com/stchris/untangle/blob/main/examples.py">examples.py</a> or this blog post: [Read XML painlessly](http://pythonadventures.wordpress.com/2011/10/30/read-xml-painlessly/) for more info)
|
|
52
|
-
|
|
53
|
-
```python
|
|
54
|
-
import untangle
|
|
55
|
-
obj = untangle.parse(resource)
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
``resource`` can be:
|
|
59
|
-
|
|
60
|
-
* a URL
|
|
61
|
-
* a filename
|
|
62
|
-
* an XML string
|
|
63
|
-
|
|
64
|
-
Running the above code and passing this XML:
|
|
65
|
-
|
|
66
|
-
```xml
|
|
67
|
-
<?xml version="1.0"?>
|
|
68
|
-
<root>
|
|
69
|
-
<child name="child1"/>
|
|
70
|
-
</root>
|
|
71
|
-
```
|
|
72
|
-
allows it to be navigated from the ``untangle``d object like this:
|
|
73
|
-
|
|
74
|
-
```python
|
|
75
|
-
obj.root.child['name'] # u'child1'
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
Changelog
|
|
79
|
-
---------
|
|
80
|
-
|
|
81
|
-
see CHANGELOG.md
|
|
82
|
-
|
untangle-1.2.1/README.md
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
untangle
|
|
2
|
-
========
|
|
3
|
-
|
|
4
|
-
[](https://github.com/stchris/untangle/actions)
|
|
5
|
-
[](https://pypi.python.org/pypi/untangle)
|
|
6
|
-
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
|
|
7
|
-
|
|
8
|
-
[Documentation](http://readthedocs.org/docs/untangle/en/latest/)
|
|
9
|
-
|
|
10
|
-
* Converts XML to a Python object.
|
|
11
|
-
* Siblings with similar names are grouped into a list.
|
|
12
|
-
* Children can be accessed with ``parent.child``, attributes with ``element['attribute']``.
|
|
13
|
-
* You can call the ``parse()`` method with a filename, an URL or an XML string.
|
|
14
|
-
* Substitutes ``-``, ``.`` and ``:`` with ``_`` ``<foobar><foo-bar/></foobar>`` can be accessed with ``foobar.foo_bar``, ``<foo.bar.baz/>`` can be accessed with ``foo_bar_baz`` and ``<foo:bar><foo:baz/></foo:bar>`` can be accessed with ``foo_bar.foo_baz``
|
|
15
|
-
* Works with Python 3.7 - 3.10
|
|
16
|
-
|
|
17
|
-
Installation
|
|
18
|
-
------------
|
|
19
|
-
|
|
20
|
-
With pip:
|
|
21
|
-
```
|
|
22
|
-
pip install untangle
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
With conda:
|
|
26
|
-
```
|
|
27
|
-
conda install -c conda-forge untangle
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Conda feedstock maintained by @htenkanen. Issues and questions about conda-forge packaging / installation can be done [here](https://github.com/conda-forge/untangle-feedstock/issues).
|
|
31
|
-
|
|
32
|
-
Usage
|
|
33
|
-
-----
|
|
34
|
-
(See and run <a href="https://github.com/stchris/untangle/blob/main/examples.py">examples.py</a> or this blog post: [Read XML painlessly](http://pythonadventures.wordpress.com/2011/10/30/read-xml-painlessly/) for more info)
|
|
35
|
-
|
|
36
|
-
```python
|
|
37
|
-
import untangle
|
|
38
|
-
obj = untangle.parse(resource)
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
``resource`` can be:
|
|
42
|
-
|
|
43
|
-
* a URL
|
|
44
|
-
* a filename
|
|
45
|
-
* an XML string
|
|
46
|
-
|
|
47
|
-
Running the above code and passing this XML:
|
|
48
|
-
|
|
49
|
-
```xml
|
|
50
|
-
<?xml version="1.0"?>
|
|
51
|
-
<root>
|
|
52
|
-
<child name="child1"/>
|
|
53
|
-
</root>
|
|
54
|
-
```
|
|
55
|
-
allows it to be navigated from the ``untangle``d object like this:
|
|
56
|
-
|
|
57
|
-
```python
|
|
58
|
-
obj.root.child['name'] # u'child1'
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
Changelog
|
|
62
|
-
---------
|
|
63
|
-
|
|
64
|
-
see CHANGELOG.md
|
untangle-1.2.1/pyproject.toml
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
[tool.poetry]
|
|
2
|
-
name = "untangle"
|
|
3
|
-
version = "1.2.1"
|
|
4
|
-
description = "Converts XML to Python objects"
|
|
5
|
-
authors = ["Christian Stefanescu <hello@stchris.net>"]
|
|
6
|
-
license = "MIT"
|
|
7
|
-
readme = "README.md"
|
|
8
|
-
|
|
9
|
-
[tool.poetry.dependencies]
|
|
10
|
-
python = "^3.7"
|
|
11
|
-
defusedxml = "^0.7.1"
|
|
12
|
-
|
|
13
|
-
[tool.poetry.dev-dependencies]
|
|
14
|
-
pytest = "^7.1.2"
|
|
15
|
-
flake8 = "^4.0.1"
|
|
16
|
-
black = "^22.6.0"
|
|
17
|
-
build = "^0.8.0"
|
|
18
|
-
setuptools = "^62.6.0"
|
|
19
|
-
wheel = "^0.37.1"
|
|
20
|
-
|
|
21
|
-
[build-system]
|
|
22
|
-
requires = ["poetry-core>=1.0.0"]
|
|
23
|
-
build-backend = "poetry.core.masonry.api"
|
untangle-1.2.1/setup.py
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from setuptools import setup
|
|
3
|
-
|
|
4
|
-
modules = \
|
|
5
|
-
['untangle']
|
|
6
|
-
install_requires = \
|
|
7
|
-
['defusedxml>=0.7.1,<0.8.0']
|
|
8
|
-
|
|
9
|
-
setup_kwargs = {
|
|
10
|
-
'name': 'untangle',
|
|
11
|
-
'version': '1.2.1',
|
|
12
|
-
'description': 'Converts XML to Python objects',
|
|
13
|
-
'long_description': 'untangle\n========\n\n[](https://github.com/stchris/untangle/actions)\n[](https://pypi.python.org/pypi/untangle)\n<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>\n\n[Documentation](http://readthedocs.org/docs/untangle/en/latest/)\n\n* Converts XML to a Python object.\n* Siblings with similar names are grouped into a list.\n* Children can be accessed with ``parent.child``, attributes with ``element[\'attribute\']``.\n* You can call the ``parse()`` method with a filename, an URL or an XML string.\n* Substitutes ``-``, ``.`` and ``:`` with ``_`` ``<foobar><foo-bar/></foobar>`` can be accessed with ``foobar.foo_bar``, ``<foo.bar.baz/>`` can be accessed with ``foo_bar_baz`` and ``<foo:bar><foo:baz/></foo:bar>`` can be accessed with ``foo_bar.foo_baz``\n* Works with Python 3.7 - 3.10\n\nInstallation\n------------\n\nWith pip:\n```\npip install untangle\n```\n\nWith conda:\n```\nconda install -c conda-forge untangle\n```\n\nConda feedstock maintained by @htenkanen. Issues and questions about conda-forge packaging / installation can be done [here](https://github.com/conda-forge/untangle-feedstock/issues).\n\nUsage\n-----\n(See and run <a href="https://github.com/stchris/untangle/blob/main/examples.py">examples.py</a> or this blog post: [Read XML painlessly](http://pythonadventures.wordpress.com/2011/10/30/read-xml-painlessly/) for more info)\n\n```python\nimport untangle\nobj = untangle.parse(resource)\n```\n\n``resource`` can be:\n\n* a URL\n* a filename\n* an XML string\n\nRunning the above code and passing this XML:\n\n```xml\n<?xml version="1.0"?>\n<root>\n\t<child name="child1"/>\n</root>\n```\nallows it to be navigated from the ``untangle``d object like this:\n\n```python\nobj.root.child[\'name\'] # u\'child1\'\n```\n\nChangelog\n---------\n\nsee CHANGELOG.md\n',
|
|
14
|
-
'author': 'Christian Stefanescu',
|
|
15
|
-
'author_email': 'hello@stchris.net',
|
|
16
|
-
'maintainer': None,
|
|
17
|
-
'maintainer_email': None,
|
|
18
|
-
'url': None,
|
|
19
|
-
'py_modules': modules,
|
|
20
|
-
'install_requires': install_requires,
|
|
21
|
-
'python_requires': '>=3.7,<4.0',
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
setup(**setup_kwargs)
|