<commit_before># coding=utf-8
from flask import g, session, request, current_app
from flask import redirect, url_for

from C4GD_web import app

from .models.orm import User, get_store


@app.before_request
def create_storm_readonly_store():
    g.store = get_store('RO')


@app.after_request
def commit_storm_store(response):
    if hasattr(g, 'store'):
        g.store.commit()
    return response

@app.teardown_request
def commit_storm_store_optionally(exception):
    if hasattr(g, 'store'):
        g.store.commit()


@app.before_request
def authenticate():
    g.is_authenticated = 'keystone_unscoped' in session
    if not g.is_authenticated:
        if request.endpoint not in current_app.config['ANONYMOUS_ALLOWED']:
            return redirect(url_for('login'))


@app.before_request
def inject_user():
    g.is_global_admin = g.is_authenticated and any([x.get('name') == 'Admin' for x in session['keystone_unscoped']['access']['user']['roles']])
    if g.is_authenticated:
        g.user = g.store.get(
            User, int(session['keystone_unscoped']['access']['user']['id']))<commit_msg>useful handling of 'is_xhr' in GET<commit_after># coding=utf-8
from flask import g, session, request, current_app
from flask import redirect, url_for

from C4GD_web import app

from .models.orm import User, get_store


@app.before_request
def create_storm_readonly_store():
    g.store = get_store('RO')


@app.after_request
def commit_storm_store(response):
    if hasattr(g, 'store'):
        g.store.commit()
    return response

@app.teardown_request
def commit_storm_store_optionally(exception):
    if hasattr(g, 'store'):
        g.store.commit()


@app.before_request
def authenticate():
    g.is_authenticated = 'keystone_unscoped' in session
    if not g.is_authenticated:
        if request.endpoint not in current_app.config['ANONYMOUS_ALLOWED']:
            return redirect(url_for('login'))


@app.before_request
def inject_user():
    g.is_global_admin = g.is_authenticated and any([x.get('name') == 'Admin' for x in session['keystone_unscoped']['access']['user']['roles']])
    if g.is_authenticated:
        g.user = g.store.get(
            User, int(session['keystone_unscoped']['access']['user']['id']))


@app.before_request
def mock_xhr():
    if 'is_xhr' in request.args:
        request.xhr = True
        request.environ['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest'

{'fraction_non_alphanumeric': 0.12750836120401338, 'fraction_numerical': 0.0016722408026755853, 'mean_word_length': 4.224890829694323, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '472148', 'n_tokens_mistral': 816, 'n_tokens_neox': 783, 'n_words': 173}