forked from karolyi/py3-validate-email
Don't use a lockfile when the blacklist update is disabled
This commit is contained in:
parent
91fb131abf
commit
667760f723
|
@ -1,3 +1,6 @@
|
|||
1.0.5:
|
||||
- Remove lockfile creation when the updater process is skipped per the environment variable introduced in 1.0.4
|
||||
|
||||
1.0.4:
|
||||
- Skipping the startup update with setting an environment variable called `PY3VE_IGNORE_UPDATER`
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -57,7 +57,7 @@ class BuildPyCommand(build_py):
|
|||
|
||||
setup(
|
||||
name='py3-validate-email',
|
||||
version='1.0.4',
|
||||
version='1.0.5',
|
||||
packages=find_packages(exclude=['tests']),
|
||||
install_requires=['dnspython~=2.1', 'idna~=3.0', 'filelock~=3.0'],
|
||||
author='László Károlyi',
|
||||
|
|
|
@ -40,17 +40,26 @@ class DomainListValidator(object):
|
|||
except FileNotFoundError:
|
||||
return BLACKLIST_FILEPATH_INSTALLED
|
||||
|
||||
def _get_blacklist_lines(self) -> list:
|
||||
'Return the lines of blacklist.txt as a list.'
|
||||
bl_path = self._blacklist_path
|
||||
LOGGER.debug(msg=f'(Re)loading blacklist from {bl_path}')
|
||||
try:
|
||||
with open(bl_path) as fd:
|
||||
return fd.readlines()
|
||||
except FileNotFoundError:
|
||||
return []
|
||||
|
||||
def reload_builtin_blacklist(self):
|
||||
'(Re)load our built-in blacklist.'
|
||||
TMP_PATH.mkdir(exist_ok=True)
|
||||
with FileLock(lock_file=str(LOCK_PATH)):
|
||||
bl_path = self._blacklist_path
|
||||
LOGGER.debug(msg=f'(Re)loading blacklist from {bl_path}')
|
||||
try:
|
||||
with open(bl_path) as fd:
|
||||
lines = fd.readlines()
|
||||
except FileNotFoundError:
|
||||
return
|
||||
# Locking is only necessary when we might have an updater
|
||||
# process running
|
||||
if ENV_IGNORE_UPDATER:
|
||||
lines = self._get_blacklist_lines()
|
||||
else:
|
||||
TMP_PATH.mkdir(exist_ok=True)
|
||||
with FileLock(lock_file=str(LOCK_PATH)):
|
||||
lines = self._get_blacklist_lines()
|
||||
self.domain_blacklist = set(
|
||||
x.strip().lower() for x in lines if x.strip())
|
||||
|
||||
|
|
Loading…
Reference in New Issue