You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-2Lines changed: 38 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
1
# XML dataclasses
2
2
3
-
This is a very rough prototype of how a library might look like for (de)serialising XML into dataclasses. XML dataclasses build on normal dataclasses from the standard library and [`lxml`](https://pypi.org/project/lxml/) elements. Loading and saving these elements is left to the consumer for flexibility of the desired output.
3
+
This is a very rough prototype of how a library might look like for (de)serialising XML into Python dataclasses. XML dataclasses build on normal dataclasses from the standard library and [`lxml`](https://pypi.org/project/lxml/) elements. Loading and saving these elements is left to the consumer for flexibility of the desired output.
4
4
5
5
It isn't ready for production if you aren't willing to do your own evaluation/quality assurance. I don't recommend using this library with untrusted content. It inherits all of `lxml`'s flaws with regards to XML attacks, and recursively resolves data structures. Because deserialisation is driven from the dataclass definitions, it shouldn't be possible to execute arbitrary Python code. But denial of service attacks would very likely be feasible.
6
6
7
+
Requires Python 3.7 or higher.
8
+
7
9
## Example
8
10
9
11
(This is a simplified real world example - the container can also include optional `links` child elements.)
@@ -42,14 +44,16 @@ class Container:
42
44
__ns__ =CONTAINER_NS
43
45
version: str= attr()
44
46
rootfiles: RootFiles = child()
47
+
# WARNING: this is an incomplete implementation of an OPF container
@@ -75,3 +79,35 @@ Most of these limitations/assumptions are enforced. They may make this project u
75
79
* Deserialisation is strict; missing required attributes and child elements will cause an error
76
80
* Unions of types aren't yet supported
77
81
* Dataclasses must be written by hand, no tools are provided to generate these from, DTDs, XML schema definitions, or RELAX NG schemas
82
+
83
+
## Development
84
+
85
+
This project uses [pre-commit](https://pre-commit.com/) to run some linting hooks when committing. When you first clone the repo, please run:
86
+
87
+
```
88
+
pre-commit install
89
+
```
90
+
91
+
You may also run the hooks at any time:
92
+
93
+
```
94
+
pre-commit run --all-files
95
+
```
96
+
97
+
Dependencies are managed via [poetry](https://python-poetry.org/). To install all dependencies, use:
98
+
99
+
```
100
+
poetry install
101
+
```
102
+
103
+
This will also install development dependencies such as `black`, `isort`, `pylint`, `mypy`, and `pytest`. I've provided a simple script to run these during development called `lint`. You can either run it from a shell session with the poetry-installed virtual environment, or run as follows:
104
+
105
+
```
106
+
poetry run ./lint
107
+
```
108
+
109
+
Auto-formatters will be applied, and static analysis/tests are run in order. The script stops on failure to allow quick iteration.
110
+
111
+
## License
112
+
113
+
This library is licensed under the Mozilla Public License Version 2.0. For more information, see `LICENSE`.
0 commit comments