def handleExpiredToken(f):
    """Handle token expiry during execution of `f`.

    Note this isn't really useful outside this module since it makes a lot
    of assumptions about `f`.
    """
    @functools.wraps(f)
    def wrapper(self, serviceRec, *args, **kwargs):
        delete_cache = lambda: self._tokenCache.Delete(serviceRec.ExternalID)
        with handle_exception(is_http_401, delete_cache):
            return f(self, serviceRec, *args, **kwargs)
        # the second attempt should now trigger a token refresh
        with handle_exception(is_http_401, raise_api_exception):
            return f(self, serviceRec, *args, **kwargs)
    return wrapper
Handle token expiry during execution of `f`.

    Note this isn't really useful outside this module since it makes a lot
    of assumptions about `f`.
    
tapiriik/services/Smashrun/smashrun.py