<commit_before># -*- coding: utf-8 -*-


from flask import render_template, request, redirect, \
    url_for, flash, session, abort, current_app, jsonify
from flask.blueprints import Blueprint
from flask.ext.babel import gettext
from flask.ext.login import current_user, login_user, logout_user, \
    login_required
from sqlalchemy.exc import OperationalError
from ldap3 import LDAPCommunicationError

from model import dormitory_from_name, user_from_ip, premature_dormitories
from model.default import BaseUser

from sipa.forms import flash_formerrors, LoginForm, AnonymousContactForm
from sipa.utils import current_user_name
from sipa.utils.exceptions import UserNotFound, PasswordInvalid
from sipa.utils.mail_utils import send_mail


import logging
logger = logging.getLogger(__name__)

bp_generic = Blueprint('generic', __name__)


@bp_generic.before_app_request
def log_request():
    current_app.extensions['sentry'].client.extra_context({
        'current_user': current_user,
        'ip_user': user_from_ip(request.remote_addr)
    })

    logging.getLogger(__name__ + '.http').debug(
        'Incoming request: %s %s', request.method, request.path,
        extra={'tags': {'user': current_user_name(),
                        'ip': request.remote_addr}}
    )


@bp_generic.app_errorhandler(401)
@bp_generic.app_errorhandler(403)
@bp_generic.app_errorhandler(404)
def error_handler_redirection(e):
    """Handles errors by flashing an according message
    :param e: The error
    :return: A flask response with the according HTTP error code<commit_msg>Add extra sentry information only if sentry enabled<commit_after># -*- coding: utf-8 -*-


from flask import render_template, request, redirect, \
    url_for, flash, session, abort, current_app, jsonify
from flask.blueprints import Blueprint
from flask.ext.babel import gettext
from flask.ext.login import current_user, login_user, logout_user, \
    login_required
from sqlalchemy.exc import OperationalError
from ldap3 import LDAPCommunicationError

from model import dormitory_from_name, user_from_ip, premature_dormitories
from model.default import BaseUser

from sipa.forms import flash_formerrors, LoginForm, AnonymousContactForm
from sipa.utils import current_user_name
from sipa.utils.exceptions import UserNotFound, PasswordInvalid
from sipa.utils.mail_utils import send_mail


import logging
logger = logging.getLogger(__name__)

bp_generic = Blueprint('generic', __name__)


@bp_generic.before_app_request
def log_request():
    if 'sentry' in current_app.extensions:
        current_app.extensions['sentry'].client.extra_context({
            'current_user': current_user,
            'ip_user': user_from_ip(request.remote_addr)
        })

    logging.getLogger(__name__ + '.http').debug(
        'Incoming request: %s %s', request.method, request.path,
        extra={'tags': {'user': current_user_name(),
                        'ip': request.remote_addr}}
    )


@bp_generic.app_errorhandler(401)
@bp_generic.app_errorhandler(403)
@bp_generic.app_errorhandler(404)
def error_handler_redirection(e):
    """Handles errors by flashing an according message
    :param e: The error
    :return: A flask response with the according HTTP error code
{'fraction_non_alphanumeric': 0.08744186046511628, 'fraction_numerical': 0.006821705426356589, 'mean_word_length': 4.669595782073814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4481779', 'n_tokens_mistral': 974, 'n_tokens_neox': 927, 'n_words': 252}