python-disposable 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- disposable_email/__init__.py +80 -0
- disposable_email/_version.py +34 -0
- disposable_email/domains.txt +72171 -0
- disposable_email/domains_strict.txt +26469 -0
- python_disposable-0.0.1.dist-info/METADATA +83 -0
- python_disposable-0.0.1.dist-info/RECORD +8 -0
- python_disposable-0.0.1.dist-info/WHEEL +4 -0
- python_disposable-0.0.1.dist-info/licenses/LICENSE +23 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from importlib.resources import files
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
_domains: Optional[frozenset[str]] = None
|
|
7
|
+
_domains_strict: Optional[frozenset[str]] = None
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _load(strict: bool = False) -> frozenset[str]:
|
|
11
|
+
global _domains, _domains_strict
|
|
12
|
+
if strict:
|
|
13
|
+
if _domains_strict is None:
|
|
14
|
+
data = files("disposable_email").joinpath("domains_strict.txt").read_text(encoding="utf-8")
|
|
15
|
+
_domains_strict = frozenset(line.strip().lower() for line in data.splitlines() if line.strip())
|
|
16
|
+
return _domains_strict
|
|
17
|
+
else:
|
|
18
|
+
if _domains is None:
|
|
19
|
+
data = files("disposable_email").joinpath("domains.txt").read_text(encoding="utf-8")
|
|
20
|
+
_domains = frozenset(line.strip().lower() for line in data.splitlines() if line.strip())
|
|
21
|
+
return _domains
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _extract_domain(email_or_domain: str) -> str:
|
|
25
|
+
"""Extract and normalize domain, stripping subdomains if needed."""
|
|
26
|
+
domain = email_or_domain.split("@")[-1].strip().lower()
|
|
27
|
+
return domain
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _is_disposable_domain(domain: str, strict: bool = False) -> bool:
|
|
31
|
+
"""Check domain and progressively strip subdomains until a match is found."""
|
|
32
|
+
domains = _load(strict)
|
|
33
|
+
parts = domain.split(".")
|
|
34
|
+
# Check from full domain down to second-level domain (e.g. a.b.c.com -> b.c.com -> c.com)
|
|
35
|
+
for i in range(len(parts) - 1):
|
|
36
|
+
candidate = ".".join(parts[i:])
|
|
37
|
+
if candidate in domains:
|
|
38
|
+
return True
|
|
39
|
+
return False
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def is_disposable(email_or_domain: str, strict: bool = False) -> bool:
|
|
43
|
+
"""Return True if the email address or domain is a known disposable/temporary email service.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
email_or_domain: An email address (user@example.com) or bare domain (example.com).
|
|
47
|
+
strict: If True, also flags greylisted domains (anonymous signup services).
|
|
48
|
+
"""
|
|
49
|
+
domain = _extract_domain(email_or_domain)
|
|
50
|
+
if not domain:
|
|
51
|
+
return False
|
|
52
|
+
return _is_disposable_domain(domain, strict=strict)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def is_valid(email_or_domain: str, strict: bool = False) -> bool:
|
|
56
|
+
"""Return True if the email address or domain is NOT a known disposable/temporary email service.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
email_or_domain: An email address (user@example.com) or bare domain (example.com).
|
|
60
|
+
strict: If True, also flags greylisted domains (anonymous signup services).
|
|
61
|
+
"""
|
|
62
|
+
return not is_disposable(email_or_domain, strict=strict)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def get_domains(strict: bool = False) -> frozenset[str]:
|
|
66
|
+
"""Return the full set of known disposable domains.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
strict: If True, returns the strict list (includes greylisted domains).
|
|
70
|
+
"""
|
|
71
|
+
return _load(strict)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def domain_count(strict: bool = False) -> int:
|
|
75
|
+
"""Return the number of known disposable domains in the bundled list.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
strict: If True, returns the count for the strict list.
|
|
79
|
+
"""
|
|
80
|
+
return len(_load(strict))
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
TYPE_CHECKING = False
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from typing import Tuple
|
|
16
|
+
from typing import Union
|
|
17
|
+
|
|
18
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
20
|
+
else:
|
|
21
|
+
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
23
|
+
|
|
24
|
+
version: str
|
|
25
|
+
__version__: str
|
|
26
|
+
__version_tuple__: VERSION_TUPLE
|
|
27
|
+
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
30
|
+
|
|
31
|
+
__version__ = version = '0.0.1'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 0, 1)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = None
|