本文整理汇总了Python中socket.EAI_ADDRFAMILY属性的典型用法代码示例。如果您正苦于以下问题:Python socket.EAI_ADDRFAMILY属性的具体用法?Python socket.EAI_ADDRFAMILY怎么用?Python socket.EAI_ADDRFAMILY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类socket
的用法示例。
在下文中一共展示了socket.EAI_ADDRFAMILY属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ipv6
# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_ADDRFAMILY [as 别名]
def test_ipv6(self):
try:
[sock] = bind_sockets(None, '::1', family=socket.AF_INET6)
port = sock.getsockname()[1]
self.http_server.add_socket(sock)
except socket.gaierror as e:
if e.args[0] == socket.EAI_ADDRFAMILY:
# python supports ipv6, but it's not configured on the network
# interface, so skip this test.
return
raise
url = '%s://[::1]:%d/hello' % (self.get_protocol(), port)
# ipv6 is currently enabled by default but can be disabled
self.http_client.fetch(url, self.stop, allow_ipv6=False)
response = self.wait()
self.assertEqual(response.code, 599)
self.http_client.fetch(url, self.stop)
response = self.wait()
self.assertEqual(response.body, b"Hello world!")
示例2: test_ipv6
# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_ADDRFAMILY [as 别名]
def test_ipv6(self):
try:
self.http_server.listen(self.get_http_port(), address='::1')
except socket.gaierror as e:
if e.args[0] == socket.EAI_ADDRFAMILY:
# python supports ipv6, but it's not configured on the network
# interface, so skip this test.
return
raise
url = self.get_url("/hello").replace("localhost", "[::1]")
# ipv6 is currently disabled by default and must be explicitly requested
self.http_client.fetch(url, self.stop)
response = self.wait()
self.assertEqual(response.code, 599)
self.http_client.fetch(url, self.stop, allow_ipv6=True)
response = self.wait()
self.assertEqual(response.body, b"Hello world!")
示例3: test_ipv6
# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_ADDRFAMILY [as 别名]
def test_ipv6(self):
if not socket.has_ipv6:
# python compiled without ipv6 support, so skip this test
return
try:
self.http_server.listen(self.get_http_port(), address='::1')
except socket.gaierror, e:
if e.args[0] == socket.EAI_ADDRFAMILY:
# python supports ipv6, but it's not configured on the network
# interface, so skip this test.
return
raise
示例4: _gen_addresses_where_possible
# 需要导入模块: import socket [as 别名]
# 或者: from socket import EAI_ADDRFAMILY [as 别名]
def _gen_addresses_where_possible(hostname):
"""Yield IPv4 and IPv6 addresses for `hostname`.
A variant of `_gen_addresses` that ignores some resolution failures. The
addresses returned are only those that are resolvable at the time this
function is called. Specifically the following errors are ignored:
+----------------+-----------------------------------------------+
| EAI_ADDRFAMILY | The specified network host does not have any |
| | network addresses in the requested address |
| | family. |
+----------------+-----------------------------------------------+
| EAI_AGAIN | The name server returned a temporary failure |
| | indication. Try again later. |
+----------------+-----------------------------------------------+
| EAI_FAIL | The name server returned a permanent failure |
| | indication. |
+----------------+-----------------------------------------------+
| EAI_NODATA | The specified network host exists, but does |
| | not have any network addresses defined. |
+----------------+-----------------------------------------------+
| EAI_NONAME | The node or service is not known; or both node|
| | and service are NULL; or AI_NUMERICSERV was |
| | specified and service was not a numeric |
| | port-number string. |
+----------------+-----------------------------------------------+
Descriptions from getaddrinfo(3).
"""
try:
yield from _gen_addresses(hostname)
except socket.gaierror as error:
if error.errno in _gen_addresses_where_possible_suppress:
# Log this but otherwise suppress/ignore for now.
logger.warning("Could not resolve %s: %s", hostname, error)
else:
raise