MCPcopy Create free account
hub / github.com/EasyIME/PIME / resolve

Method resolve

python/python3/tornado/platform/caresresolver.py:62–93  ·  view source on GitHub ↗
(
        self, host: str, port: int, family: int = 0
    )

Source from the content-addressed store, hash-verified

60
61 @gen.coroutine
62 def resolve(
63 self, host: str, port: int, family: int = 0
64 ) -> "Generator[Any, Any, List[Tuple[int, Any]]]":
65 if is_valid_ip(host):
66 addresses = [host]
67 else:
68 # gethostbyname doesn't take callback as a kwarg
69 fut = Future() # type: Future[Tuple[Any, Any]]
70 self.channel.gethostbyname(
71 host, family, lambda result, error: fut.set_result((result, error))
72 )
73 result, error = yield fut
74 if error:
75 raise IOError(
76 "C-Ares returned error %s: %s while resolving %s"
77 % (error, pycares.errno.strerror(error), host)
78 )
79 addresses = result.addresses
80 addrinfo = []
81 for address in addresses:
82 if "." in address:
83 address_family = socket.AF_INET
84 elif ":" in address:
85 address_family = socket.AF_INET6
86 else:
87 address_family = socket.AF_UNSPEC
88 if family != socket.AF_UNSPEC and family != address_family:
89 raise IOError(
90 "Requested socket family %d but got %d" % (family, address_family)
91 )
92 addrinfo.append((typing.cast(int, address_family), (address, port)))
93 return addrinfo

Callers

nothing calls this directly

Calls 2

is_valid_ipFunction · 0.90
appendMethod · 0.45

Tested by

no test coverage detected