Skip to content

Commit 2750a82

Browse files
committed
Drop support for Python <3.6 and dnspython 1.x
1 parent 34b5856 commit 2750a82

File tree

4 files changed

+13
-29
lines changed

4 files changed

+13
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
In Development
22
--------------
33

4+
* Python versions through 3.5 and dnspython 1.x are no longer supported. Python 3.6+ with dnspython 2.x are now required.
45
* The library has been reorganized internally into smaller modules.
56

67
Version 1.3.1 (January 21, 2023)

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ email-validator: Validate Email Addresses
22
=========================================
33

44
A robust email address syntax and deliverability validation library for
5-
Python by [Joshua Tauberer](https://joshdata.me).
5+
Python 3.6+ by [Joshua Tauberer](https://joshdata.me).
66

7-
This library validates that a string is of the form `name@example.com`. This is
8-
the sort of validation you would want for an email-based login form on
9-
a website.
7+
This library validates that a string is of the form `name@example.com` and optionally checks that the domain name is set up to receive email. This is
8+
the sort of validation you would want for an email-based registration form on
9+
a website (but not necessarily for composing an email message).
1010

1111
Key features:
1212

1313
* Checks that an email address has the correct syntax --- good for
14-
login forms or other uses related to identifying users.
14+
registration/login forms or other uses related to identifying users.
1515
* Gives friendly error messages when validation fails (appropriate to show
1616
to end users).
17-
* (optionally) Checks deliverability: Does the domain name resolve? And you can override the default DNS resolver.
17+
* (optionally) Checks deliverability: Does the domain name resolve? You can override the default DNS resolver.
1818
* Supports internationalized domain names and (optionally)
1919
internationalized local parts, but blocks unsafe characters.
2020
* Normalizes email addresses (super important for internationalized
@@ -27,8 +27,6 @@ And this library does NOT permit obsolete forms of email addresses, so
2727
if you need strict validation against the email specs exactly, use
2828
[pyIsEmail](https://github.com/michaelherold/pyIsEmail).
2929

30-
This library is tested with Python 3.6+ but should work in earlier versions:
31-
3230
[![Build Status](https://app.travis-ci.com/JoshData/python-email-validator.svg?branch=main)](https://app.travis-ci.com/JoshData/python-email-validator)
3331

3432
View the [CHANGELOG / Release Notes](CHANGELOG.md) for the version history of changes in the library. Occasionally this README is ahead of the latest published package --- see the CHANGELOG for details.

email_validator/deliverability.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,6 @@ def validate_email_deliverability(domain, domain_i18n, timeout=None, dns_resolve
3232

3333
deliverability_info = {}
3434

35-
def dns_resolver_resolve_shim(domain, record):
36-
try:
37-
# dns.resolver.Resolver.resolve is new to dnspython 2.x.
38-
# https://dnspython.readthedocs.io/en/latest/resolver-class.html#dns.resolver.Resolver.resolve
39-
return dns_resolver.resolve(domain, record)
40-
except AttributeError:
41-
# dnspython 2.x is only available in Python 3.6 and later. For earlier versions
42-
# of Python, we maintain compatibility with dnspython 1.x which has a
43-
# dnspython.resolver.Resolver.query method instead. The only difference is that
44-
# query may treat the domain as relative and use the system's search domains,
45-
# which we prevent by adding a "." to the domain name to make it absolute.
46-
# dns.resolver.Resolver.query is deprecated in dnspython version 2.x.
47-
# https://dnspython.readthedocs.io/en/latest/resolver-class.html#dns.resolver.Resolver.query
48-
return dns_resolver.query(domain + ".", record)
49-
5035
try:
5136
# We need a way to check how timeouts are handled in the tests. So we
5237
# have a secret variable that if set makes this method always test the
@@ -56,7 +41,7 @@ def dns_resolver_resolve_shim(domain, record):
5641

5742
try:
5843
# Try resolving for MX records.
59-
response = dns_resolver_resolve_shim(domain, "MX")
44+
response = dns_resolver.resolve(domain, "MX")
6045

6146
# For reporting, put them in priority order and remove the trailing dot in the qnames.
6247
mtas = sorted([(r.preference, str(r.exchange).rstrip('.')) for r in response])
@@ -76,14 +61,14 @@ def dns_resolver_resolve_shim(domain, record):
7661

7762
# If there was no MX record, fall back to an A record, as SMTP servers do.
7863
try:
79-
response = dns_resolver_resolve_shim(domain, "A")
64+
response = dns_resolver.resolve(domain, "A")
8065
deliverability_info["mx"] = [(0, str(r)) for r in response]
8166
deliverability_info["mx_fallback_type"] = "A"
8267
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
8368

8469
# If there was no A record, fall back to an AAAA record.
8570
try:
86-
response = dns_resolver_resolve_shim(domain, "AAAA")
71+
response = dns_resolver.resolve(domain, "AAAA")
8772
deliverability_info["mx"] = [(0, str(r)) for r in response]
8873
deliverability_info["mx_fallback_type"] = "AAAA"
8974
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
@@ -98,7 +83,7 @@ def dns_resolver_resolve_shim(domain, record):
9883
# absence of an MX record, this is probably a good sign that the
9984
# domain is not used for email.
10085
try:
101-
response = dns_resolver_resolve_shim(domain, "TXT")
86+
response = dns_resolver.resolve(domain, "TXT")
10287
for rec in response:
10388
value = b"".join(rec.strings)
10489
if value.startswith(b"v=spf1 "):

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ keywords = email address validator
2424
[options]
2525
packages = find:
2626
install_requires =
27-
dnspython>=1.15.0
27+
dnspython>=2.0.0
2828
idna>=2.0.0
29-
python_requires = >=3.5
29+
python_requires = >=3.6
3030

3131
[options.entry_points]
3232
console_scripts =

0 commit comments

Comments
 (0)