Skip to content

Commit

Permalink
Add support for getnameinfo
Browse files Browse the repository at this point in the history
This is a followup to aio-libs#118 to add `getnameinfo` as well to support

aio-libs/aiohttp#8270
  • Loading branch information
bdraco committed Mar 30, 2024
1 parent c77e97a commit 8f38fc2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion aiodns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
Any,
Optional,
Set,
Sequence
Sequence,
Tuple,
Union
)

from . import error
Expand Down Expand Up @@ -117,6 +119,12 @@ def getaddrinfo(self, host: str, family: socket.AddressFamily = socket.AF_UNSPEC
self._channel.getaddrinfo(host, port, cb, family=family, type=type, proto=proto, flags=flags)
return fut

def getnameinfo(self, sockaddr: Union[Tuple[str, int], Tuple[str, int, int, int]], flags: int = 0) -> asyncio.Future:
fut = asyncio.Future(loop=self.loop) # type: asyncio.Future
cb = functools.partial(self._callback, fut)
self._channel.getnameinfo(sockaddr, flags, cb)
return fut

def gethostbyaddr(self, name: str) -> asyncio.Future:
fut = asyncio.Future(loop=self.loop) # type: asyncio.Future
cb = functools.partial(self._callback, fut)
Expand Down
12 changes: 12 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ def test_getaddrinfo_address_family_af_inet6(self):
self.assertTrue(result)
self.assertTrue(all(node.family == socket.AF_INET6 for node in result.nodes))

def test_getnameinfo_ipv4(self):
f = self.resolver.getnameinfo(('127.0.0.1', 0))
result = self.loop.run_until_complete(f)
self.assertTrue(result)
self.assertTrue(result.node)

def test_getnameinfo_ipv6(self):
f = self.resolver.getnameinfo(('::1', 0, 0, 0))
result = self.loop.run_until_complete(f)
self.assertTrue(result)
self.assertTrue(result.node)

@unittest.skipIf(sys.platform == 'win32', 'skipped on Windows')
def test_gethostbyaddr(self):
f = self.resolver.gethostbyaddr('127.0.0.1')
Expand Down

0 comments on commit 8f38fc2

Please sign in to comment.