Пример #1
0
 def checker(loc):
     host, port = parse_host_port(loc)
     assert host == expected_host
     if expected_port is not None:
         assert port == expected_port
     else:
         assert 1023 < port < 65536
Пример #2
0
 def checker(loc):
     host, port = parse_host_port(loc)
     assert host == expected_host
     if expected_port is not None:
         assert port == expected_port
     else:
         assert 1023 < port < 65536
Пример #3
0
def uri_from_host_port(host_arg, port_arg, default_port):
    """
    Process the *host* and *port* CLI options.
    Return a URI.
    """
    # Much of distributed depends on a well-known IP being assigned to
    # each entity (Worker, Scheduler, etc.), so avoid "universal" addresses
    # like '' which would listen on all registered IPs and interfaces.
    scheme, loc = parse_address(host_arg or "")

    host, port = parse_host_port(
        loc, port_arg if port_arg is not None else default_port)

    if port is None and port_arg is None:
        port_arg = default_port

    if port and port_arg and port != port_arg:
        raise ValueError("port number given twice in options: "
                         "host %r and port %r" % (host_arg, port_arg))
    if port is None and port_arg is not None:
        port = port_arg
    # Note `port = 0` means "choose a random port"
    if port is None:
        port = default_port
    loc = unparse_host_port(host, port)
    addr = unparse_address(scheme, loc)

    return addr