## 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.
.
This commit is contained in:
Sean Whalen
2025-12-02 19:41:14 -05:00
parent d312522ab7
commit cf3b7f2c29
3 changed files with 23 additions and 6 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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()