当前位置: 首页>>代码示例>>Python>>正文


Python idna.decode方法代码示例

本文整理汇总了Python中idna.decode方法的典型用法代码示例。如果您正苦于以下问题:Python idna.decode方法的具体用法?Python idna.decode怎么用?Python idna.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在idna的用法示例。


在下文中一共展示了idna.decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _cache_tlds

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def _cache_tlds(self, tlds):
        '''Logs a diff of the new TLDs and caches them on disk, according to
        settings passed to __init__.'''
        if LOG.isEnabledFor(logging.DEBUG):
            import difflib
            snapshot_stream = pkg_resources.resource_stream(__name__, '.tld_set_snapshot')
            with closing(snapshot_stream) as snapshot_file:
                snapshot = sorted(
                    json.loads(snapshot_file.read().decode('utf-8'))
                )
            new = sorted(tlds)
            LOG.debug('computed TLD diff:\n' + '\n'.join(difflib.unified_diff(
                snapshot,
                new,
                fromfile=".tld_set_snapshot",
                tofile=self.cache_file
            )))

        if self.cache_file:
            try:
                with open(self.cache_file, 'w') as cache_file:
                    json.dump(tlds, cache_file)
            except IOError as ioe:
                LOG.warn("unable to cache TLDs in file %s: %s", self.cache_file, ioe) 
开发者ID:abaykan,项目名称:CrawlBox,代码行数:26,代码来源:tldextract.py

示例2: _idnaText

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def _idnaText(octets):
    """
    Convert some IDNA-encoded octets into some human-readable text.

    Currently only used by the tests.

    @param octets: Some bytes representing a hostname.
    @type octets: L{bytes}

    @return: A human-readable domain name.
    @rtype: L{unicode}
    """
    try:
        import idna
    except ImportError:
        return octets.decode("idna")
    else:
        return idna.decode(octets) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:_idna.py

示例3: host

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def host(self):
        """Decoded host part of URL.

        None for relative URLs.

        """
        raw = self.raw_host
        if raw is None:
            return None
        if "%" in raw:
            # Hack for scoped IPv6 addresses like
            # fe80::2%Проверка
            # presence of '%' sign means only IPv6 address, so idna is useless.
            return raw
        try:
            return idna.decode(raw.encode("ascii"))
        except UnicodeError:  # e.g. '::1'
            return raw.encode("ascii").decode("idna") 
开发者ID:aio-libs,项目名称:yarl,代码行数:20,代码来源:__init__.py

示例4: _encode_host

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def _encode_host(cls, host):
            try:
                ip, sep, zone = host.partition("%")
                ip = ip_address(ip)
            except ValueError:
                # IDNA encoding is slow,
                # skip it for ASCII-only strings
                if host.isascii():
                    return host
                try:
                    host = idna.encode(host, uts46=True).decode("ascii")
                except UnicodeError:
                    host = host.encode("idna").decode("ascii")
            else:
                host = ip.compressed
                if sep:
                    host += "%" + zone
                if ip.version == 6:
                    host = "[" + host + "]"
            return host 
开发者ID:aio-libs,项目名称:yarl,代码行数:22,代码来源:__init__.py

示例5: host

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def host(self):
        """Decoded host part of URL.

        None for relative URLs.

        """
        raw = self.raw_host
        if raw is None:
            return None
        if "%" in raw:
            # Hack for scoped IPv6 addresses like
            # fe80::2%Проверка
            # presence of '%' sign means only IPv6 address, so idna is useless.
            return raw

        try:
            return idna.decode(raw.encode("ascii"))
        except UnicodeError:  # e.g. '::1'
            return raw.encode("ascii").decode("idna") 
开发者ID:TouwaStar,项目名称:Galaxy_Plugin_Bethesda,代码行数:21,代码来源:__init__.py

示例6: _encode_host

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def _encode_host(cls, host):
        try:
            ip, sep, zone = host.partition("%")
            ip = ip_address(ip)
        except ValueError:
            try:
                host = idna.encode(host, uts46=True).decode("ascii")
            except UnicodeError:
                host = host.encode("idna").decode("ascii")
        else:
            host = ip.compressed
            if sep:
                host += "%" + zone
            if ip.version == 6:
                host = "[" + host + "]"
        return host 
开发者ID:TouwaStar,项目名称:Galaxy_Plugin_Bethesda,代码行数:18,代码来源:__init__.py

示例7: _get_snapshot_tld_extractor

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def _get_snapshot_tld_extractor():
        snapshot_stream = pkg_resources.resource_stream(__name__, '.tld_set_snapshot')
        with closing(snapshot_stream) as snapshot_file:
            return json.loads(snapshot_file.read().decode('utf-8')) 
开发者ID:abaykan,项目名称:CrawlBox,代码行数:6,代码来源:tldextract.py

示例8: _obj2txt

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def _obj2txt(backend, obj):
    # Set to 80 on the recommendation of
    # https://www.openssl.org/docs/crypto/OBJ_nid2ln.html#return_values
    buf_len = 80
    buf = backend._ffi.new("char[]", buf_len)
    res = backend._lib.OBJ_obj2txt(buf, buf_len, obj, 1)
    backend.openssl_assert(res > 0)
    return backend._ffi.buffer(buf, res)[:].decode() 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:10,代码来源:x509.py

