Skip to content

Commit

Permalink
fix: add missing public functions to __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterious-ben committed May 3, 2021
1 parent f0fe71d commit 14c8a99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion xmlrecords/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from xmlrecords.src.xmlrecords import parse
from xmlrecords.src.xmlrecords import XMLParsingError, XMLValidationError, parse, validate
9 changes: 7 additions & 2 deletions xmlrecords/src/xmlrecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
from xml.etree import ElementTree


class XMLParsingError(ValueError):
pass


def _update_dict_nocollision(d1: dict, d2: dict) -> None:
expected_length = len(d1) + len(d2)
d1.update(d2)
if len(d1) != expected_length:
common_keys = set(d1.keys()).intersection(set(d2.keys()))
raise ValueError(
raise XMLParsingError(
f"Dictionaries have common keys: {common_keys} (try setting prefix to True)"
)

Expand Down Expand Up @@ -104,6 +108,7 @@ def parse(
* = all namespaces
:param remove_namespace: if true, do not include namespace in the record key
:return: list of records
:raises: XMLParsingError (subclass of ValueError)
"""

tree = ElementTree.fromstring(xml)
Expand Down Expand Up @@ -172,7 +177,7 @@ class XMLValidationError(ValueError):
def validate(records: List[dict], expected_keys: List[str]):
"""Validate that records have all expected keys
:raises: XMLParsingError
:raises: XMLValidationError (subclass of ValueError)
"""
for i, r in enumerate(records):
if list(r.keys()) != expected_keys:
Expand Down

0 comments on commit 14c8a99

Please sign in to comment.