Skip to content

Commit 34b5856

Browse files
committed
Remove Python 2.x shims and tests since Py2 is not supported anymore
See d7fd074.
1 parent ab293fd commit 34b5856

File tree

5 files changed

+16
-70
lines changed

5 files changed

+16
-70
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,6 @@ part is converted to [IDNA ASCII](https://tools.ietf.org/html/rfc5891).
251251
(You probably should not do this at account creation time so you don't
252252
change the user's login information without telling them.)
253253

254-
### Support for Python 2.7
255-
256-
The last version of this library supporting Python 2.x is version 1.2.1.
257-
258-
When using Python 2.x, it is required that it was built with
259-
UCS-4 support (see
260-
[here](https://stackoverflow.com/questions/29109944/python-returns-length-of-2-for-single-unicode-character-string)).
261-
Without UCS-4 support, unicode characters outside of the BMP (Basic
262-
Multilingual Plane) will not validate correctly.
263-
264254
Normalization
265255
-------------
266256

@@ -407,6 +397,17 @@ or likely to cause trouble:
407397
IP address in brackets) is rejected. Other obsolete and deprecated syntaxes are
408398
rejected. No one uses these forms anymore.
409399

400+
Support for Python 2.x
401+
----------------------
402+
403+
The last version of this library supporting Python 2.x is version 1.2.1.
404+
405+
When using Python 2.x, it is required that Python be built with
406+
UCS-4 support (see
407+
[here](https://stackoverflow.com/questions/29109944/python-returns-length-of-2-for-single-unicode-character-string)).
408+
Without UCS-4 support, unicode characters outside of the BMP (Basic
409+
Multilingual Plane) will not validate correctly in internationalized addresses.
410+
410411
Testing
411412
-------
412413

email_validator/__main__.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,24 @@
1717
from .exceptions_types import EmailNotValidError
1818

1919

20-
def __utf8_input_shim(input_str):
21-
if sys.version_info < (3,):
22-
return input_str.decode("utf-8")
23-
return input_str
24-
25-
26-
def __utf8_output_shim(output_str):
27-
if sys.version_info < (3,):
28-
return unicode_class(output_str).encode("utf-8")
29-
return output_str
30-
31-
3220
def main():
3321
if len(sys.argv) == 1:
3422
# Validate the email addresses pased line-by-line on STDIN.
3523
dns_resolver = caching_resolver()
3624
for line in sys.stdin:
37-
email = __utf8_input_shim(line.strip())
25+
email = line.strip()
3826
try:
3927
validate_email(email, dns_resolver=dns_resolver)
4028
except EmailNotValidError as e:
41-
print(__utf8_output_shim("{} {}".format(email, e)))
29+
print("{} {}".format(email, e))
4230
else:
4331
# Validate the email address passed on the command line.
44-
email = __utf8_input_shim(sys.argv[1])
32+
email = sys.argv[1]
4533
try:
4634
result = validate_email(email)
4735
print(json.dumps(result.as_dict(), indent=2, sort_keys=True, ensure_ascii=False))
4836
except EmailNotValidError as e:
49-
print(__utf8_output_shim(e))
37+
print(e)
5038

5139

5240
if __name__ == "__main__":

email_validator/rfc_constants.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
# These constants are defined by the email specifications.
42

53
# Based on RFC 2822 section 3.2.4 / RFC 5322 section 3.2.3, these
@@ -29,11 +27,3 @@
2927
EMAIL_MAX_LENGTH = 254
3028
LOCAL_PART_MAX_LENGTH = 64
3129
DOMAIN_MAX_LENGTH = 255
32-
33-
34-
# In Python 2.x, turn the regexes above from bytes regexes into unicode
35-
# regexes. If Python 3.x had a "ur" string literal prefix we'd use that instead.
36-
if sys.version_info < (3,):
37-
ATEXT = ATEXT.decode("ascii")
38-
DOT_ATOM_TEXT = DOT_ATOM_TEXT.decode("ascii")
39-
ATEXT_HOSTNAME = ATEXT_HOSTNAME.decode("ascii")

email_validator/validate_email.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import sys
2-
31
from .exceptions_types import EmailSyntaxError, ValidatedEmail
42
from .syntax import validate_email_local_part, validate_email_domain_part, get_length_reason
53
from .deliverability import validate_email_deliverability
64
from .rfc_constants import EMAIL_MAX_LENGTH
75

8-
# ease compatibility in type checking
9-
if sys.version_info >= (3,):
10-
unicode_class = str
11-
else:
12-
unicode_class = unicode # noqa: F821
13-
146

157
def validate_email(
168
email,
@@ -46,7 +38,7 @@ def validate_email(
4638
# Allow email to be a str or bytes instance. If bytes,
4739
# it must be ASCII because that's how the bytes work
4840
# on the wire with SMTP.
49-
if not isinstance(email, (str, unicode_class)):
41+
if not isinstance(email, str):
5042
try:
5143
email = email.decode("ascii")
5244
except ValueError:

tests/test_main.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -591,31 +591,6 @@ def test_main_multi_input(monkeypatch, capsys):
591591
assert test_cases[3] in stdout
592592

593593

594-
def test_main_input_shim(monkeypatch, capsys):
595-
import json
596-
monkeypatch.setattr('sys.version_info', (2, 7))
597-
test_email = b"google@google.com"
598-
monkeypatch.setattr('sys.argv', ['email_validator', test_email])
599-
validator_command_line_tool()
600-
stdout, _ = capsys.readouterr()
601-
output = json.loads(str(stdout))
602-
assert isinstance(output, dict)
603-
assert validate_email(test_email).original_email == output["original_email"]
604-
605-
606-
def test_main_output_shim(monkeypatch, capsys):
607-
monkeypatch.setattr('sys.version_info', (2, 7))
608-
test_email = b"test@.com"
609-
monkeypatch.setattr('sys.argv', ['email_validator', test_email])
610-
validator_command_line_tool()
611-
stdout, _ = capsys.readouterr()
612-
613-
# This looks bad but it has to do with the way python 2.7 prints vs py3
614-
# The \n is part of the print statement, not part of the string, which is what the b'...' is
615-
# Since we're mocking py 2.7 here instead of actually using 2.7, this was the closest I could get
616-
assert stdout == "b'An email address cannot have a period immediately after the @-sign.'\n"
617-
618-
619594
def test_validate_email__with_caching_resolver():
620595
# unittest.mock.patch("dns.resolver.LRUCache.get") doesn't
621596
# work --- it causes get to always return an empty list.

0 commit comments

Comments
 (0)