How to use the idna.IDNAError function in idna

To help you get started, we’ve selected a few idna examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Tautulli / Tautulli / lib / requests / models.py View on Github external
def _get_idna_encoded_host(host):
        import idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
github thisismyrobot / dnstwister / dnstwister / dnstwist / dnstwist.py View on Github external
def is_valid_domain(domain):
    """Validate a domain - including unicode domains."""
    try:
        if len(domain) > 255:
            return False

        encoded_domain = idna.encode(domain)
        if domain != encoded_domain and len(domain) == encoded_domain:
            return False

        return VALID_DOMAIN_RE.match(encoded_domain) is not None
    except (UnicodeError, TypeError, idna.IDNAError):
        pass
    return False
github rthalley / dnspython / dns / name.py View on Github external
def decode(self, label):
        if not self.strict_decode:
            return super(IDNA2008Codec, self).decode(label)
        if label == b'':
            return ''
        if not have_idna_2008:
            raise NoIDNA2008
        try:
            if self.uts_46:
                label = idna.uts46_remap(label, False, False)
            return _escapify(idna.ulabel(label))
        except idna.IDNAError as e:
            raise IDNAException(idna_exception=e)
github commoncrawl / cc-pyspark / wat_extract_links.py View on Github external
# trailing dot is allowed, strip it
            parts = parts[0:-1]
        if len(parts) <= 1:
            # do not accept single-word hosts, must be at least `domain.tld'
            return None
        if len(parts) > 2 and parts[0] == 'www':
            # strip leading 'www' to reduce number of "duplicate" hosts,
            # but leave at least 2 trailing parts (www.com is a valid domain)
            parts = parts[1:]
        for (i, part) in enumerate(parts):
            if len(part) > 63:
                return None
            if not ExtractHostLinksJob.host_part_pattern.match(part):
                try:
                    idn = idna.encode(part).decode('ascii')
                except (idna.IDNAError, UnicodeError, IndexError, Exception):
                    # self.get_logger().debug("Invalid host name: {}".format(url))
                    return None

                if ExtractHostLinksJob.host_part_pattern.match(idn):
                    parts[i] = idn
                else:
                    # self.get_logger().debug("Invalid host name: {}".format(url))
                    return None
        parts.reverse()
        return '.'.join(parts)
github google / crmint / cli / patches / lib / requests / models.py View on Github external
def _get_idna_encoded_host(host):
        import idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
github LukeMurphey / splunk-website-monitoring / src / bin / website_monitoring_app / requests / models.py View on Github external
def _get_idna_encoded_host(host):
        try:
            from .packages import idna
        except ImportError:
            # tolerate the possibility of downstream repackagers unvendoring `requests`
            # For more information, read: packages/__init__.py
            import idna
            sys.modules['requests.packages.idna'] = idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
github rembo10 / headphones / lib / urllib3 / util / url.py View on Github external
def idna_encode(name):
        if name and any([ord(x) > 128 for x in name]):
            try:
                import idna
            except ImportError:
                raise LocationParseError("Unable to parse URL without the 'idna' module")
            try:
                return idna.encode(name.lower(), strict=True, std3_rules=True)
            except idna.IDNAError:
                raise LocationParseError(u"Name '%s' is not a valid IDNA label" % name)
        return name
github ColdGrub1384 / Pyto / site-packages / requests / models.py View on Github external
def _get_idna_encoded_host(host):
        import idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host
github Twoure / KissNetwork.bundle / Contents / Libraries / Shared / requests / models.py View on Github external
def _get_idna_encoded_host(host):
        try:
            from .packages import idna
        except ImportError:
            # tolerate the possibility of downstream repackagers unvendoring `requests`
            # For more information, read: packages/__init__.py
            import idna
            sys.modules['requests.packages.idna'] = idna

        try:
            host = idna.encode(host, uts46=True).decode('utf-8')
        except idna.IDNAError:
            raise UnicodeError
        return host