

def _dnsname_to_pat(dn, max_wildcards=1):
    pats = []
    for frag in dn.split('.'):
        if (frag.count('*') > max_wildcards):
            raise CertificateError(('too many wildcards in certificate DNS name: ' + repr(dn)))
        if (frag == '*'):
            pats.append('[^.]+')
        else:
            frag = re.escape(frag)
            pats.append(frag.replace('\\*', '[^.]*'))
    return re.compile((('\\A' + '\\.'.join(pats)) + '\\Z'), re.IGNORECASE)

dataset/ETHPy150Open blynch/CloudMemeBackend/pymongo/ssl_match_hostname.py _dnsname_to_pat/original