File: _resolver_async_trio.py

package info (click to toggle)
electrum 4.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 35,248 kB
  • sloc: python: 222,785; sh: 165; java: 73; javascript: 10; makefile: 9
file content (21 lines) | stat: -rw-r--r-- 607 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import trio

from ._resolver_async import AsyncResolver


class Resolver(AsyncResolver):

    async def resolve(self, host, port=0, family=trio.socket.AF_UNSPEC):
        infos = await trio.socket.getaddrinfo(
            host=host, port=port,
            family=family, type=trio.socket.SOCK_STREAM
        )

        if not infos:
            raise OSError('Can`t resolve address '  # pragma: no cover
                          '{}:{} [{}]'.format(host, port, family))

        infos = sorted(infos, key=lambda info: info[0])

        family, _, _, _, address = infos[0]
        return family, address[0]