Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/email_validator/__init__.py: 84%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

19 statements  

1from typing import TYPE_CHECKING 

2 

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 

7from .version import __version__ 

8 

9__all__ = ["validate_email", 

10 "ValidatedEmail", "EmailNotValidError", 

11 "EmailSyntaxError", "EmailUndeliverableError", 

12 "caching_resolver", "__version__"] 

13 

14if TYPE_CHECKING: 

15 from .deliverability import caching_resolver 

16else: 

17 def caching_resolver(*args, **kwargs): 

18 # Lazy load `deliverability` as it is slow to import (due to dns.resolver) 

19 from .deliverability import caching_resolver 

20 

21 return caching_resolver(*args, **kwargs) 

22 

23 

24# These global attributes are a part of the library's API and can be 

25# changed by library users. 

26 

27# Default values for keyword arguments. 

28 

29ALLOW_SMTPUTF8 = True 

30ALLOW_QUOTED_LOCAL = False 

31ALLOW_DOMAIN_LITERAL = False 

32ALLOW_DISPLAY_NAME = False 

33GLOBALLY_DELIVERABLE = True 

34CHECK_DELIVERABILITY = True 

35TEST_ENVIRONMENT = False 

36DEFAULT_TIMEOUT = 15 # secs 

37 

38# IANA Special Use Domain Names 

39# Last Updated 2021-09-21 

40# https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.txt 

41# 

42# The domain names without dots would be caught by the check that the domain 

43# name in an email address must have a period, but this list will also catch 

44# subdomains of these domains, which are also reserved. 

45SPECIAL_USE_DOMAIN_NAMES = [ 

46 # The "arpa" entry here is consolidated from a lot of arpa subdomains 

47 # for private address (i.e. non-routable IP addresses like 172.16.x.x) 

48 # reverse mapping, plus some other subdomains. Although RFC 6761 says 

49 # that application software should not treat these domains as special, 

50 # they are private-use domains and so cannot have globally deliverable 

51 # email addresses, which is an assumption of this library, and probably 

52 # all of arpa is similarly special-use, so we reject it all. 

53 "arpa", 

54 

55 # RFC 6761 says applications "SHOULD NOT" treat the "example" domains 

56 # as special, i.e. applications should accept these domains. 

57 # 

58 # The domain "example" alone fails our syntax validation because it 

59 # lacks a dot (we assume no one has an email address on a TLD directly). 

60 # "@example.com/net/org" will currently fail DNS-based deliverability 

61 # checks because IANA publishes a NULL MX for these domains, and 

62 # "@mail.example[.com/net/org]" and other subdomains will fail DNS- 

63 # based deliverability checks because IANA does not publish MX or A 

64 # DNS records for these subdomains. 

65 # "example", # i.e. "wwww.example" 

66 # "example.com", 

67 # "example.net", 

68 # "example.org", 

69 

70 # RFC 6761 says that applications are permitted to treat this domain 

71 # as special and that DNS should return an immediate negative response, 

72 # so we also immediately reject this domain, which also follows the 

73 # purpose of the domain. 

74 "invalid", 

75 

76 # RFC 6762 says that applications "may" treat ".local" as special and 

77 # that "name resolution APIs and libraries SHOULD recognize these names 

78 # as special," and since ".local" has no global definition, we reject 

79 # it, as we expect email addresses to be gloally routable. 

80 "local", 

81 

82 # RFC 6761 says that applications (like this library) are permitted 

83 # to treat "localhost" as special, and since it cannot have a globally 

84 # deliverable email address, we reject it. 

85 "localhost", 

86 

87 # RFC 7686 says "applications that do not implement the Tor protocol 

88 # SHOULD generate an error upon the use of .onion and SHOULD NOT 

89 # perform a DNS lookup. 

90 "onion", 

91 

92 # Although RFC 6761 says that application software should not treat 

93 # these domains as special, it also warns users that the address may 

94 # resolve differently in different systems, and therefore it cannot 

95 # have a globally routable email address, which is an assumption of 

96 # this library, so we reject "@test" and "@*.test" addresses, unless 

97 # the test_environment keyword argument is given, to allow their use 

98 # in application-level test environments. These domains will generally 

99 # fail deliverability checks because "test" is not an actual TLD. 

100 "test", 

101]