<commit_before>from flask import Blueprint, render_template, request, make_response
from .collector import Collector
from .serializer import dumps
from .usage import Usage

blueprint = Blueprint('v2', __name__, url_prefix='/v2', template_folder='templates', static_folder='static')
usage = Usage()

def request_wants_json():
    best = request.accept_mimetypes \
        .best_match(['application/json', 'text/html'])
    return best == 'application/json' and \
           request.accept_mimetypes[best] > \
           request.accept_mimetypes['text/html']

def show_pretty_response(res, path = ''):
    res.headers.add('Access-Control-Allow-Origin', '*')

    if request_wants_json() or 'json' in request.args:
        return res
    else:
        return render_template('json.html', path='/v2/' + path, method=request.method, data=res)

@blueprint.route('/usage')
def show_usage():
    res = make_response((dumps(usage.show_usage()), 200))
    
    return show_pretty_response(res)

@blueprint.route('/')
@blueprint.route('/<path:path>')
def resolve(path = ''):
    if not usage.process(request):
        return 'Rate limit exceeded', 492

    collector = Collector()
    collector.collect(path, request.args.to_dict(True))

    res = make_response((dumps(collector.results()), 200))

    return show_pretty_response(res, path)<commit_msg>show path properly in usage request<commit_after>from flask import Blueprint, render_template, request, make_response
from .collector import Collector
from .serializer import dumps
from .usage import Usage

blueprint = Blueprint('v2', __name__, url_prefix='/v2', template_folder='templates', static_folder='static')
usage = Usage()

def request_wants_json():
    best = request.accept_mimetypes \
        .best_match(['application/json', 'text/html'])
    return best == 'application/json' and \
           request.accept_mimetypes[best] > \
           request.accept_mimetypes['text/html']

def show_pretty_response(res, path = ''):
    res.headers.add('Access-Control-Allow-Origin', '*')

    if request_wants_json() or 'json' in request.args:
        return res
    else:
        return render_template('json.html', path='/v2/' + path, method=request.method, data=res)

@blueprint.route('/usage')
def show_usage():
    res = make_response((dumps(usage.show_usage()), 200))
    
    return show_pretty_response(res, 'usage')

@blueprint.route('/')
@blueprint.route('/<path:path>')
def resolve(path = ''):
    if not usage.process(request):
        return 'Rate limit exceeded', 492

    collector = Collector()
    collector.collect(path, request.args.to_dict(True))

    res = make_response((dumps(collector.results()), 200))

    return show_pretty_response(res, path)
{'fraction_non_alphanumeric': 0.13969775156653153, 'fraction_numerical': 0.008846295613711759, 'mean_word_length': 4.209213051823417, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5858098', 'n_tokens_mistral': 865, 'n_tokens_neox': 827, 'n_words': 181}