diff --git a/CHANGELOG.md b/CHANGELOG.md index 65be704..8caa334 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 9.0.2 + +## Improvements + +- Type hinting is now used properly across the entire library. (#445) + +## Fixes + +- Decompress report files as needed when passed via the CLI. +- Fixed incomplete removal of the ability for `parsedmarc.utils.extract_report` to accept a file path directly in `8.15.0`. + +## Breaking changes + +This version of the library requires consumers to pass certain arguments as keyword-only. Internally, the API uses a bare `*` in the function signature. This is standard per [PEP 3102](https://peps.python.org/pep-3102/) and as documented in the Python Language Reference. + ## 9.0.1 ### Fixes diff --git a/parsedmarc/__init__.py b/parsedmarc/__init__.py index 0b45659..8c2c849 100644 --- a/parsedmarc/__init__.py +++ b/parsedmarc/__init__.py @@ -853,9 +853,7 @@ def extract_report(content: Union[bytes, str, IO[Any]]) -> str: try: file_object = BytesIO(b64decode(content)) except binascii.Error: - pass - if file_object is None: - file_object = open(content, "rb") + return content elif type(content) is bytes: file_object = BytesIO(content) else: @@ -879,10 +877,12 @@ def extract_report(content: Union[bytes, str, IO[Any]]) -> str: file_object.close() except UnicodeDecodeError: - file_object.close() + if file_object: + file_object.close() raise ParserError("File objects must be opened in binary (rb) mode") except Exception as error: - file_object.close() + if file_object: + file_object.close() raise ParserError("Invalid archive file: {0}".format(error.__str__())) return report @@ -1612,6 +1612,8 @@ def parse_report_file( content = file_object.read() file_object.close() + if content.startswith(MAGIC_ZIP) or content.startswith(MAGIC_GZIP): + content = extract_report(content) try: report = parse_aggregate_report_file( content, diff --git a/tests.py b/tests.py index a5ce47a..121bab3 100644 --- a/tests.py +++ b/tests.py @@ -74,7 +74,7 @@ class Test(unittest.TestCase): print() file = "samples/extract_report/nice-input.xml" print("Testing {0}: ".format(file), end="") - xmlout = parsedmarc.extract_report(file) + xmlout = parsedmarc.extract_report_from_file_path(file) xmlin_file = open("samples/extract_report/nice-input.xml") xmlin = xmlin_file.read() xmlin_file.close()