<commit_before>import copy
from importlib import import_module
import logging
from uuid import uuid4
import traceback

from flask.ext.babel import Babel
from babel.support import LazyProxy
from flask.ext.mako import MakoTemplates, render_template
from flask.helpers import send_from_directory
from jwkest.jwk import rsa_load, RSAKey
from mako.lookup import TemplateLookup
from flask import Flask
from flask import g
from flask import abort
from flask import request
from flask import session

from flask import redirect

from cmservice.consent import Consent
from cmservice.consent_manager import ConsentManager
from cmservice.database import ConsentDB, TicketDB

app = Flask(__name__, static_url_path='')
app.config.from_pyfile("settings.cfg")

LOGGER = logging.getLogger("")
LOGFILE_NAME = app.config['LOGGING_FILE']
hdlr = logging.FileHandler(LOGFILE_NAME)
base_formatter = logging.Formatter("[%(asctime)-19.19s] [%(levelname)-5.5s]: %(message)s")
hdlr.setFormatter(base_formatter)
hdlr.setLevel(app.config['LOGGING_LEVEL'])
LOGGER.addHandler(hdlr)

mako = MakoTemplates()
mako.init_app(app)
app._mako_lookup = TemplateLookup(directories=["templates"],
                                  input_encoding='utf-8', output_encoding='utf-8',
                                  imports=["from flask.ext.babel import gettext as _"])

babel = Babel(app)


def ugettext(s):
    # we assume a before_request function
    # assigns the correct user-specific
    # translations
    return g.translations.ugettext(s)


ugettext_lazy = LazyProxy(ugettext)


@babel.localeselector
def get_locale():
    try:
        return session['language']
    except:
        pass


@app.route('/static/<path:path>')
def send_js(path):
    return send_from_directory('static', path)

@app.route("/verify/<id>")
def verify(id):
    attributes = cm.find_consent(id, app.config['CONSENT_SALT'])
    if attributes:
        return attributes
    abort(401)


@app.route("/creq/<jwt>")
def creq(jwt):
    try:
        ticket = cm.save_consent_req(jwt)
        return ticket
    except:
        abort(400)


@app.route('/consent', methods=['GET'])
def consent():
    try:
        # gettext("test")
        ticket = request.args["ticket"]
        data = cm.get_attributes(ticket)
        if data is None:
            abort(403)
        session["id"] = data["id"]
        session["state"] = uuid4().urn
        session["redirect_endpoint"] = data["redirect_endpoint"]
        session["attr"] = data["attr"]
        session["locked_attr"] = data["locked_attr"]
        session["requester_name"] = data["requester_name"]
        session["requestor"] = data["requestor"]

        return render_consent(language=request.accept_languages.best_match(['sv', 'en']))
    except Exception as ex:
        if app.debug:
            traceback.print_exc()
        abort(400)


def render_consent(language):
    session['language'] = language

    requester_name = find_requester_name(language)
    if not requester_name:
        requester_name = find_requester_name("en")
    if not requester_name:
        requester_name = session["requester_name"][0]['text']

    locked_attr = session["locked_attr"]
    if not isinstance(locked_attr, list):
        locked_attr = [locked_attr]
<commit_msg>Remove expectation of 'requestor' attribut in incoming data.<commit_after>import copy
from importlib import import_module
import logging
from uuid import uuid4
import traceback

from flask.ext.babel import Babel
from babel.support import LazyProxy
from flask.ext.mako import MakoTemplates, render_template
from flask.helpers import send_from_directory
from jwkest.jwk import rsa_load, RSAKey
from mako.lookup import TemplateLookup
from flask import Flask
from flask import g
from flask import abort
from flask import request
from flask import session

from flask import redirect

from cmservice.consent import Consent
from cmservice.consent_manager import ConsentManager
from cmservice.database import ConsentDB, TicketDB

app = Flask(__name__, static_url_path='')
app.config.from_pyfile("settings.cfg")

LOGGER = logging.getLogger("")
LOGFILE_NAME = app.config['LOGGING_FILE']
hdlr = logging.FileHandler(LOGFILE_NAME)
base_formatter = logging.Formatter("[%(asctime)-19.19s] [%(levelname)-5.5s]: %(message)s")
hdlr.setFormatter(base_formatter)
hdlr.setLevel(app.config['LOGGING_LEVEL'])
LOGGER.addHandler(hdlr)

mako = MakoTemplates()
mako.init_app(app)
app._mako_lookup = TemplateLookup(directories=["templates"],
                                  input_encoding='utf-8', output_encoding='utf-8',
                                  imports=["from flask.ext.babel import gettext as _"])

babel = Babel(app)


def ugettext(s):
    # we assume a before_request function
    # assigns the correct user-specific
    # translations
    return g.translations.ugettext(s)


ugettext_lazy = LazyProxy(ugettext)


@babel.localeselector
def get_locale():
    try:
        return session['language']
    except:
        pass


@app.route('/static/<path:path>')
def send_js(path):
    return send_from_directory('static', path)

@app.route("/verify/<id>")
def verify(id):
    attributes = cm.find_consent(id, app.config['CONSENT_SALT'])
    if attributes:
        return attributes
    abort(401)


@app.route("/creq/<jwt>")
def creq(jwt):
    try:
        ticket = cm.save_consent_req(jwt)
        return ticket
    except:
        abort(400)


@app.route('/consent', methods=['GET'])
def consent():
    try:
        # gettext("test")
        ticket = request.args["ticket"]
        data = cm.get_attributes(ticket)
        if data is None:
            abort(403)
        session["id"] = data["id"]
        session["state"] = uuid4().urn
        session["redirect_endpoint"] = data["redirect_endpoint"]
        session["attr"] = data["attr"]
        session["locked_attr"] = data["locked_attr"]
        session["requester_name"] = data["requester_name"]

        return render_consent(language=request.accept_languages.best_match(['sv', 'en']))
    except Exception as ex:
        if app.debug:
            traceback.print_exc()
        abort(400)


def render_consent(language):
    session['language'] = language

    requester_name = find_requester_name(language)
    if not requester_name:
        requester_name = find_requester_name("en")
    if not requester_name:
        requester_name = session["requester_name"][0]['text']

    locked_attr = session["locked_attr"]
    if not isinstance(locked_attr, list):
        locked_attr = [locked_attr]

{'fraction_non_alphanumeric': 0.11378353376503238, 'fraction_numerical': 0.0070921985815602835, 'mean_word_length': 3.693921852387844, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '318240', 'n_tokens_mistral': 2062, 'n_tokens_neox': 2011, 'n_words': 451}