(dn, hostname)
return dn_remainder.lower() == hostname_remainder.lower()
Matching according to RFC 6125, section 6.4.3

    - Hostnames are compared lower case.
    - For IDNA, both dn and hostname must be encoded as IDN A-label (ACE).
    - Partial wildcards like 'www*.example.org', multiple wildcards, sole
      wildcard or wildcards in labels other then the left-most label are not
      supported and a CertificateError is raised.
    - A wildcard must match at least one character.
Matching according to RFC 6125, section 6.4.3
Matching according to RFC 6125 section 6 . 4 . 3
def _dnsname_match(dn, hostname):
    """Matching according to RFC 6125, section 6.4.3

    - Hostnames are compared lower case.
    - For IDNA, both dn and hostname must be encoded as IDN A-label (ACE).
    - Partial wildcards like 'www*.example.org', multiple wildcards, sole
      wildcard or wildcards in labels other then the left-most label are not
      supported and a CertificateError is raised.
    - A wildcard must match at least one character.
    """
    if not dn:
        return False

    wildcards = dn.count('*')
    # speed up common case w/o wildcards
    if not wildcards:
        return dn.lower() == hostname.lower()

    if wildcards > 1:
        raise CertificateError(
            "too many wildcards in certificate DNS name: {!r}.".format(dn))

    dn_leftmost, sep, dn_remainder = dn.partition('.')

    if '*' in dn_remainder:
        # Only match wildcard in leftmost segment.
        raise CertificateError(
            "wildcard can only be present in the leftmost label: "
            "{!r}.".format(dn))

    if not sep:
        # no right side
        raise CertificateError(
            "sole wildcard without additional labels are not support: "
            "{!r}.".format(dn))

    if dn_leftmost != '*':
        # no partial wildcard matching
        raise CertificateError(
            "partial wildcards in leftmost label are not supported: "
            "{!r}.".format(dn))

    hostname_leftmost, sep, hostname_remainder = hostname.partition('.')
    if not hostname_leftmost or not sep:
        # wildcard must match at least one char
        return False
    return dn_remainder.lower() == hostname_remainder.lower()
def _dnsname_match ( dn , hostname ) : if not dn : return False wildcards = dn . count ( '*' ) # speed up common case w/o wildcards if not wildcards : return dn . lower ( ) == hostname . lower ( ) if wildcards > 1 : raise CertificateError ( "too many wildcards in certificate DNS name: {!r}." . format ( dn ) ) dn_leftmost , sep , dn_remainder = dn . partition ( '.' ) if '*' in dn_remainder : # Only match wildcard in leftmost segment. raise CertificateError ( "wildcard can only be present in the leftmost label: " "{!r}." . format ( dn ) ) if not sep : # no right side raise CertificateError ( "sole wildcard without additional labels are not support: " "{!r}." . format ( dn ) ) if dn_leftmost != '*' : # no partial wildcard matching raise CertificateError ( "partial wildcards in leftmost label are not supported: " "{!r}." . format ( dn ) ) hostname_leftmost , sep , hostname_remainder = hostname . partition ( '.' ) if not hostname_leftmost or not sep : # wildcard must match at least one char return False return dn_remainder . lower ( ) == hostname_remainder . lower ( )