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


Python socket.EAI_NONAME属性代码示例

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


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

示例1: is_valid_ip

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def is_valid_ip(ip):
    """Returns true if the given string is a well-formed IP address.

    Supports IPv4 and IPv6.
    """
    if not ip or '\x00' in ip:
        # getaddrinfo resolves empty strings to localhost, and truncates
        # on zero bytes.
        return False
    try:
        res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC,
                                 socket.SOCK_STREAM,
                                 0, socket.AI_NUMERICHOST)
        return bool(res)
    except socket.gaierror as e:
        if e.args[0] == socket.EAI_NONAME:
            return False
        raise
    return True 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:21,代码来源:netutil.py

示例2: is_valid_ip

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def is_valid_ip(ip):
    """Returns true if the given string is a well-formed IP address.

    Supports IPv4 and IPv6.
    //取自 tornado
    """
    if not ip or '\x00' in ip:
        # getaddrinfo resolves empty strings to localhost, and truncates
        # on zero bytes.
        return False
    try:
        res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC,
                                 socket.SOCK_STREAM,
                                 0, socket.AI_NUMERICHOST)
        return bool(res)
    except socket.gaierror as e:
        if e.args[0] == socket.EAI_NONAME:
            return False
        raise
    return True 
开发者ID:alexsunday,项目名称:pyvpn,代码行数:22,代码来源:util.py

示例3: is_valid_ip

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def is_valid_ip(ip: str) -> bool:
    """Returns ``True`` if the given string is a well-formed IP address.

    Supports IPv4 and IPv6.
    """
    if not ip or "\x00" in ip:
        # getaddrinfo resolves empty strings to localhost, and truncates
        # on zero bytes.
        return False
    try:
        res = socket.getaddrinfo(
            ip, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST
        )
        return bool(res)
    except socket.gaierror as e:
        if e.args[0] == socket.EAI_NONAME:
            return False
        raise
    return True 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:21,代码来源:netutil.py

示例4: is_valid_address

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def is_valid_address(address):
    """ check ip address, Supports IPv4 and IPv6"""

    if not address or '\x00' in address:
        return False

    try:
        res = socket.getaddrinfo(address, 0, socket.AF_UNSPEC,
                                 socket.SOCK_STREAM,
                                 0, socket.AI_NUMERICHOST)
        return bool(res)
    except socket.gaierror:
        err = sys.exc_info()[1]
        if err.args[0] == socket.EAI_NONAME:
            return False
        raise
    return True 
开发者ID:HuaweiSwitch,项目名称:CloudEngine-Ansible,代码行数:19,代码来源:ce_info_center_global.py

示例5: check_ip_addr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def check_ip_addr(**kwargs):
    """ check_ip_addr, Supports IPv4 and IPv6"""

    ipaddr = kwargs["ipaddr"]

    if not ipaddr or '\x00' in ipaddr:
        return False

    try:
        res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
                                 socket.SOCK_STREAM,
                                 0, socket.AI_NUMERICHOST)
        return bool(res)
    except socket.gaierror:
        err = sys.exc_info()[1]
        if err.args[0] == socket.EAI_NONAME:
            return False
        raise
    return True 
开发者ID:HuaweiSwitch,项目名称:CloudEngine-Ansible,代码行数:21,代码来源:ce_bgp_af.py

示例6: check_ip_addr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def check_ip_addr(ipaddr):
    """check ip address, Supports IPv4 and IPv6"""

    if not ipaddr or '\x00' in ipaddr:
        return False

    try:
        res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
                                 socket.SOCK_STREAM,
                                 0, socket.AI_NUMERICHOST)
        return bool(res)
    except socket.gaierror:
        err = sys.exc_info()[1]
        if err.args[0] == socket.EAI_NONAME:
            return False
        raise

    return True 
开发者ID:HuaweiSwitch,项目名称:CloudEngine-Ansible,代码行数:20,代码来源:ce_bfd_session.py

示例7: check_ip_addr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def check_ip_addr(ipaddr):
    """ check_ip_addr, Supports IPv4 and IPv6 """

    if not ipaddr or '\x00' in ipaddr:
        return False

    try:
        res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
                                 socket.SOCK_STREAM,
                                 0, socket.AI_NUMERICHOST)
        return bool(res)
    except socket.gaierror:
        err = sys.exc_info()[1]
        if err.args[0] == socket.EAI_NONAME:
            return False
        raise
    return True 
开发者ID:HuaweiSwitch,项目名称:CloudEngine-Ansible,代码行数:19,代码来源:ce_aaa_server_host.py

