def rate_limit(limit=100, window=60):
    def decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            key = "{0}: {1}".format(request.remote_addr, request.path)

            try:
                remaining = limit - int(redis.get(key))
            except (ValueError, __HOLE__):
                remaining = limit
                redis.set(key, 0)

            expires_in = redis.ttl(key)
            if not expires_in:
                redis.expire(key, window)
                expires_in = window

            g.rate_limits = (limit, remaining-1, time()+expires_in)

            if remaining > 0:
                redis.incr(key, 1)
                return func(*args, **kwargs)
            return TOO_MANY_REQUESTS
        return wrapper
    return decorator
dataset/ETHPy150Open projectweekend/Flask-PostgreSQL-API-Seed/app/utils/rate_limit.py/rate_limit