Python idna.IDNAError() Examples
The following are 30
code examples of idna.IDNAError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
idna
, or try the search function
.
Example #1
Source File: url.py From CudaText with Mozilla Public License 2.0 | 6 votes |
def _idna_encode(name): if name and any([ord(x) > 128 for x in name]): try: import idna except ImportError: six.raise_from( LocationParseError("Unable to parse URL without the 'idna' module"), None, ) try: return idna.encode(name.lower(), strict=True, std3_rules=True) except idna.IDNAError: six.raise_from( LocationParseError(u"Name '%s' is not a valid IDNA label" % name), None ) return name.lower().encode("ascii")
Example #2
Source File: utils.py From web3.py with MIT License | 6 votes |
def normalize_name(name: str) -> str: """ Clean the fully qualified name, as defined in ENS `EIP-137 <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-137.md#name-syntax>`_ This does *not* enforce whether ``name`` is a label or fully qualified domain. :param str name: the dot-separated ENS name :raises InvalidName: if ``name`` has invalid syntax """ if not name: return name elif isinstance(name, (bytes, bytearray)): name = name.decode('utf-8') try: return idna.uts46_remap(name, std3_rules=True) except idna.IDNAError as exc: raise InvalidName(f"{name} is an invalid name, because {exc}") from exc
Example #3
Source File: url.py From Cloudmare with GNU General Public License v3.0 | 6 votes |
def _idna_encode(name): if name and any([ord(x) > 128 for x in name]): try: import idna except ImportError: six.raise_from( LocationParseError("Unable to parse URL without the 'idna' module"), None, ) try: return idna.encode(name.lower(), strict=True, std3_rules=True) except idna.IDNAError: six.raise_from( LocationParseError(u"Name '%s' is not a valid IDNA label" % name), None ) return name.lower().encode("ascii")
Example #4
Source File: url.py From cronyo with MIT License | 6 votes |
def _idna_encode(name): if name and any([ord(x) > 128 for x in name]): try: import idna except ImportError: six.raise_from( LocationParseError("Unable to parse URL without the 'idna' module"), None, ) try: return idna.encode(name.lower(), strict=True, std3_rules=True) except idna.IDNAError: six.raise_from( LocationParseError(u"Name '%s' is not a valid IDNA label" % name), None ) return name.lower().encode("ascii")
Example #5
Source File: url.py From pipenv with MIT License | 6 votes |
def _idna_encode(name): if name and any([ord(x) > 128 for x in name]): try: import idna except ImportError: six.raise_from( LocationParseError("Unable to parse URL without the 'idna' module"), None, ) try: return idna.encode(name.lower(), strict=True, std3_rules=True) except idna.IDNAError: six.raise_from( LocationParseError(u"Name '%s' is not a valid IDNA label" % name), None ) return name.lower().encode("ascii")
Example #6
Source File: url.py From chinese-support-redux with GNU General Public License v3.0 | 6 votes |
def _idna_encode(name): if name and any([ord(x) > 128 for x in name]): try: import idna except ImportError: six.raise_from( LocationParseError("Unable to parse URL without the 'idna' module"), None, ) try: return idna.encode(name.lower(), strict=True, std3_rules=True) except idna.IDNAError: six.raise_from( LocationParseError(u"Name '%s' is not a valid IDNA label" % name), None ) return name.lower().encode("ascii")
Example #7
Source File: url.py From CudaText with Mozilla Public License 2.0 | 6 votes |
def _idna_encode(name): if name and any([ord(x) > 128 for x in name]): try: import idna except ImportError: six.raise_from( LocationParseError("Unable to parse URL without the 'idna' module"), None, ) try: return idna.encode(name.lower(), strict=True, std3_rules=True) except idna.IDNAError: six.raise_from( LocationParseError(u"Name '%s' is not a valid IDNA label" % name), None ) return name.lower().encode("ascii")
Example #8
Source File: utils.py From django-ca with GNU General Public License v3.0 | 6 votes |
def validate_email(addr): """Validate an email address. This function raises ``ValueError`` if the email address is not valid. >>> validate_email('foo@bar.com') 'foo@bar.com' >>> validate_email('foo@bar com') Traceback (most recent call last): ... ValueError: Invalid domain: bar com """ if '@' not in addr: raise ValueError('Invalid email address: %s' % addr) node, domain = addr.split('@', 1) try: domain = idna.encode(force_text(domain)) except idna.core.IDNAError: raise ValueError('Invalid domain: %s' % domain) return '%s@%s' % (node, force_text(domain))
Example #9
Source File: url.py From quickstart-redhat-openshift with Apache License 2.0 | 6 votes |
def _idna_encode(name): if name and any([ord(x) > 128 for x in name]): try: import idna except ImportError: six.raise_from( LocationParseError("Unable to parse URL without the 'idna' module"), None, ) try: return idna.encode(name.lower(), strict=True, std3_rules=True) except idna.IDNAError: six.raise_from( LocationParseError(u"Name '%s' is not a valid IDNA label" % name), None ) return name.lower().encode("ascii")
Example #10
Source File: url.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def _idna_encode(name): if name and any([ord(x) > 128 for x in name]): try: import idna except ImportError: six.raise_from( LocationParseError("Unable to parse URL without the 'idna' module"), None, ) try: return idna.encode(name.lower(), strict=True, std3_rules=True) except idna.IDNAError: six.raise_from( LocationParseError(u"Name '%s' is not a valid IDNA label" % name), None ) return name.lower().encode("ascii")
Example #11
Source File: url.py From luci-py with Apache License 2.0 | 6 votes |
def _idna_encode(name): if name and any([ord(x) > 128 for x in name]): try: import idna except ImportError: six.raise_from( LocationParseError("Unable to parse URL without the 'idna' module"), None, ) try: return idna.encode(name.lower(), strict=True, std3_rules=True) except idna.IDNAError: six.raise_from( LocationParseError(u"Name '%s' is not a valid IDNA label" % name), None ) return name.lower().encode("ascii")
Example #12
Source File: url.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def _idna_encode(name): if name and any([ord(x) > 128 for x in name]): try: import idna except ImportError: six.raise_from( LocationParseError("Unable to parse URL without the 'idna' module"), None, ) try: return idna.encode(name.lower(), strict=True, std3_rules=True) except idna.IDNAError: six.raise_from( LocationParseError(u"Name '%s' is not a valid IDNA label" % name), None ) return name.lower().encode("ascii")
Example #13
Source File: models.py From bazarr with GNU General Public License v3.0 | 5 votes |
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
Example #14
Source File: models.py From pyRevit with GNU General Public License v3.0 | 5 votes |
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
Example #15
Source File: name.py From bazarr with GNU General Public License v3.0 | 5 votes |
def decode(self, label): if not self.strict_decode: return super(IDNA2008Codec, self).decode(label) if label == b'': return u'' if not have_idna_2008: raise NoIDNA2008 try: if self.uts_46: label = idna.uts46_remap(label, False, False) return _escapify(idna.ulabel(label), True) except idna.IDNAError as e: raise IDNAException(idna_exception=e)
Example #16
Source File: models.py From sumologic-content with Apache License 2.0 | 5 votes |
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
Example #17
Source File: models.py From lambda-text-extractor with Apache License 2.0 | 5 votes |
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
Example #18
Source File: models.py From quickstart-redhat-openshift with Apache License 2.0 | 5 votes |
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
Example #19
Source File: models.py From open-ledger with MIT License | 5 votes |
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
Example #20
Source File: models.py From lambda-text-extractor with Apache License 2.0 | 5 votes |
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
Example #21
Source File: models.py From komodo-wakatime with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #22
Source File: models.py From ZEROScan with MIT License | 5 votes |
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
Example #23
Source File: models.py From Ansible with MIT License | 5 votes |
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
Example #24
Source File: name.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def encode(self, label): if label == '': return b'' if self.allow_pure_ascii and self.is_all_ascii(label): return label.encode('ascii') if not have_idna_2008: raise NoIDNA2008 try: if self.uts_46: label = idna.uts46_remap(label, False, self.transitional) return idna.alabel(label) except idna.IDNAError as e: raise IDNAException(idna_exception=e)
Example #25
Source File: models.py From CudaText with Mozilla Public License 2.0 | 5 votes |
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
Example #26
Source File: models.py From CudaText with Mozilla Public License 2.0 | 5 votes |
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
Example #27
Source File: profiles.py From django-ca with GNU General Public License v3.0 | 5 votes |
def _update_san_from_cn(self, cn_in_san, subject, extensions): if subject.get('CN') and cn_in_san is True: try: cn = parse_general_name(subject['CN']) except idna.IDNAError: raise ValueError('%s: Could not parse CommonName as subjectAlternativeName.' % subject['CN']) extensions.setdefault(SubjectAlternativeName.key, SubjectAlternativeName()) if cn not in extensions[SubjectAlternativeName.key]: extensions[SubjectAlternativeName.key].append(cn) elif not subject.get('CN') and SubjectAlternativeName.key in extensions: cn = extensions[SubjectAlternativeName.key].get_common_name() if cn is not None: subject['CN'] = cn
Example #28
Source File: models.py From googletranslate.popclipext with MIT License | 5 votes |
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
Example #29
Source File: models.py From luci-py with Apache License 2.0 | 5 votes |
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
Example #30
Source File: models.py From Requester with MIT License | 5 votes |
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