本文整理汇总了Python中socket.AI_V4MAPPED属性的典型用法代码示例。如果您正苦于以下问题:Python socket.AI_V4MAPPED属性的具体用法?Python socket.AI_V4MAPPED怎么用?Python socket.AI_V4MAPPED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类socket
的用法示例。
在下文中一共展示了socket.AI_V4MAPPED属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: address_info
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_V4MAPPED [as 别名]
def address_info(self):
conf_refresh_interval = get_config_parameter('ADDRESS_INFO_REFRESH_TIME')
if not self._address_info or (datetime.now() - self._address_info_resolved_time).seconds > conf_refresh_interval:
# converts addresses tuple to list and adds a 6th parameter for availability (None = not checked, True = available, False=not available) and a 7th parameter for the checking time
addresses = None
try:
if self.ipc:
addresses = [(socket.AF_UNIX, socket.SOCK_STREAM, 0, None, self.host, None)]
else:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED)
except (socket.gaierror, AttributeError):
pass
if not addresses: # if addresses not found or raised an exception (for example for bad flags) tries again without flags
try:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP)
except socket.gaierror:
pass
if addresses:
self._address_info = [list(address) + [None, None] for address in addresses]
self._address_info_resolved_time = datetime.now()
else:
self._address_info = []
self._address_info_resolved_time = datetime(MINYEAR, 1, 1) # smallest date
if log_enabled(BASIC):
for address in self._address_info:
log(BASIC, 'address for <%s> resolved as <%r>', self, address[:-2])
return self._address_info
示例2: address_info
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_V4MAPPED [as 别名]
def address_info(self):
conf_refresh_interval = get_config_parameter('ADDRESS_INFO_REFRESH_TIME')
if not self._address_info or (datetime.now() - self._address_info_resolved_time).seconds > conf_refresh_interval:
# converts addresses tuple to list and adds a 6th parameter for availability (None = not checked, True = available, False=not available) and a 7th parameter for the checking time
addresses = None
try:
if self.ipc:
addresses = [(socket.AF_UNIX, socket.SOCK_STREAM, 0, None, self.host, None)]
else:
if self.mode == IP_V4_ONLY:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED)
elif self.mode == IP_V6_ONLY:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED)
else:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED)
except (socket.gaierror, AttributeError):
pass
if not addresses: # if addresses not found or raised an exception (for example for bad flags) tries again without flags
try:
if self.mode == IP_V4_ONLY:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
elif self.mode == IP_V6_ONLY:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_TCP)
else:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP)
except socket.gaierror:
pass
if addresses:
self._address_info = [list(address) + [None, None] for address in addresses]
self._address_info_resolved_time = datetime.now()
else:
self._address_info = []
self._address_info_resolved_time = datetime(MINYEAR, 1, 1) # smallest date
if log_enabled(BASIC):
for address in self._address_info:
log(BASIC, 'address for <%s> resolved as <%r>', self, address[:-2])
return self._address_info
示例3: getconnectionsbyendpointname
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_V4MAPPED [as 别名]
def getconnectionsbyendpointname(self, name, vhost = '', timeout = 30):
"Get connection by endpoint name (Domain name, IP or IPv6 address)"
# Resolve the name
if not name:
endpoint = ''
return await self.getconnectionbyendpoint(endpoint, vhost)
else:
request = (name, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED)
# Resolve hostname
await self.apiroutine.wait_for_send(ResolveRequestEvent(request))
timeout_, ev, m = await self.apiroutine.wait_with_timeout(timeout, ResolveResponseEvent.createMatcher(request))
if timeout_:
# Resolve is only allowed through asynchronous resolver
#try:
# self.addrinfo = socket.getaddrinfo(self.hostname, self.port, socket.AF_UNSPEC, socket.SOCK_DGRAM if self.udp else socket.SOCK_STREAM, socket.IPPROTO_UDP if self.udp else socket.IPPROTO_TCP, socket.AI_ADDRCONFIG|socket.AI_NUMERICHOST)
#except:
raise IOError('Resolve hostname timeout: ' + name)
else:
if hasattr(ev, 'error'):
raise IOError('Cannot resolve hostname: ' + name)
resp = ev.response
for r in resp:
raddr = r[4]
if isinstance(raddr, tuple):
# Ignore port
endpoint = raddr[0]
else:
# Unix socket? This should not happen, but in case...
endpoint = raddr
r = await self.getconnectionsbyendpoint(endpoint, vhost)
if r is not None:
return r
return None
示例4: getconnectionsbyendpointname
# 需要导入模块: import socket [as 别名]
# 或者: from socket import AI_V4MAPPED [as 别名]
def getconnectionsbyendpointname(self, name, vhost = '', timeout = 30):
"Get connection by endpoint name (Domain name, IP or IPv6 address)"
# Resolve the name
if not name:
endpoint = ''
return await self.getconnectionbyendpoint(endpoint, vhost)
else:
request = (name, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED)
# Resolve hostname
await self.apiroutine.wait_for_send(ResolveRequestEvent(request))
timeout_, ev, _ = await self.apiroutine.wait_with_timeout(timeout, ResolveResponseEvent.createMatcher(request))
if timeout_:
# Resolve is only allowed through asynchronous resolver
#try:
# self.addrinfo = socket.getaddrinfo(self.hostname, self.port, socket.AF_UNSPEC, socket.SOCK_DGRAM if self.udp else socket.SOCK_STREAM, socket.IPPROTO_UDP if self.udp else socket.IPPROTO_TCP, socket.AI_ADDRCONFIG|socket.AI_NUMERICHOST)
#except:
raise IOError('Resolve hostname timeout: ' + name)
else:
if hasattr(ev, 'error'):
raise IOError('Cannot resolve hostname: ' + name)
resp = ev.response
for r in resp:
raddr = r[4]
if isinstance(raddr, tuple):
# Ignore port
endpoint = raddr[0]
else:
# Unix socket? This should not happen, but in case...
endpoint = raddr
r = await self.getconnectionsbyendpoint(endpoint, vhost)
if r is not None:
return r