當前位置: 首頁>>代碼示例>>Python>>正文


Python idna.encode方法代碼示例

本文整理匯總了Python中pip._vendor.idna.encode方法的典型用法代碼示例。如果您正苦於以下問題:Python idna.encode方法的具體用法?Python idna.encode怎麽用?Python idna.encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pip._vendor.idna的用法示例。


在下文中一共展示了idna.encode方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _encode_params

# 需要導入模塊: from pip._vendor import idna [as 別名]
# 或者: from pip._vendor.idna import encode [as 別名]
def _encode_params(data):
        """Encode parameters in a piece of data.

        Will successfully encode parameters when passed as a dict or a list of
        2-tuples. Order is retained if data is a list of 2-tuples but arbitrary
        if parameters are supplied as a dict.
        """

        if isinstance(data, (str, bytes)):
            return data
        elif hasattr(data, 'read'):
            return data
        elif hasattr(data, '__iter__'):
            result = []
            for k, vs in to_key_val_list(data):
                if isinstance(vs, basestring) or not hasattr(vs, '__iter__'):
                    vs = [vs]
                for v in vs:
                    if v is not None:
                        result.append(
                            (k.encode('utf-8') if isinstance(k, str) else k,
                             v.encode('utf-8') if isinstance(v, str) else v))
            return urlencode(result, doseq=True)
        else:
            return data 
開發者ID:HaoZhang95,項目名稱:Python24,代碼行數:27,代碼來源:models.py

示例2: wrap_socket

# 需要導入模塊: from pip._vendor import idna [as 別名]
# 或者: from pip._vendor.idna import encode [as 別名]
def wrap_socket(self, sock, server_side=False,
                    do_handshake_on_connect=True, suppress_ragged_eofs=True,
                    server_hostname=None):
        cnx = OpenSSL.SSL.Connection(self._ctx, sock)

        if isinstance(server_hostname, six.text_type):  # Platform-specific: Python 3
            server_hostname = server_hostname.encode('utf-8')

        if server_hostname is not None:
            cnx.set_tlsext_host_name(server_hostname)

        cnx.set_connect_state()

        while True:
            try:
                cnx.do_handshake()
            except OpenSSL.SSL.WantReadError:
                if not util.wait_for_read(sock, sock.gettimeout()):
                    raise timeout('select timed out')
                continue
            except OpenSSL.SSL.Error as e:
                raise ssl.SSLError('bad handshake: %r' % e)
            break

        return WrappedSocket(cnx, sock) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:27,代碼來源:pyopenssl.py

示例3: _idna_encode

# 需要導入模塊: from pip._vendor import idna [as 別名]
# 或者: from pip._vendor.idna import encode [as 別名]
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") 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:18,代碼來源:url.py

示例4: _dnsname_to_stdlib

# 需要導入模塊: from pip._vendor import idna [as 別名]
# 或者: from pip._vendor.idna import encode [as 別名]
def _dnsname_to_stdlib(name):
    """
    Converts a dNSName SubjectAlternativeName field to the form used by the
    standard library on the given Python version.

    Cryptography produces a dNSName as a unicode string that was idna-decoded
    from ASCII bytes. We need to idna-encode that string to get it back, and
    then on Python 3 we also need to convert to unicode via UTF-8 (the stdlib
    uses PyUnicode_FromStringAndSize on it, which decodes via UTF-8).
    """
    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)

    name = idna_encode(name)
    if sys.version_info >= (3, 0):
        name = name.decode('utf-8')
    return name 
開發者ID:HaoZhang95,項目名稱:Python24,代碼行數:30,代碼來源:pyopenssl.py

示例5: set_ciphers

# 需要導入模塊: from pip._vendor import idna [as 別名]
# 或者: from pip._vendor.idna import encode [as 別名]
def set_ciphers(self, ciphers):
        if isinstance(ciphers, six.text_type):
            ciphers = ciphers.encode('utf-8')
        self._ctx.set_cipher_list(ciphers) 
開發者ID:HaoZhang95,項目名稱:Python24,代碼行數:6,代碼來源:pyopenssl.py

示例6: load_verify_locations

# 需要導入模塊: from pip._vendor import idna [as 別名]
# 或者: from pip._vendor.idna import encode [as 別名]
def load_verify_locations(self, cafile=None, capath=None, cadata=None):
        if cafile is not None:
            cafile = cafile.encode('utf-8')
        if capath is not None:
            capath = capath.encode('utf-8')
        self._ctx.load_verify_locations(cafile, capath)
        if cadata is not None:
            self._ctx.load_verify_locations(BytesIO(cadata)) 
開發者ID:HaoZhang95,項目名稱:Python24,代碼行數:10,代碼來源:pyopenssl.py

示例7: wrap_socket

# 需要導入模塊: from pip._vendor import idna [as 別名]
# 或者: from pip._vendor.idna import encode [as 別名]
def wrap_socket(self, sock, server_side=False,
                    do_handshake_on_connect=True, suppress_ragged_eofs=True,
                    server_hostname=None):
        cnx = OpenSSL.SSL.Connection(self._ctx, sock)

        if isinstance(server_hostname, six.text_type):  # Platform-specific: Python 3
            server_hostname = server_hostname.encode('utf-8')

        if server_hostname is not None:
            cnx.set_tlsext_host_name(server_hostname)

        cnx.set_connect_state()

        while True:
            try:
                cnx.do_handshake()
            except OpenSSL.SSL.WantReadError:
                rd = util.wait_for_read(sock, sock.gettimeout())
                if not rd:
                    raise timeout('select timed out')
                continue
            except OpenSSL.SSL.Error as e:
                raise ssl.SSLError('bad handshake: %r' % e)
            break

        return WrappedSocket(cnx, sock) 
開發者ID:HaoZhang95,項目名稱:Python24,代碼行數:28,代碼來源:pyopenssl.py

示例8: _get_idna_encoded_host

# 需要導入模塊: from pip._vendor import idna [as 別名]
# 或者: from pip._vendor.idna import encode [as 別名]
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 
開發者ID:HaoZhang95,項目名稱:Python24,代碼行數:10,代碼來源:models.py


注:本文中的pip._vendor.idna.encode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。