Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for getnameinfo #119

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading