def rate_limited(max_per_second):
    import datetime
    min_request_time = datetime.timedelta(seconds=max_per_second)
    last_time_called = [None]
    def decorate(func):
        def rate_limited_function(*args, **kwargs):
            if last_time_called[0]:
                delta = datetime.datetime.now() - last_time_called[0]
                if delta < datetime.timedelta.min:
                    raise chrw.exceptions.TimeIsBackToFront, "Call the Doc!"
                elif delta < min_request_time:
                    msg = "Last request was {0}, should be at least {1}".format(
                        delta, min_request_time
                    )
                    raise chrw.exceptions.RequestRateTooHigh, msg
            ret = func(*args, **kwargs)
            last_time_called[0] = datetime.datetime.now()
            return ret
        return functools.update_wrapper(rate_limited_function, func)
    return decorate