def parse_user_prefix(prefix):
    """
    Parses:
        prefix = nickname [ [ "!" user ] "@" host ]
    Returns:
        triple (nick, user, host), user and host might be None
    """
    user = None
    host = None
    nick = prefix
    host_split = prefix.split('@', 1)
    if len(host_split) == 2:
        nick = host_split[0]
        host = host_split[1]
        user_split = nick.split('!', 1)
        if len(user_split) == 2:
            nick = user_split[0]
            user = user_split[1]
    return nick, user, host