<commit_before># -*- coding: utf8 -*-
# This file is part of PyBossa.
#
# Copyright (C) 2013 SF Isle of Man Limited
#
# PyBossa is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyBossa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with PyBossa.  If not, see <http://www.gnu.org/licenses/>.
# Cache global variables for timeouts
"""
Rate limit module for limiting the requests in the API.

This module exports:
    * RateLimit class: for limiting the requests
    * ratelimit decorator: for decorating the views

"""
import time
from functools import update_wrapper, wraps
from flask import request, g
from werkzeug.exceptions import TooManyRequests
from pybossa.core import sentinel
from pybossa.error import ErrorStatus

error = ErrorStatus()


class RateLimit(object):

    """
    Limit the number of requests.

    It uses a Redis pipe from the master node (configured via Sentinel) to
    limit the number of requests.

    """

    expiration_window = 10

    def __init__(self, key_prefix, limit, per, send_x_headers):
        self.reset = (int(time.time()) // per) * per + per
        self.key = key_prefix + str(self.reset)
        self.limit = limit
        self.per = per
        self.send_x_headers = send_x_headers

        redis_master = sentinel.master_for('mymaster')
        p = redis_master.pipeline()
        p.incr(self.key)<commit_msg>Use the new sentinel object<commit_after># -*- coding: utf8 -*-
# This file is part of PyBossa.
#
# Copyright (C) 2013 SF Isle of Man Limited
#
# PyBossa is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyBossa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with PyBossa.  If not, see <http://www.gnu.org/licenses/>.
# Cache global variables for timeouts
"""
Rate limit module for limiting the requests in the API.

This module exports:
    * RateLimit class: for limiting the requests
    * ratelimit decorator: for decorating the views

"""
import time
from functools import update_wrapper, wraps
from flask import request, g
from werkzeug.exceptions import TooManyRequests
from pybossa.core import sentinel
from pybossa.error import ErrorStatus

error = ErrorStatus()


class RateLimit(object):

    """
    Limit the number of requests.

    It uses a Redis pipe from the master node (configured via Sentinel) to
    limit the number of requests.

    """

    expiration_window = 10

    def __init__(self, key_prefix, limit, per, send_x_headers):
        self.reset = (int(time.time()) // per) * per + per
        self.key = key_prefix + str(self.reset)
        self.limit = limit
        self.per = per
        self.send_x_headers = send_x_headers

        redis_master = sentinel.connection.master_for('mymaster')
        p = redis_master.pipeline()
        p.incr(self.key)
{'fraction_non_alphanumeric': 0.0732371358562483, 'fraction_numerical': 0.004356112169888375, 'mean_word_length': 3.4479418886198547, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3925224', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1014, 'n_words': 451}