Python idna.IDNAError() Examples
The following are 30 code examples for showing how to use idna.IDNAError(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
idna
, or try the search function
.
Example 1
Project: misp42splunk Author: remg427 File: url.py License: 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 2
Project: misp42splunk Author: remg427 File: url.py License: 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 3
Project: chinese-support-redux Author: luoliyan File: url.py License: 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
Project: pipenv Author: pypa File: url.py License: 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
Project: cronyo Author: cronyo File: url.py License: 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
Project: luci-py Author: luci File: url.py License: 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 7
Project: django-ca Author: mathiasertl File: utils.py License: 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 8
Project: CudaText Author: Alexey-T File: url.py License: 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 9
Project: CudaText Author: Alexey-T File: url.py License: 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 10
Project: web3.py Author: ethereum File: utils.py License: 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 11
Project: Cloudmare Author: MrH0wl File: url.py License: 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 12
Project: quickstart-redhat-openshift Author: aws-quickstart File: url.py License: 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 13
Project: gist-alfred Author: danielecook File: models.py License: 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 14
Project: misp42splunk Author: remg427 File: models.py License: GNU Lesser 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 15
Project: misp42splunk Author: remg427 File: models.py License: GNU Lesser 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 16
Project: misp42splunk Author: remg427 File: models.py License: GNU Lesser 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 17
Project: core Author: getavalon File: models.py License: 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 18
Project: ServerlessCrawler-VancouverRealState Author: MarcelloLins File: models.py License: 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 19
Project: ServerlessCrawler-VancouverRealState Author: MarcelloLins File: models.py License: 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 20
Project: ServerlessCrawler-VancouverRealState Author: MarcelloLins File: models.py License: 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 21
Project: faces Author: skarlekar File: models.py License: GNU General Public License v2.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 22
Project: vnpy_crypto Author: birforce File: models.py License: 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 23
Project: wow-addon-updater Author: kuhnertdm File: models.py License: 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 24
Project: isthislegit Author: duo-labs File: address.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def ace_address(self): if not is_pure_ascii(self.mailbox): raise ValueError('address {} has no ASCII-compatable encoding' .format(self.address.encode('utf-8'))) ace_hostname = self.hostname if not is_pure_ascii(self.hostname): try: ace_hostname = idna.encode(self.hostname) except idna.IDNAError: raise ValueError('address {} has no ASCII-compatable encoding' .format(self.address.encode('utf-8'))) return '{}@{}'.format(self.mailbox, ace_hostname)
Example 25
Project: isthislegit Author: duo-labs File: address.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def requires_non_ascii(self): """ Can the address be converted to an ASCII compatible encoding? """ if not is_pure_ascii(self.mailbox): return True if not is_pure_ascii(self.hostname): try: idna.encode(self.hostname) except idna.IDNAError: return True return False
Example 26
Project: isthislegit Author: duo-labs File: address.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def _lift_parse_result(parse_rs): if isinstance(parse_rs, Mailbox): try: return EmailAddress( display_name=smart_unquote(parse_rs.display_name.decode('utf-8')), mailbox=parse_rs.local_part.decode('utf-8'), hostname=parse_rs.domain.decode('utf-8')) except (UnicodeError, IDNAError): return None if isinstance(parse_rs, Url): return UrlAddress(address=parse_rs.address.decode('utf-8')) return None
Example 27
Project: anpr Author: italia File: models.py License: Creative Commons Attribution 4.0 International | 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 28
Project: deepWordBug Author: QData File: models.py License: 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 29
Project: pipenv Author: pypa File: models.py License: 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 30
Project: quickstart-taskcat-ci Author: aws-quickstart File: models.py License: 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