示例9: _decode_certificate_policies

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def _decode_certificate_policies(backend, cp):
    cp = backend._ffi.cast("Cryptography_STACK_OF_POLICYINFO *", cp)
    cp = backend._ffi.gc(cp, backend._lib.sk_POLICYINFO_free)
    num = backend._lib.sk_POLICYINFO_num(cp)
    certificate_policies = []
    for i in range(num):
        qualifiers = None
        pi = backend._lib.sk_POLICYINFO_value(cp, i)
        oid = x509.ObjectIdentifier(_obj2txt(backend, pi.policyid))
        if pi.qualifiers != backend._ffi.NULL:
            qnum = backend._lib.sk_POLICYQUALINFO_num(pi.qualifiers)
            qualifiers = []
            for j in range(qnum):
                pqi = backend._lib.sk_POLICYQUALINFO_value(
                    pi.qualifiers, j
                )
                pqualid = x509.ObjectIdentifier(
                    _obj2txt(backend, pqi.pqualid)
                )
                if pqualid == CertificatePoliciesOID.CPS_QUALIFIER:
                    cpsuri = backend._ffi.buffer(
                        pqi.d.cpsuri.data, pqi.d.cpsuri.length
                    )[:].decode('ascii')
                    qualifiers.append(cpsuri)
                else:
                    assert pqualid == CertificatePoliciesOID.CPS_USER_NOTICE
                    user_notice = _decode_user_notice(
                        backend, pqi.d.usernotice
                    )
                    qualifiers.append(user_notice)

        certificate_policies.append(
            x509.PolicyInformation(oid, qualifiers)
        )

    return x509.CertificatePolicies(certificate_policies) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:38,代码来源:x509.py

示例10: _decode_invalidity_date

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def _decode_invalidity_date(backend, inv_date):
    generalized_time = backend._ffi.cast(
        "ASN1_GENERALIZEDTIME *", inv_date
    )
    generalized_time = backend._ffi.gc(
        generalized_time, backend._lib.ASN1_GENERALIZEDTIME_free
    )
    time = backend._ffi.string(
        backend._lib.ASN1_STRING_data(
            backend._ffi.cast("ASN1_STRING *", generalized_time)
        )
    ).decode("ascii")
    return datetime.datetime.strptime(time, "%Y%m%d%H%M%SZ") 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:15,代码来源:x509.py

示例11: _lift_parse_result

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
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 
开发者ID:duo-labs,项目名称:isthislegit,代码行数:16,代码来源:address.py

示例12: _lift_parse_list_result

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def _lift_parse_list_result(parse_list_rs):
    addr_list_obj = AddressList()
    bad_list = []
    for parse_rs in parse_list_rs:
        addr_obj = _lift_parse_result(parse_rs)
        if not addr_obj:
            if isinstance(parse_rs, Mailbox):
                bad_list.append(u'%s@%s' % (parse_rs.local_part.decode('utf-8'),
                                            parse_rs.domain.decode('utf-8')))
            continue

        addr_list_obj.append(addr_obj)

    return addr_list_obj, bad_list 
开发者ID:duo-labs,项目名称:isthislegit,代码行数:16,代码来源:address.py

示例13: _asn1_string_to_ascii

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def _asn1_string_to_ascii(backend, asn1_string):
    return _asn1_string_to_bytes(backend, asn1_string).decode("ascii") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:4,代码来源:decode_asn1.py

示例14: _asn1_string_to_utf8

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def _asn1_string_to_utf8(backend, asn1_string):
    buf = backend._ffi.new("unsigned char **")
    res = backend._lib.ASN1_STRING_to_UTF8(buf, asn1_string)
    if res == -1:
        raise ValueError(
            "Unsupported ASN1 string type. Type: {0}".format(asn1_string.type)
        )

    backend.openssl_assert(buf[0] != backend._ffi.NULL)
    buf = backend._ffi.gc(
        buf, lambda buffer: backend._lib.OPENSSL_free(buffer[0])
    )
    return backend._ffi.buffer(buf[0], res)[:].decode('utf8') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:decode_asn1.py

示例15: _load_cached_tlds

# 需要导入模块: import idna [as 别名]
# 或者: from idna import decode [as 别名]
def _load_cached_tlds(self):
        """
        Loads TLDs from cached file to set.

        :return: Set of current TLDs
        :rtype: set
        """

        # check if cached file is readable
        if not os.access(self._tld_list_path, os.R_OK):
            self._logger.error("Cached file is not readable for current "
                               "user. ({})".format(self._tld_list_path))
            raise CacheFileError(
                "Cached file is not readable for current user."
            )

        set_of_tlds = set()

        with filelock.FileLock(self._get_cache_lock_file_path()):
            with open(self._tld_list_path, 'r') as f_cache_tld:
                for line in f_cache_tld:
                    tld = line.strip().lower()
                    # skip empty lines
                    if not tld:
                        continue
                    # skip comments
                    if tld[0] == '#':
                        continue

                    set_of_tlds.add("." + tld)
                    set_of_tlds.add("." + idna.decode(tld))

        return set_of_tlds 
开发者ID:lipoja,项目名称:URLExtract,代码行数:35,代码来源:cachefile.py


注:本文中的idna.decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。