mirror of
https://github.com/aljazceru/validate_email.git
synced 2025-12-20 15:34:24 +01:00
Updated to Python 3.
In order to preserve compatibility with Python 2, raw_input was preserved.
This commit is contained in:
@@ -22,6 +22,12 @@ import smtplib
|
|||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
try:
|
||||||
|
raw_input
|
||||||
|
except NameError:
|
||||||
|
def raw_input(prompt=''):
|
||||||
|
return input(prompt)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import DNS
|
import DNS
|
||||||
ServerError = DNS.ServerError
|
ServerError = DNS.ServerError
|
||||||
@@ -94,7 +100,7 @@ def get_mx_ip(hostname):
|
|||||||
if hostname not in MX_DNS_CACHE:
|
if hostname not in MX_DNS_CACHE:
|
||||||
try:
|
try:
|
||||||
MX_DNS_CACHE[hostname] = DNS.mxlookup(hostname)
|
MX_DNS_CACHE[hostname] = DNS.mxlookup(hostname)
|
||||||
except ServerError, e:
|
except ServerError as e:
|
||||||
if e.rcode == 3: # NXDOMAIN (Non-Existent Domain)
|
if e.rcode == 3: # NXDOMAIN (Non-Existent Domain)
|
||||||
MX_DNS_CACHE[hostname] = None
|
MX_DNS_CACHE[hostname] = None
|
||||||
else:
|
else:
|
||||||
@@ -191,11 +197,11 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
result = validate_email(email, mx, validate, debug=True, smtp_timeout=1)
|
result = validate_email(email, mx, validate, debug=True, smtp_timeout=1)
|
||||||
if result:
|
if result:
|
||||||
print "Valid!"
|
print("Valid!")
|
||||||
elif result is None:
|
elif result is None:
|
||||||
print "I'm not sure."
|
print("I'm not sure.")
|
||||||
else:
|
else:
|
||||||
print "Invalid!"
|
print("Invalid!")
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user