def portCoerce(value):
    """
    Coerce a string value to an int port number, and checks the validity.
    """
    value = int(value)
    if value < 0 or value > 65535:
        raise ValueError("Port number not in range: %s" % (value,))
    return value

    Coerce a string value to an int port number, and checks the validity.
    
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/usage.py