A special argument type that splits a string on ':' and transforms
    the result into a tuple of host and (integer) port.

def address(addr):
    """
    A special argument type that splits a string on ':' and transforms
    the result into a tuple of host and (integer) port.
    """

    if ':' in addr:
        # Using rpartition here means we should be able to support
        # IPv6, but only with a strict syntax
        host, _sep, port = addr.rpartition(':')

        # Convert the port to a number
        try:
            port = int(port)
        except ValueError:
            raise ValueError("invalid port number %r" % port)

        addr = (host, port)

    return addr