(addr)
return str(addr)
Tries to return an IPAddress, otherwise returns a string.

    TODO consider explicitly checking for .exit or .onion at the end?
Tries to return an IPAddress, otherwise returns a string.
Tries to return an IPAddress otherwise returns a string .
def maybe_ip_addr(addr):
    """
    Tries to return an IPAddress, otherwise returns a string.

    TODO consider explicitly checking for .exit or .onion at the end?
    """

    if six.PY2 and isinstance(addr, str):
        addr = unicode(addr)  # noqa
    try:
        return ipaddress.ip_address(addr)
    except ValueError:
        pass
    return str(addr)
def maybe_ip_addr ( addr ) : if six . PY2 and isinstance ( addr , str ) : addr = unicode ( addr ) # noqa try : return ipaddress . ip_address ( addr ) except ValueError : pass return str ( addr )