xmlpydict 0.0.12__tar.gz → 0.0.13__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xmlpydict
3
- Version: 0.0.12
3
+ Version: 0.0.13
4
4
  Summary: xml to dictionary tool for python
5
5
  Author-email: Matthew Taylor <matthew.taylor.andre@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/MatthewAndreTaylor/xml-to-pydict
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "xmlpydict"
7
- version = "0.0.12"
7
+ version = "0.0.13"
8
8
  description="xml to dictionary tool for python"
9
9
  authors = [
10
10
  {name = "Matthew Taylor", email = "matthew.taylor.andre@gmail.com"},
@@ -1,6 +1,6 @@
1
1
  import pytest
2
2
  import json
3
- from xmlpydict import parse
3
+ from xmlpydict import parse, parse_file
4
4
 
5
5
 
6
6
  def test_simple():
@@ -350,3 +350,35 @@ def test_document():
350
350
  ]
351
351
  }
352
352
  }
353
+
354
+
355
+ def test_parse_file(tmp_path):
356
+ s = """<?xml version="1.0" encoding="UTF-8"?><repository>
357
+ <project pypi="xmlpydict">
358
+ <title>XML document parser</title>
359
+ <author>Matthew Taylor</author>
360
+ </project>
361
+ <project pypi="blank">
362
+ <title>Test project</title>
363
+ <author>Matthew Taylor</author>
364
+ </project>
365
+ </repository>"""
366
+ with open(tmp_path / "test.xml", "w") as f:
367
+ f.write(s)
368
+
369
+ assert parse_file(tmp_path / "test.xml") == {
370
+ "repository": {
371
+ "project": [
372
+ {
373
+ "@pypi": "xmlpydict",
374
+ "title": "XML document parser",
375
+ "author": "Matthew Taylor",
376
+ },
377
+ {
378
+ "@pypi": "blank",
379
+ "title": "Test project",
380
+ "author": "Matthew Taylor",
381
+ },
382
+ ]
383
+ }
384
+ }
@@ -45,9 +45,9 @@ def parse_file(file_path, attr_prefix: str = "@", cdata_key: str = "#text") -> d
45
45
  return handler.item
46
46
 
47
47
 
48
-
49
- def iter_xml_documents(file_path, chunk_size=64 * 1024):
50
- start_token = b"<?xml"
48
+ def iter_xml_documents(
49
+ file_path, chunk_size: int = 64 * 1024, start_token: bytes = b"<?xml"
50
+ ):
51
51
  buffer = b""
52
52
  with open(file_path, "rb") as f:
53
53
  while True:
@@ -63,13 +63,27 @@ def iter_xml_documents(file_path, chunk_size=64 * 1024):
63
63
  break
64
64
  yield buffer[:start_index]
65
65
  buffer = buffer[start_index:]
66
-
67
-
68
66
 
69
- def parse_xml_collections(file_path, attr_prefix: str = "@", cdata_key: str = "#text"):
70
- for xml_content in iter_xml_documents(file_path):
67
+
68
+ def parse_xml_collections(
69
+ file_path,
70
+ attr_prefix: str = "@",
71
+ cdata_key: str = "#text",
72
+ start_token: bytes = b"<?xml",
73
+ ):
74
+ """
75
+ Parse collections of xml documents based on a delimeter start_token
76
+
77
+ Args:
78
+ file_path: The path to the XML file to be parsed.
79
+ attr_prefix: The prefix to use for attributes in the resulting dictionary.
80
+ cdata_key: The key to use for character data in the resulting dictionary.
81
+ start_token: The byte sequence that delimits the start of each XML document.
82
+
83
+ Returns:
84
+ A generator yielding dictionaries representing each XML document in the collection.
85
+ """
86
+ for xml_content in iter_xml_documents(file_path, start_token=start_token):
71
87
  yield parse(
72
- xml_content.decode("utf-8"),
73
- attr_prefix=attr_prefix,
74
- cdata_key=cdata_key
88
+ xml_content.decode("utf-8"), attr_prefix=attr_prefix, cdata_key=cdata_key
75
89
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xmlpydict
3
- Version: 0.0.12
3
+ Version: 0.0.13
4
4
  Summary: xml to dictionary tool for python
5
5
  Author-email: Matthew Taylor <matthew.taylor.andre@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/MatthewAndreTaylor/xml-to-pydict
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes