diff --git a/CHANGELOG.md b/CHANGELOG.md index 36167d1..9d8ed4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ + 2.0.0 ----- ### New features @@ -10,6 +11,11 @@ - `-o`/`--output` option is now a path to an output directory, instead of an output file +1.1.0 +----- +- Add `extract_xml()` and `human_timespamp_to_datetime` methods + + 1.0.5 ----- - Prefix public suffix and GeoIP2 database filenames with `.` diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..217ba35 --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +. ~/venv/domainaware/bin/activate +cd docs && make html && cp -r _build/html/* ../../parsedmarc-docs/ +cd .. +rm -rf dist/ build/ +python setup.py bdist_wheel + diff --git a/makedocs.sh b/makedocs.sh deleted file mode 100644 index 4ad87ec..0000000 --- a/makedocs.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -. ~/venv/domainaware/bin/activate -cd docs && make html && cp -r build/html/* ../../parsedmarc-docs/ diff --git a/parsedmarc.py b/parsedmarc.py index f09612f..fd3163c 100644 --- a/parsedmarc.py +++ b/parsedmarc.py @@ -191,7 +191,7 @@ def _timestamp_to_human(timestamp): return _timestamp_to_datetime(timestamp).strftime("%Y-%m-%d %H:%M:%S") -def _human_timestamp_to_datetime(human_timestamp): +def human_timestamp_to_datetime(human_timestamp): """ Converts a human-readable timestamp into a Python ``DateTime`` object @@ -479,17 +479,17 @@ def parse_aggregate_report_xml(xml, nameservers=None, timeout=6.0): "{0}".format(error.__str__())) -def parse_aggregate_report_file(input_, nameservers=None, timeout=6.0): - """Parses a file at the given path, a file-like object. or bytes as a - aggregate DMARC report +def extract_xml(input_): + """ + Extracts xml from a zip or gzip file at the given path, file-like object, + or bytes. Args: input_: A path to a file, a file like object, or bytes - nameservers (list): A list of one or more nameservers to use - timeout (float): Sets the DNS timeout in seconds Returns: - OrderedDict: The parsed DMARC aggregate report + str: The extracted XML + """ if type(input_) == str or type(input_) == unicode: file_object = open(input_, "rb") @@ -512,10 +512,28 @@ def parse_aggregate_report_file(input_, nameservers=None, timeout=6.0): raise InvalidAggregateReport("Not a valid zip, gzip, or xml file") file_object.close() + except UnicodeDecodeError: raise InvalidAggregateReport("File objects must be opened in binary " "(rb) mode") + return xml + + +def parse_aggregate_report_file(_input, nameservers=None, timeout=6.0): + """Parses a file at the given path, a file-like object. or bytes as a + aggregate DMARC report + + Args: + _input: A path to a file, a file like object, or bytes + nameservers (list): A list of one or more nameservers to use + timeout (float): Sets the DNS timeout in seconds + + Returns: + OrderedDict: The parsed DMARC aggregate report + """ + xml = extract_xml(_input) + return parse_aggregate_report_xml(xml, nameservers=nameservers, timeout=timeout)