本文整理匯總了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