MCPcopy Index your code
hub / github.com/python/cpython / domain_match

Function domain_match

Lib/http/cookiejar.py:551–588  ·  view source on GitHub ↗

Return True if domain A domain-matches domain B, according to RFC 2965. A and B may be host domain names or IP addresses. RFC 2965, section 1: Host names can be specified either as an IP address or a HDN string. Sometimes we compare one host name with another. (Such comparisons S

(A, B)

Source from the content-addressed store, hash-verified

549 return True
550
551def domain_match(A, B):
552 """Return True if domain A domain-matches domain B, according to RFC 2965.
553
554 A and B may be host domain names or IP addresses.
555
556 RFC 2965, section 1:
557
558 Host names can be specified either as an IP address or a HDN string.
559 Sometimes we compare one host name with another. (Such comparisons SHALL
560 be case-insensitive.) Host A's name domain-matches host B's if
561
562 * their host name strings string-compare equal; or
563
564 * A is a HDN string and has the form NB, where N is a non-empty
565 name string, B has the form .B', and B' is a HDN string. (So,
566 x.y.com domain-matches .Y.com but not Y.com.)
567
568 Note that domain-match is not a commutative operation: a.b.c.com
569 domain-matches .c.com, but not the reverse.
570
571 """
572 # Note that, if A or B are IP addresses, the only relevant part of the
573 # definition of the domain-match algorithm is the direct string-compare.
574 A = A.lower()
575 B = B.lower()
576 if A == B:
577 return True
578 if not is_HDN(A):
579 return False
580 i = A.rfind(B)
581 if i == -1 or i == 0:
582 # A does not have form NB, or N is the empty string
583 return False
584 if not B.startswith("."):
585 return False
586 if not is_HDN(B[1:]):
587 return False
588 return True
589
590def liberal_is_HDN(text):
591 """Return True if text is a sort-of-like a host domain name.

Callers 4

test_domain_matchMethod · 0.90
is_third_partyFunction · 0.85
set_ok_domainMethod · 0.85
return_ok_domainMethod · 0.85

Calls 4

is_HDNFunction · 0.85
lowerMethod · 0.45
rfindMethod · 0.45
startswithMethod · 0.45

Tested by 1

test_domain_matchMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…