Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/email_validator/__init__.py: 86%
14 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:32 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:32 +0000
1# -*- coding: utf-8 -*-
3# Export the main method, helper methods, and the public data types.
4from .exceptions_types import ValidatedEmail, EmailNotValidError, \
5 EmailSyntaxError, EmailUndeliverableError
6from .validate_email import validate_email
9__all__ = ["validate_email",
10 "ValidatedEmail", "EmailNotValidError",
11 "EmailSyntaxError", "EmailUndeliverableError",
12 "caching_resolver"]
15def caching_resolver(*args, **kwargs):
16 # Lazy load `deliverability` as it is slow to import (due to dns.resolver)
17 from .deliverability import caching_resolver
19 return caching_resolver(*args, **kwargs)
22# These global attributes are a part of the library's API and can be
23# changed by library users.
25# Default values for keyword arguments.
27ALLOW_SMTPUTF8 = True
28ALLOW_QUOTED_LOCAL = False
29ALLOW_DOMAIN_LITERAL = False
30GLOBALLY_DELIVERABLE = True
31CHECK_DELIVERABILITY = True
32TEST_ENVIRONMENT = False
33DEFAULT_TIMEOUT = 15 # secs
35# IANA Special Use Domain Names
36# Last Updated 2021-09-21
37# https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.txt
38#
39# The domain names without dots would be caught by the check that the domain
40# name in an email address must have a period, but this list will also catch
41# subdomains of these domains, which are also reserved.
42SPECIAL_USE_DOMAIN_NAMES = [
43 # The "arpa" entry here is consolidated from a lot of arpa subdomains
44 # for private address (i.e. non-routable IP addresses like 172.16.x.x)
45 # reverse mapping, plus some other subdomains. Although RFC 6761 says
46 # that application software should not treat these domains as special,
47 # they are private-use domains and so cannot have globally deliverable
48 # email addresses, which is an assumption of this library, and probably
49 # all of arpa is similarly special-use, so we reject it all.
50 "arpa",
52 # RFC 6761 says applications "SHOULD NOT" treat the "example" domains
53 # as special, i.e. applications should accept these domains.
54 #
55 # The domain "example" alone fails our syntax validation because it
56 # lacks a dot (we assume no one has an email address on a TLD directly).
57 # "@example.com/net/org" will currently fail DNS-based deliverability
58 # checks because IANA publishes a NULL MX for these domains, and
59 # "@mail.example[.com/net/org]" and other subdomains will fail DNS-
60 # based deliverability checks because IANA does not publish MX or A
61 # DNS records for these subdomains.
62 # "example", # i.e. "wwww.example"
63 # "example.com",
64 # "example.net",
65 # "example.org",
67 # RFC 6761 says that applications are permitted to treat this domain
68 # as special and that DNS should return an immediate negative response,
69 # so we also immediately reject this domain, which also follows the
70 # purpose of the domain.
71 "invalid",
73 # RFC 6762 says that applications "may" treat ".local" as special and
74 # that "name resolution APIs and libraries SHOULD recognize these names
75 # as special," and since ".local" has no global definition, we reject
76 # it, as we expect email addresses to be gloally routable.
77 "local",
79 # RFC 6761 says that applications (like this library) are permitted
80 # to treat "localhost" as special, and since it cannot have a globally
81 # deliverable email address, we reject it.
82 "localhost",
84 # RFC 7686 says "applications that do not implement the Tor protocol
85 # SHOULD generate an error upon the use of .onion and SHOULD NOT
86 # perform a DNS lookup.
87 "onion",
89 # Although RFC 6761 says that application software should not treat
90 # these domains as special, it also warns users that the address may
91 # resolve differently in different systems, and therefore it cannot
92 # have a globally routable email address, which is an assumption of
93 # this library, so we reject "@test" and "@*.test" addresses, unless
94 # the test_environment keyword argument is given, to allow their use
95 # in application-level test environments. These domains will generally
96 # fail deliverability checks because "test" is not an actual TLD.
97 "test",
98]