<commit_before>import urllib
import urllib2
import uuid
import json
import re

from datetime import date
from functools import wraps

from pymongo import Connection

from tornado import (
    httpserver,
    httpclient,
    ioloop,
    options,
    web,
    gen
    )

from tornado.options import (
    define,
    options
    )

import tornado
import asyncmongo

define("host", default='localhost', help="run on the given host")
define("port", default=80, help="run on the given port", type=int)
define("mongodb_port", default=27017, help="run MongoDB on the given port", type=int)
define("mongodb_host", default='localhost', help="run MongoDB on the given hostname")
define("mongodb_database", default='analytics', help="Record accesses on the given database")
define("mongodb_max_connections", default=2000, help="run MongoDB with the given max connections", type=int)
define("mongodb_max_cached", default=0, help="run MongoDB with the given max cached", type=int)
define("mongodb_max_usage", default=0, help="run MongoDB with the given max cached", type=int)
define("mongodb_min_cached", default=1000, help="run MongoDB with the given min cached", type=int)
define("allowed_hosts", default=None, help="indicates a txt file with hostnames allowed to post data.", type=str)
define("manager_token", default=str(uuid.uuid4()), help="indicates a token that must be used to manage allowed_tokens.", type=str)
define("broadcast_timeout", default=1, help="indicates the max timeout in seconds that the broadcast must finish.", type=str)


LIMIT = 20
REGEX_ISSN = re.compile("^[0-9]{4}-[0-9]{3}[0-9xX]$")
REGEX_ISSUE = re.compile("^[0-9]{4}-[0-9]{3}[0-9xX][0-2][0-9]{3}[0-9]{4}$")
REGEX_ARTICLE = re.compile("^S[0-9]{4}-[0-9]{3}[0-9xX][0-2][0-9]{3}[0-9]{4}[0-9]{5}$")
REGEX_FBPE = re.compile("^S[0-9]{4}-[0-9]{3}[0-9xX]\([0-9]{2}\)[0-9]{8}$")


def get_next(endpoint, total, limit, offset, fltr=None):

    offset += limit
    if offset >= total:
        return None

    fltrs = ''
    if fltr:
        fltrs += '&%s' % '&'.join(set(['='.join([key, value]) for key, value in fltr.items()]))

    return '/api/v1/%s?offset=%s%s' % (endpoint, offset, fltrs)


def get_previous(endpoint, total, limit, offset, fltr=None):
    offset -= limit
    if offset < 0:
        return None

    fltrs = ''
    if fltr:
        fltrs += '&%s' % '&'.join(set(['='.join([key, value]) for key, value in fltr.items()]))

    return '/api/v1/%s?offset=%s%s' % (endpoint, offset, fltrs)


def authenticated(func):
    @wraps(func)<commit_msg>Ajustes em parametrização de endpoint general<commit_after>import urllib
import urllib2
import uuid
import json
import re

from datetime import date
from functools import wraps

from pymongo import Connection

from tornado import (
    httpserver,
    httpclient,
    ioloop,
    options,
    web,
    gen
    )

from tornado.options import (
    define,
    options
    )

import tornado
import asyncmongo

define("host", default='localhost', help="run on the given host")
define("port", default=80, help="run on the given port", type=int)
define("mongodb_port", default=27017, help="run MongoDB on the given port", type=int)
define("mongodb_host", default='localhost', help="run MongoDB on the given hostname")
define("mongodb_database", default='analytics', help="Record accesses on the given database")
define("mongodb_max_connections", default=2000, help="run MongoDB with the given max connections", type=int)
define("mongodb_max_cached", default=0, help="run MongoDB with the given max cached", type=int)
define("mongodb_max_usage", default=0, help="run MongoDB with the given max cached", type=int)
define("mongodb_min_cached", default=1000, help="run MongoDB with the given min cached", type=int)
define("allowed_hosts", default=None, help="indicates a txt file with hostnames allowed to post data.", type=str)
define("manager_token", default=str(uuid.uuid4()), help="indicates a token that must be used to manage allowed_tokens.", type=str)
define("broadcast_timeout", default=1, help="indicates the max timeout in seconds that the broadcast must finish.", type=str)


LIMIT = 20
REGEX_ISSN = re.compile("^[0-9]{4}-[0-9]{3}[0-9xX]$")
REGEX_ISSUE = re.compile("^[0-9]{4}-[0-9]{3}[0-9xX][0-2][0-9]{3}[0-9]{4}$")
REGEX_ARTICLE = re.compile("^S[0-9]{4}-[0-9]{3}[0-9xX][0-2][0-9]{3}[0-9]{4}[0-9]{5}$")
REGEX_FBPE = re.compile("^S[0-9]{4}-[0-9]{3}[0-9xX]\([0-9]{2}\)[0-9]{8}$")


def get_next(endpoint, total, limit, offset, fltr=None):

    offset += limit
    if offset >= total:
        return None

    fltrs = ''
    if fltr:
        fltrs += '&%s' % '&'.join(set(['='.join([key, value]) for key, value in fltr.items()]))

    return '/api/v1/%s/?offset=%s%s' % (endpoint, offset, fltrs)


def get_previous(endpoint, total, limit, offset, fltr=None):
    offset -= limit
    if offset < 0:
        return None

    fltrs = ''
    if fltr:
        fltrs += '&%s' % '&'.join(set(['='.join([key, value]) for key, value in fltr.items()]))

    return '/api/v1/%s/?offset=%s%s' % (endpoint, offset, fltrs)


def authenticated(func):
    @wraps(func)
{'fraction_non_alphanumeric': 0.1695583596214511, 'fraction_numerical': 0.032334384858044164, 'mean_word_length': 4.725733634311513, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6909587', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1755, 'n_words': 470}