def parse_credentials(creds):
    """
    Parses a credentials string. The first part is the password which
    is separated by a forward-slash to the host-name. The host-name is
    separated by a double-colon to the port-name.

    Returns a tuple of ``(password, host, port)``. A *ValueError* is
    raised if the format is invalid. The password is optional and
    None is returned if it is not specified.
    """

    password, _, creds = creds.rpartition('/')
    if not password:
        password = None

    host, _, creds = creds.rpartition(':')
    if not host:
        raise ValueError('no host')

    if not creds:
        raise ValueError('no port')
    try:
        port = int(creds)
    except ValueError:
        raise ValueError('invalid port')

    return (password, host, port)