コード例 #1
0
def ascii_to_idn(host):
    '''convert ACE (ASCII-compatible encoding) to IDN
	(Internationalized Domain Names)'''
    labels = idna.dots.split(host)
    converted_labels = []
    for label in labels:
        converted_labels.append(idna.ToUnicode(label))
    return ".".join(converted_labels)
コード例 #2
0
ファイル: deceptiveidn.py プロジェクト: shangadi/deceptiveidn
def idn_to_unicode(s):
    rv = []
    for part in s.split('.'):
        if part.startswith('xn--'):
            rv.append(idna.ToUnicode(part))
        else:
            rv.append(part)

    return '.'.join(rv)
コード例 #3
0
    def norm(self, valu, oldval=None):
        valu = valu.replace('[.]', '.')
        if not fqdnre.match(valu):
            self._raiseBadValu(valu)
        if valu.startswith('xn--'):
            valu = idna.ToUnicode(valu)
        valu = valu.lower()

        parts = valu.split('.', 1)
        subs = {'host': parts[0]}
        if len(parts) == 2:
            subs['domain'] = parts[1]
        else:
            subs['sfx'] = 1
        return valu, subs
コード例 #4
0
def _parse_labels(string):
    try:
        # Note: idna.ToASCII also enforces the minimum and maximum label length.
        labels = tuple(idna.ToASCII(x).lower() for x in string.split(u"."))
    except UnicodeError:
        return None

    if len(labels) + sum(len(x) for x in labels) > 253:
        return None

    if labels[-1].isdigit():
        return None
    if not all(_LABEL_REX.match(x) for x in labels):
        return None

    return tuple(idna.ToUnicode(x) for x in labels)
コード例 #5
0
def mightDecode(s):
    if s[:4] == "xn--":
        return idna.ToUnicode(s)
    return s
コード例 #6
0
ファイル: __init__.py プロジェクト: brandonscott1780/luci-py
def decode(host):
    # Used by cryptography/hazmat/backends/openssl/x509.py
    return idna.ToUnicode(host)