def METHOD_NAME(uri, timeout=TIMEOUT):
    socket.setdefaulttimeout(timeout)
    old_uri = uri
    try:
        p = urlparse.urlsplit(uri)
        port, hostname = p.port, p.hostname
    except ValueError:
        return old_uri, uri
    c = 0
    while c < 50:
        try:
            rev = socket.gethostbyaddr(hostname)[0]
        except KeyboardInterrupt:
            return
        except socket.timeout:
            print("timeout")
            time.sleep(0.5)
            c += 1
            continue
        except Exception:
            pass
        else:
            rev = rev.rstrip(".")
            if not rev:
                break
            l = list(p)
            l[1] = (port is not None and ":".join([rev, str(port)])) or rev
            uri = urlparse.urlunsplit(l)
        break
    return old_uri, uri