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