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)
| 549 | return True |
| 550 | |
| 551 | def 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 | |
| 590 | def liberal_is_HDN(text): |
| 591 | """Return True if text is a sort-of-like a host domain name. |
searching dependent graphs…