Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
john-kurkowski committed Aug 27, 2021
1 parent f5c7397 commit 3b9af51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_ip():


def test_looks_like_ip():
assert_extract(u'1\xe9', ('', '', u'1\xe9', ''))
assert_extract('1\xe9', ('', '', '1\xe9', ''))


def test_punycode():
Expand Down Expand Up @@ -134,9 +134,9 @@ def test_invalid_puny_with_puny():


def test_puny_with_non_puny():
assert_extract(u'http://xn--zckzap6140b352by.blog.so-net.教育.hk',
(u'xn--zckzap6140b352by.blog.so-net.教育.hk',
'xn--zckzap6140b352by.blog', 'so-net', u'教育.hk'))
assert_extract('http://xn--zckzap6140b352by.blog.so-net.教育.hk',
('xn--zckzap6140b352by.blog.so-net.教育.hk',
'xn--zckzap6140b352by.blog', 'so-net', '教育.hk'))


def test_idna_2008():
Expand Down
14 changes: 9 additions & 5 deletions tldextract/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ def get_pkg_unique_identifier():
tldextract_version = "tldextract-" + version
python_env_name = os.path.basename(sys.prefix)
# just to handle the edge case of two identically named python environments
python_binary_path_short_hash = hashlib.md5(sys.prefix.encode("utf-8")).hexdigest()[:6]
python_binary_path_short_hash = hashlib.md5(sys.prefix.encode("utf-8")).hexdigest()[
:6
]
python_version = ".".join([str(v) for v in sys.version_info[:-1]])
identifier_parts = [
python_version,
python_env_name,
python_binary_path_short_hash,
tldextract_version
tldextract_version,
]
pkg_identifier = "__".join(identifier_parts)

Expand All @@ -62,7 +64,9 @@ def get_cache_dir():
xdg_cache_home = os.path.join(user_home, ".cache")

if xdg_cache_home is not None:
return os.path.join(xdg_cache_home, "python-tldextract", get_pkg_unique_identifier())
return os.path.join(
xdg_cache_home, "python-tldextract", get_pkg_unique_identifier()
)

# fallback to trying to use package directory itself
return os.path.join(os.path.dirname(__file__), ".suffix_cache/")
Expand All @@ -88,7 +92,7 @@ def get(self, namespace, key):
if not os.path.isfile(cache_filepath):
raise KeyError("namespace: " + namespace + " key: " + repr(key))
try:
with open(cache_filepath) as cache_file:
with open(cache_filepath) as cache_file: # pylint: disable=unspecified-encoding
return json.load(cache_file)
except (OSError, ValueError) as exc:
LOG.error("error reading TLD cache file %s: %s", cache_filepath, exc)
Expand All @@ -104,7 +108,7 @@ def set(self, namespace, key, value):

try:
_make_dir(cache_filepath)
with open(cache_filepath, "w") as cache_file:
with open(cache_filepath, "w") as cache_file: # pylint: disable=unspecified-encoding
json.dump(value, cache_file)
except OSError as ioe:
global _DID_LOG_UNABLE_TO_CACHE # pylint: disable=global-statement
Expand Down

0 comments on commit 3b9af51

Please sign in to comment.