'Takes a macaroon and tries to parse and validate it. This is cached
if and only if rights == access and there isn\'t an expiry.
On invalid macaroon raises _InvalidMacaroonException
Returns:
(user_id, is_guest)'

def _parse_and_validate_macaroon(self, token, rights='access'):

    if (rights == 'access'):
        cached = self.token_cache.get(token, None)
        if cached:
            return cached
    try:
        macaroon = pymacaroons.Macaroon.deserialize(token)
    except Exception:
        raise _InvalidMacaroonException()
    try:
        user_id = self.get_user_id_from_macaroon(macaroon)
        has_expiry = False
        guest = False
        for caveat in macaroon.caveats:
            if caveat.caveat_id.startswith('time    '):
                has_expiry = True
            elif (caveat.caveat_id == 'guest    =    true'):
                guest = True
        self.validate_macaroon(macaroon, rights, self.hs.config.expire_access_token, user_id=user_id)
    except (pymacaroons.exceptions.MacaroonException, TypeError, ValueError):
        raise AuthError(self.TOKEN_NOT_FOUND_HTTP_STATUS, 'Invalid    macaroon    passed.', errcode=Codes.UNKNOWN_TOKEN)
    if ((not has_expiry) and (rights == 'access')):
        self.token_cache[token] = (user_id, guest)
    return (user_id, guest)
