(uri, component)
return (0 <= port <= 65535)
Determine if the userinfo, host, and port are valid.
Determine if the userinfo, host, and port are valid.
Determine if the userinfo host and port are valid .
def subauthority_component_is_valid(uri, component):
    """Determine if the userinfo, host, and port are valid."""
    try:
        subauthority_dict = uri.authority_info()
    except exceptions.InvalidAuthority:
        return False

    # If we can parse the authority into sub-components and we're not
    # validating the port, we can assume it's valid.
    if component == 'host':
        return host_is_valid(subauthority_dict['host'])
    elif component != 'port':
        return True

    try:
        port = int(subauthority_dict['port'])
    except TypeError:
        # If the port wasn't provided it'll be None and int(None) raises a
        # TypeError
        return True

    return (0 <= port <= 65535)
def subauthority_component_is_valid ( uri , component ) : try : subauthority_dict = uri . authority_info ( ) except exceptions . InvalidAuthority : return False # If we can parse the authority into sub-components and we're not # validating the port, we can assume it's valid. if component == 'host' : return host_is_valid ( subauthority_dict [ 'host' ] ) elif component != 'port' : return True try : port = int ( subauthority_dict [ 'port' ] ) except TypeError : # If the port wasn't provided it'll be None and int(None) raises a # TypeError return True return ( 0 <= port <= 65535 )