Downloading blacklist.txt on install
This commit is contained in:
parent
ce2fa590fd
commit
443f264fd7
|
@ -3,6 +3,7 @@ include LICENSE
|
||||||
include README.rst
|
include README.rst
|
||||||
recursive-include validate_email *
|
recursive-include validate_email *
|
||||||
prune tests
|
prune tests
|
||||||
|
recursive-exclude tests *
|
||||||
recursive-exclude * __pycache__
|
recursive-exclude * __pycache__
|
||||||
recursive-exclude * *.pyc
|
recursive-exclude * *.pyc
|
||||||
recursive-exclude * *.pyo
|
recursive-exclude * *.pyo
|
||||||
|
|
39
setup.py
39
setup.py
|
@ -1,30 +1,33 @@
|
||||||
from setuptools import setup
|
from os.path import join
|
||||||
from setuptools.command.develop import develop
|
from urllib.request import urlopen
|
||||||
from setuptools.command.install import install
|
|
||||||
|
from setuptools import find_packages, setup
|
||||||
|
from setuptools.command.build_py import build_py
|
||||||
|
|
||||||
|
blacklist_url = (
|
||||||
|
'https://raw.githubusercontent.com/martenson/disposable-email-domains/'
|
||||||
|
'master/disposable_email_blocklist.conf')
|
||||||
|
|
||||||
|
|
||||||
class PostDevelopCommand(develop):
|
class PostBuildPyCommand(build_py):
|
||||||
'Post-installation for development mode'
|
'Post-installation for build_py'
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
if self.dry_run:
|
||||||
|
return super().run()
|
||||||
|
with urlopen(url=blacklist_url) as fd:
|
||||||
|
content = fd.read().decode('utf-8')
|
||||||
|
target_dir = join(self.build_lib, 'validate_email/lib')
|
||||||
|
self.mkpath(target_dir)
|
||||||
|
with open(join(target_dir, 'blacklist.txt'), 'w') as fd:
|
||||||
|
fd.write(content)
|
||||||
super().run()
|
super().run()
|
||||||
with open('/tmp/test-develop', 'w') as fd:
|
|
||||||
fd.write(str(vars(self)))
|
|
||||||
|
|
||||||
|
|
||||||
class PostInstallCommand(install):
|
|
||||||
'Post-installation for installation mode'
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
super().run()
|
|
||||||
with open('/tmp/test-install', 'w') as fd:
|
|
||||||
fd.write(str(vars(self)))
|
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='py3-validate-email',
|
name='py3-validate-email',
|
||||||
version='0.1',
|
version='0.1',
|
||||||
py_modules=('validate_email',),
|
packages=find_packages(exclude=['tests']),
|
||||||
install_requires=['dnspython'],
|
install_requires=['dnspython'],
|
||||||
author='László Károlyi',
|
author='László Károlyi',
|
||||||
author_email='laszlo@karolyi.hu',
|
author_email='laszlo@karolyi.hu',
|
||||||
|
@ -32,6 +35,6 @@ setup(
|
||||||
long_description=open('README.rst').read(),
|
long_description=open('README.rst').read(),
|
||||||
keywords='email validation verification mx verify',
|
keywords='email validation verification mx verify',
|
||||||
url='http://github.com/karolyi/py3-validate-email',
|
url='http://github.com/karolyi/py3-validate-email',
|
||||||
cmdclass=dict(develop=PostDevelopCommand, install=PostInstallCommand),
|
cmdclass=dict(build_py=PostBuildPyCommand),
|
||||||
license='LGPL',
|
license='LGPL',
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from ipaddress import IPv4Address, IPv6Address
|
from ipaddress import IPv4Address, IPv6Address
|
||||||
|
from os.path import dirname, join
|
||||||
from re import IGNORECASE
|
from re import IGNORECASE
|
||||||
from re import compile as re_compile
|
from re import compile as re_compile
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
@ -51,10 +52,24 @@ class EmailValidator(object):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, whitelist: SetOrNone = None, blacklist: SetOrNone = None):
|
self, whitelist: SetOrNone = None, blacklist: SetOrNone = None):
|
||||||
self.domain_whitelist = whitelist or self.domain_whitelist
|
self.domain_whitelist = set(whitelist) \
|
||||||
self.domain_blacklist = blacklist or self.domain_blacklist
|
if whitelist else self.domain_whitelist
|
||||||
|
self._load_blacklist(blacklist=blacklist)
|
||||||
|
|
||||||
def __call__(self, value) -> bool:
|
def _load_blacklist(self, blacklist: SetOrNone = None):
|
||||||
|
'Load our blacklist.'
|
||||||
|
self.domain_blacklist = set(blacklist) \
|
||||||
|
if blacklist else self.domain_blacklist
|
||||||
|
path = join(dirname(__file__), 'lib', 'blacklist.txt')
|
||||||
|
try:
|
||||||
|
with open(path) as fd:
|
||||||
|
lines = fd.readlines()
|
||||||
|
except FileNotFoundError:
|
||||||
|
return
|
||||||
|
self.domain_blacklist = self.domain_blacklist.union(
|
||||||
|
x.strip() for x in lines)
|
||||||
|
|
||||||
|
def __call__(self, value: str, use_blacklist: bool) -> bool:
|
||||||
if not value or '@' not in value:
|
if not value or '@' not in value:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ from .regex_check import regex_check
|
||||||
|
|
||||||
|
|
||||||
def validate_email(
|
def validate_email(
|
||||||
email_address, check_regex=True, check_mx=True, smtp_timeout=10):
|
email_address: str, check_regex: bool = True, check_mx: bool = True,
|
||||||
|
smtp_timeout: int = 10, use_blacklist: bool = True) -> bool:
|
||||||
|
|
||||||
if check_regex and not regex_check(email_address):
|
if check_regex and not regex_check(email_address):
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in New Issue