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