From b97a6f5150c89288dd1f1685c8d58aef949161a7 Mon Sep 17 00:00:00 2001 From: Sean Whalen Date: Wed, 18 Jul 2018 09:46:40 -0400 Subject: [PATCH] 3.7.0 --- CHANGELOG.md | 6 ++++++ parsedmarc/__init__.py | 21 +++++++++++---------- setup.py | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 171ec996..ec268bb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +3.7.0 +----- + +- Fix bug where PSL would be called before it was downloaded if the PSL was +older than 24 Hours + 3.6.1 ----- diff --git a/parsedmarc/__init__.py b/parsedmarc/__init__.py index 2b08e19d..0a5c71f6 100644 --- a/parsedmarc/__init__.py +++ b/parsedmarc/__init__.py @@ -43,7 +43,7 @@ import imapclient.exceptions import dateparser import mailparser -__version__ = "3.6.1" +__version__ = "3.7.0" logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) @@ -100,22 +100,23 @@ def _get_base_domain(domain): psl_path = ".public_suffix_list.dat" def download_psl(): - fresh_psl = publicsuffix.fetch() + fresh_psl = publicsuffix.fetch().read() with open(psl_path, "w", encoding="utf-8") as fresh_psl_file: - fresh_psl_file.write(fresh_psl.read()) - - return publicsuffix.PublicSuffixList(fresh_psl) + fresh_psl_file.write(fresh_psl) if not os.path.exists(psl_path): - psl = download_psl() + download_psl() else: psl_age = datetime.now() - datetime.fromtimestamp( os.stat(psl_path).st_mtime) if psl_age > timedelta(hours=24): - psl = download_psl() - else: - with open(psl_path, encoding="utf-8") as psl_file: - psl = publicsuffix.PublicSuffixList(psl_file) + try: + download_psl() + except Exception as error: + logger.warning("Failed to download an updated PSL - \ + {0}".format(error)) + with open(psl_path, encoding="utf-8") as psl_file: + psl = publicsuffix.PublicSuffixList(psl_file) return psl.get_public_suffix(domain) diff --git a/setup.py b/setup.py index 90dd1d5c..cc493676 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ from setuptools import setup from codecs import open from os import path -__version__ = "3.6.1" +__version__ = "3.7.0" description = "A Python package and CLI for parsing aggregate and " \ "forensic DMARC reports"