def _dnsname_match(dn, hostname, max_wildcards=<NUM_LIT:1>):
pats = []<EOL>if not dn:<EOL><INDENT>return False<EOL><DEDENT>parts = dn.split(r'<STR_LIT:.>')<EOL>leftmost = parts[<NUM_LIT:0>]<EOL>remainder = parts[<NUM_LIT:1>:]<EOL>wildcards = leftmost.count('<STR_LIT:*>')<EOL>if wildcards > max_wildcards:<EOL><INDENT>raise CertificateError(<EOL>"<STR_LIT>" + repr(dn))<EOL><DEDENT>if not wildcards:<EOL><INDENT>return dn.lower() == hostname.lower()<EOL><DEDENT>if leftmost == '<STR_LIT:*>':<EOL><INDENT>pats.append('<STR_LIT>')<EOL><DEDENT>elif leftmost.startswith('<STR_LIT>') or hostname.startswith('<STR_LIT>'):<EOL><INDENT>pats.append(re.escape(leftmost))<EOL><DEDENT>else:<EOL><INDENT>pats.append(re.escape(leftmost).replace(r'<STR_LIT>', '<STR_LIT>'))<EOL><DEDENT>for frag in remainder:<EOL><INDENT>pats.append(re.escape(frag))<EOL><DEDENT>pat = re.compile(r'<STR_LIT>' + r'<STR_LIT>'.join(pats) + r'<STR_LIT>', re.IGNORECASE)<EOL>return pat.match(hostname)<EOL>
Matching according to RFC 6125, section 6.4.3

    http://tools.ietf.org/html/rfc6125#section-6.4.3