當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。