Skip to content

Commit 7480968

Browse files
bdracosaghul
authored andcommitted
Add support for getnameinfo
This is a followup to #118 to add `getnameinfo` as well to support aio-libs/aiohttp#8270
1 parent c77e97a commit 7480968

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

aiodns/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
Any,
1010
Optional,
1111
Set,
12-
Sequence
12+
Sequence,
13+
Tuple,
14+
Union
1315
)
1416

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

122+
def getnameinfo(self, sockaddr: Union[Tuple[str, int], Tuple[str, int, int, int]], flags: int = 0) -> asyncio.Future:
123+
fut = asyncio.Future(loop=self.loop) # type: asyncio.Future
124+
cb = functools.partial(self._callback, fut)
125+
self._channel.getnameinfo(sockaddr, flags, cb)
126+
return fut
127+
120128
def gethostbyaddr(self, name: str) -> asyncio.Future:
121129
fut = asyncio.Future(loop=self.loop) # type: asyncio.Future
122130
cb = functools.partial(self._callback, fut)

tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,18 @@ def test_getaddrinfo_address_family_af_inet6(self):
169169
self.assertTrue(result)
170170
self.assertTrue(all(node.family == socket.AF_INET6 for node in result.nodes))
171171

172+
def test_getnameinfo_ipv4(self):
173+
f = self.resolver.getnameinfo(('127.0.0.1', 0))
174+
result = self.loop.run_until_complete(f)
175+
self.assertTrue(result)
176+
self.assertTrue(result.node)
177+
178+
def test_getnameinfo_ipv6(self):
179+
f = self.resolver.getnameinfo(('::1', 0, 0, 0))
180+
result = self.loop.run_until_complete(f)
181+
self.assertTrue(result)
182+
self.assertTrue(result.node)
183+
172184
@unittest.skipIf(sys.platform == 'win32', 'skipped on Windows')
173185
def test_gethostbyaddr(self):
174186
f = self.resolver.gethostbyaddr('127.0.0.1')

0 commit comments

Comments
 (0)