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


Python idna.IDNAError方法代码示例

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


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

示例1: _idna_encode

# 需要导入模块: import idna [as 别名]
# 或者: from idna import IDNAError [as 别名]
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") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:18,代码来源:url.py

示例2: validate_email

# 需要导入模块: import idna [as 别名]
# 或者: from idna import IDNAError [as 别名]
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)) 
开发者ID:mathiasertl,项目名称:django-ca,代码行数:25,代码来源:utils.py

示例3: normalize_name

# 需要导入模块: import idna [as 别名]
# 或者: from idna import IDNAError [as 别名]
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 
开发者ID:ethereum,项目名称:web3.py,代码行数:21,代码来源:utils.py

示例4: _get_idna_encoded_host

# 需要导入模块: import idna [as 别名]
# 或者: from idna import IDNAError [as 别名]
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 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:10,代码来源:models.py

示例5: _get_idna_encoded_host

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

示例6: ace_address

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

示例7: requires_non_ascii

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

示例8: _lift_parse_result

# 需要导入模块: import idna [as 别名]
# 或者: from idna import IDNAError [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


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