def idna_encode(name): """ Borrowed wholesale from the Python Cryptography Project. It turns out that we can't just safely call `idna.encode`: it can explode for wildcard names. This avoids that problem. """ from pip._vendor import idna try: for prefix in [u"*.", u"."]: if name.startswith(prefix): name = name[len(prefix):] return prefix.encode("ascii") + idna.encode(name) return idna.encode(name) except idna.core.IDNAError: return None
def idna_encode(name): """ Borrowed wholesale from the Python Cryptography Project. It turns out that we can't just safely call `idna.encode`: it can explode for wildcard names. This avoids that problem. """ from pip._vendor import idna for prefix in [u'*.', u'.']: if name.startswith(prefix): name = name[len(prefix):] return prefix.encode('ascii') + idna.encode(name) return idna.encode(name)
def _idna_encode(name): if name and any([ord(x) > 128 for x in name]): try: from pip._vendor 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")
def _get_idna_encoded_host(host): from pip._vendor import idna try: host = idna.encode(host, uts46=True).decode('utf-8') except idna.IDNAError: raise UnicodeError return host
def idna_encoder(name): if any(ord(c) > 128 for c in name): try: return idna.encode(name.lower(), strict=True, std3_rules=True) except idna.IDNAError: raise exceptions.InvalidAuthority(self.authority) return name
======= >>>>>>> 71358189c5e72ee2ac9883b408a2f540a7f5745e def idna_encode(name): """ Borrowed wholesale from the Python Cryptography Project. It turns out that we can't just safely call `idna.encode`: it can explode for wildcard names. This avoids that problem. """ from pip._vendor import idna try: <<<<<<< HEAD for prefix in [u"*.", u"."]: if name.startswith(prefix): name = name[len(prefix) :] return prefix.encode("ascii") + idna.encode(name) ======= for prefix in [u'*.', u'.']: if name.startswith(prefix): name = name[len(prefix):] return prefix.encode('ascii') + idna.encode(name) >>>>>>> 71358189c5e72ee2ac9883b408a2f540a7f5745e return idna.encode(name) except idna.core.IDNAError: return None <<<<<<< HEAD # Don't send IPv6 addresses through the IDNA encoder. if ":" in name: return name