<commit_before>from ebooks import app

import json
import os

from flask import redirect, request, session, url_for
from functools import wraps
from urllib.parse import urljoin, urlparse


def load_saml_settings():
    json_settings = {}
    with open("saml/settings.json", 'r') as json_file:
        json_settings = json.load(json_file)
        json_settings['debug'] = app.config['DEBUG']
        json_settings['sp']['entityId'] = os.getenv('SP_ENTITY_ID')
        json_settings['sp']['assertionConsumerService']['url'] = \
            os.getenv('SP_ACS_URL')
        json_settings['sp']['x509cert'] = os.getenv('SP_CERT')
        json_settings['sp']['privateKey'] = os.getenv('SP_KEY')
        json_settings['idp']['entityId'] = os.getenv('IDP_ENTITY_ID')
        json_settings['idp']['singleSignOnService']['url'] = \
            os.getenv('IDP_SSO_URL')
        json_settings['idp']['x509cert'] = os.getenv('IDP_CERT')
    return json_settings


def is_safe_url(target):
    ref_url = urlparse(request.host_url)
    test_url = urlparse(urljoin(request.host_url, target))
    return test_url.scheme in ('http', 'https') and \
        ref_url.netloc == test_url.netloc


def login_required(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        if 'samlSessionIndex' not in session:
            return redirect(url_for('saml', sso=True, next=request.url))
        return f(*args, **kwargs)
    return decorated_function


def prepare_flask_request(request):
    url_data = urlparse(request.url)
    return {
        'https': 'on' if request.scheme == 'https' else 'off',
        'http_host': request.host,
        'server_port': url_data.port,
        'script_name': request.path,
        'get_data': request.args.copy(),
        'post_data': request.form.copy()<commit_msg>Do not require auth in development<commit_after>import json
import os
from functools import wraps
from urllib.parse import urljoin, urlparse

from ebooks import app
from flask import redirect, request, session, url_for


def load_saml_settings():
    json_settings = {}
    with open("saml/settings.json", 'r') as json_file:
        json_settings = json.load(json_file)
        json_settings['debug'] = app.config['DEBUG']
        json_settings['sp']['entityId'] = os.getenv('SP_ENTITY_ID')
        json_settings['sp']['assertionConsumerService']['url'] = \
            os.getenv('SP_ACS_URL')
        json_settings['sp']['x509cert'] = os.getenv('SP_CERT')
        json_settings['sp']['privateKey'] = os.getenv('SP_KEY')
        json_settings['idp']['entityId'] = os.getenv('IDP_ENTITY_ID')
        json_settings['idp']['singleSignOnService']['url'] = \
            os.getenv('IDP_SSO_URL')
        json_settings['idp']['x509cert'] = os.getenv('IDP_CERT')
    return json_settings


def is_safe_url(target):
    ref_url = urlparse(request.host_url)
    test_url = urlparse(urljoin(request.host_url, target))
    return test_url.scheme in ('http', 'https') and \
        ref_url.netloc == test_url.netloc


def login_required(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        if (app.config['ENV'] is 'production' and
                'samlSessionIndex' not in session):
            return redirect(url_for('saml', sso=True, next=request.url))
        return f(*args, **kwargs)
    return decorated_function


def prepare_flask_request(request):
    url_data = urlparse(request.url)
    return {
        'https': 'on' if request.scheme == 'https' else 'off',
        'http_host': request.host,
        'server_port': url_data.port,
        'script_name': request.path,
        'get_data': request.args.copy(),
        'post_data': request.form.copy()
{'fraction_non_alphanumeric': 0.1428181321682141, 'fraction_numerical': 0.0032768978700163844, 'mean_word_length': 3.522222222222222, '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': '1594234', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1173, 'n_words': 226}