Skip to content

Commit

Permalink
Merge pull request #128 from cisagov/bug/switch_psl_helper_package
Browse files Browse the repository at this point in the history
Switch helper package for the Public Suffix List
  • Loading branch information
jsf9k authored Jan 30, 2023
2 parents 1ad8975 + 08dcea2 commit f8f7f32
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_version(version_file):
install_requires=[
"dnspython",
"docopt",
"publicsuffix",
"publicsuffixlist[update]",
"py3dns",
"pyspf",
"requests",
Expand Down
2 changes: 1 addition & 1 deletion src/trustymail/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""This file defines the version of this module."""
__version__ = "0.8.0"
__version__ = "0.8.1"
20 changes: 7 additions & 13 deletions src/trustymail/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,32 @@
from typing import Dict

# Third-Party Libraries
import publicsuffix
from publicsuffixlist.compat import PublicSuffixList
from publicsuffixlist.update import updatePSL

from . import PublicSuffixListFilename, PublicSuffixListReadOnly, trustymail


def get_psl():
"""
Get the Public Suffix List - either new, or cached in the CWD for 24 hours.
"""Get the Public Suffix List - either new, or cached in the CWD for 24 hours.
Returns
-------
PublicSuffixList: An instance of PublicSuffixList loaded with a cached or updated list
"""

def download_psl():
fresh_psl = publicsuffix.fetch()
with open(PublicSuffixListFilename, "w", encoding="utf-8") as fresh_psl_file:
fresh_psl_file.write(fresh_psl.read())

# Download the psl if necessary
# Download the PSL if necessary
if not PublicSuffixListReadOnly:
if not path.exists(PublicSuffixListFilename):
download_psl()
updatePSL(PublicSuffixListFilename)
else:
psl_age = datetime.now() - datetime.fromtimestamp(
stat(PublicSuffixListFilename).st_mtime
)
if psl_age > timedelta(hours=24):
download_psl()
updatePSL(PublicSuffixListFilename)

with open(PublicSuffixListFilename, encoding="utf-8") as psl_file:
psl = publicsuffix.PublicSuffixList(psl_file)
psl = PublicSuffixList(psl_file)

return psl

Expand Down

0 comments on commit f8f7f32

Please sign in to comment.