Skip to content

Commit f8f7f32

Browse files
authored
Merge pull request #128 from cisagov/bug/switch_psl_helper_package
Switch helper package for the Public Suffix List
2 parents 1ad8975 + 08dcea2 commit f8f7f32

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def get_version(version_file):
9292
install_requires=[
9393
"dnspython",
9494
"docopt",
95-
"publicsuffix",
95+
"publicsuffixlist[update]",
9696
"py3dns",
9797
"pyspf",
9898
"requests",

src/trustymail/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""This file defines the version of this module."""
2-
__version__ = "0.8.0"
2+
__version__ = "0.8.1"

src/trustymail/domain.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,32 @@
77
from typing import Dict
88

99
# Third-Party Libraries
10-
import publicsuffix
10+
from publicsuffixlist.compat import PublicSuffixList
11+
from publicsuffixlist.update import updatePSL
1112

1213
from . import PublicSuffixListFilename, PublicSuffixListReadOnly, trustymail
1314

1415

1516
def get_psl():
16-
"""
17-
Get the Public Suffix List - either new, or cached in the CWD for 24 hours.
17+
"""Get the Public Suffix List - either new, or cached in the CWD for 24 hours.
1818
1919
Returns
2020
-------
2121
PublicSuffixList: An instance of PublicSuffixList loaded with a cached or updated list
2222
"""
23-
24-
def download_psl():
25-
fresh_psl = publicsuffix.fetch()
26-
with open(PublicSuffixListFilename, "w", encoding="utf-8") as fresh_psl_file:
27-
fresh_psl_file.write(fresh_psl.read())
28-
29-
# Download the psl if necessary
23+
# Download the PSL if necessary
3024
if not PublicSuffixListReadOnly:
3125
if not path.exists(PublicSuffixListFilename):
32-
download_psl()
26+
updatePSL(PublicSuffixListFilename)
3327
else:
3428
psl_age = datetime.now() - datetime.fromtimestamp(
3529
stat(PublicSuffixListFilename).st_mtime
3630
)
3731
if psl_age > timedelta(hours=24):
38-
download_psl()
32+
updatePSL(PublicSuffixListFilename)
3933

4034
with open(PublicSuffixListFilename, encoding="utf-8") as psl_file:
41-
psl = publicsuffix.PublicSuffixList(psl_file)
35+
psl = PublicSuffixList(psl_file)
4236

4337
return psl
4438

0 commit comments

Comments
 (0)