Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_getnameinfo(self):
self.result, self.errorno = None, None
def cb(result, errorno):
self.result, self.errorno = result, errorno
self.channel.getnameinfo(('127.0.0.1', 80), pycares.ARES_NI_LOOKUPHOST|pycares.ARES_NI_LOOKUPSERVICE, cb)
self.wait()
self.assertNoError(self.errorno)
self.assertEqual(type(self.result), pycares.ares_nameinfo_result)
self.assertIn(self.result.node, ('localhost.localdomain', 'localhost'))
self.assertEqual(self.result.service, 'http')
def getnameinfo(self, sockaddr, flags):
if not isinstance(flags, int):
raise TypeError('an integer is required')
if not isinstance(sockaddr, tuple):
raise TypeError('getnameinfo() argument 1 must be a tuple')
try:
port = int(sockaddr[1])
except Exception:
raise TypeError('an integer is required')
_flags = pycares.ARES_NI_LOOKUPHOST|pycares.ARES_NI_LOOKUPSERVICE
for socket_flag, ares_flag in self._ares_flag_map:
if socket_flag & flags:
_flags |= ares_flag
try:
result = self.getaddrinfo(sockaddr[0], sockaddr[1], family=socket.AF_UNSPEC, socktype=socket.SOCK_DGRAM)
except ValueError:
raise socket.gaierror(8, 'nodename nor servname provided, or not known')
if len(result) != 1:
raise socket.error('sockaddr resolved to multiple addresses')
family, socktype, proto, name, address = result[0]
if family == socket.AF_INET:
if len(sockaddr) != 2:
raise socket.error("IPv4 sockaddr must be 2 tuple")
elif family == socket.AF_INET6:
address = address[:2] # TODO: is this ok?
waiter = Waiter(self.hub)