示例8: check_ip_addr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def check_ip_addr(**kwargs):
    """ check_ip_addr, Supports IPv4 and IPv6 """

    ipaddr = kwargs["ipaddr"]

    if not ipaddr or '\x00' in ipaddr:
        return False

    try:
        res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
                                 socket.SOCK_STREAM,
                                 0, socket.AI_NUMERICHOST)
        return bool(res)
    except socket.gaierror:
        err = sys.exc_info()[1]
        if err.args[0] == socket.EAI_NONAME:
            return False
        raise
    return True 
开发者ID:HuaweiSwitch,项目名称:CloudEngine-Ansible,代码行数:21,代码来源:ce_bgp_neighbor_af.py

示例9: check_ip_addr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def check_ip_addr(ipaddr):
    """check ip address, Supports IPv4 and IPv6"""

    if not ipaddr or '\x00' in ipaddr:
        return False

    try:
        res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
                                 socket.SOCK_STREAM,
                                 0, socket.AI_NUMERICHOST)
        return bool(res)
    except socket.gaierror:
        err = sys.exc_info()[1]
        if err.args[0] == socket.EAI_NONAME:
            return False
        raise 
开发者ID:HuaweiSwitch,项目名称:CloudEngine-Ansible,代码行数:18,代码来源:ce_bfd_global.py

示例10: check_ip_addr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def check_ip_addr(ipaddr):
    """ check ip address, Supports IPv4 and IPv6 """

    if not ipaddr or '\x00' in ipaddr:
        return False

    try:
        res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
                                 socket.SOCK_STREAM,
                                 0, socket.AI_NUMERICHOST)
        return bool(res)
    except socket.gaierror:
        err = sys.exc_info()[1]
        if err.args[0] == socket.EAI_NONAME:
            return False
        raise
    return True 
开发者ID:HuaweiSwitch,项目名称:CloudEngine-Ansible,代码行数:19,代码来源:ce_acl_advance.py

示例11: is_valid_ip_bysocket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def is_valid_ip_bysocket(ip):
    if not ip or '\x00' in ip:
        # getaddrinfo resolves empty strings to localhost, and truncates
        # on zero bytes.
        return False
    try:
        res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC,
                                 socket.SOCK_STREAM,
                                 0, socket.AI_NUMERICHOST)
        return bool(res)
    except socket.gaierror as e:
        if e.args[0] == socket.EAI_NONAME:
            return False
        raise 
开发者ID:qunarcorp,项目名称:open_dnsdb,代码行数:16,代码来源:utils.py

示例12: is_valid_ip

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def is_valid_ip(ip):
    """Returns true if the given string is a well-formed IP address.

    Supports IPv4 and IPv6.
    """
    try:
        res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC,
                                 socket.SOCK_STREAM,
                                 0, socket.AI_NUMERICHOST)
        return bool(res)
    except socket.gaierror as e:
        if e.args[0] == socket.EAI_NONAME:
            return False
        raise
    return True 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:17,代码来源:netutil.py

示例13: test_resolveNumericHost

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def test_resolveNumericHost(self):
        """
        L{_resolveIPv6} raises a L{socket.gaierror} (L{socket.EAI_NONAME}) when
        invoked with a non-numeric host.  (In other words, it is passing
        L{socket.AI_NUMERICHOST} to L{socket.getaddrinfo} and will not
        accidentally block if it receives bad input.)
        """
        err = self.assertRaises(socket.gaierror, _resolveIPv6, "localhost", 1)
        self.assertEqual(err.args[0], socket.EAI_NONAME) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:test_tcp.py

示例14: test_resolveNumericService

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def test_resolveNumericService(self):
        """
        L{_resolveIPv6} raises a L{socket.gaierror} (L{socket.EAI_NONAME}) when
        invoked with a non-numeric port.  (In other words, it is passing
        L{socket.AI_NUMERICSERV} to L{socket.getaddrinfo} and will not
        accidentally block if it receives bad input.)
        """
        err = self.assertRaises(socket.gaierror, _resolveIPv6, "::1", "http")
        self.assertEqual(err.args[0], socket.EAI_NONAME) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:test_tcp.py

示例15: _valid_ip

# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_NONAME [as 别名]
def _valid_ip(self, ip):
        try:
            res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC,
                                     socket.SOCK_STREAM,
                                     0, socket.AI_NUMERICHOST)
            return bool(res)
        except socket.gaierror, e:
            if e.args[0] == socket.EAI_NONAME:
                return False
            raise 
开发者ID:omererdem,项目名称:honeything,代码行数:12,代码来源:httpserver.py


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