def create_retries_app(cache):
    retries_app = Flask(__name__)
    retries_app.PORT = 12
    retries_app.cache = cache

    # we want the retries app to listen on all methods
    retries_app.url_map.add(Rule('/', endpoint='index'))
    @retries_app.endpoint("index")
    def check_retries():
        json_hdr = {'Content-Type': 'application/json'}
        key = request.args.get('key', 'default')
        tries = request.args.get('tries', 3)
        try:
            tries = int(tries)
        except Exception:
            return Response(status=400, headers=json_hdr, response=json.dumps({
                'error': 'Please pass an integer number of tries',
                'key': key,
                'success': False,
            }))

        if key in retries_app.cache:
            retries_app.cache[key] -= 1
        else:
            retries_app.cache[key] = int(tries) - 1

        if retries_app.cache[key] <= 0:
            data = {
                'key': key,
                'tries_remaining': retries_app.cache[key],
                'success': True
            }
            return Response(response=json.dumps(data), status=200,
                            headers=json_hdr)
        else:
            msg = 'The server had an error. Try again {retry_times} more {time_p}'
            time_p = 'time' if retries_app.cache[key] == 1 else 'times'
            content = {
                'error': msg.format(retry_times=retries_app.cache[key], time_p=time_p),
                'tries_remaining': retries_app.cache[key],
                'key': key,
                'success': False,
            }
            return Response(response=json.dumps(content), status=500,
                            headers=json_hdr)

    @retries_app.route("/counters", methods=['POST'])
    def reset():
        key = request.values.get('key', 'default')
        tries = request.values.get('tries', 3)
        try:
            tries = int(tries)
        except Exception:
            return Response(status=400, headers=json_hdr, response=json.dumps({
                'error': 'Please pass an integer number of tries',
                'key': key,
                'success': False,
            }))

        retries_app.cache[key] = tries

        content = {
            'key': key,
            'tries_remaining': tries,
            'success': True,
        }
        return Response(response=json.dumps(content), status=200,
                        headers={'Content-Type': 'application/json'})

    @retries_app.route("/counters", methods=['GET'])
    def counter():
        content = {'counters': retries_app.cache, 'success': True}
        return Response(response=json.dumps(content), status=200,
                        headers={'Content-Type': 'application/json'})

    @retries_app.after_request
    def retries_header(resp):
        _log_flask(resp.status_code)
        resp.headers['Server'] = 'hamms'
        return resp

    return retries_app
dataset/ETHPy150Open kevinburke/hamms/hamms/__init__.py/create_retries_app/original