def _gethostbyaddr(self, ip_address_bytes): try: return resolver._gethostbyaddr(ip_address_bytes) except gaierror as ex: if ex.args[0] == EAI_NONAME: # Note: The system doesn't *always* raise herror; # sometimes the original gaierror propagates through. # It's impossible to say ahead of time or just based # on the name which it should be. The herror seems to # be by far the most common, though. raise herror(1, "Unknown host") raise
def _gethostbyname_ex(self, hostname_bytes, family): while True: ares = self.cares try: waiter = Waiter(self.hub) ares.gethostbyname(waiter, hostname_bytes, family) result = waiter.get() if not result[-1]: raise herror(EAI_NONAME, self.EAI_NONAME_MSG) return result except herror as ex: if ares is self.cares: if ex.args[0] == 1: # Somewhere along the line, the internal # implementation of gethostbyname_ex changed to invoke # getaddrinfo() as a first pass, much like we do for ``getnameinfo()``; # this means it raises a different error for not-found hosts. raise gaierror(EAI_NONAME, self.EAI_NONAME_MSG) raise