File: _resolver.py

package info (click to toggle)
python-socks 2.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 544 kB
  • sloc: python: 5,191; sh: 8; makefile: 3
file content (16 lines) | stat: -rw-r--r-- 547 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import socket
from .. import _abc as abc


class SyncResolver(abc.SyncResolver):
    # noinspection PyMethodMayBeStatic
    def resolve(self, host, port=0, family=socket.AF_UNSPEC):
        infos = socket.getaddrinfo(host=host, port=port, family=family, type=socket.SOCK_STREAM)

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

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

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