<commit_before>import os
import markdown
import yaml
from flask import render_template, render_template_string, session, request
from .. import main
from application import application
from app.main import errors
from app.authentication.jwt_decoder import Decoder, NoTokenException, InvalidTokenException
import os

rrm_public_key_file = os.getenv('RRM_PUBLIC_KEY', './jwt-test-keys/rrm-public.pem')
sr_private_key_file = os.getenv('SR_PRIVATE_KEY', './jwt-test-keys/sr-private.pem')


with open(rrm_public_key_file, "rb") as public_key_file:
    rmm_public_key = public_key_file.read()

with open(sr_private_key_file, "rb") as private_key_file:
    sr_private_key = private_key_file.read()

decoder = Decoder(rmm_public_key, sr_private_key, "digitaleq")


# TODO Put this back in
# @main.before_request
def jwt_decrypt():
    try:
        encrypted_token = request.args.get('token')
        token = decoder.decrypt_jwt_token(encrypted_token)
        return render_template('index.html')
    except NoTokenException as e:
        return errors.unauthorized(e)
    except InvalidTokenException as e:
        return errors.forbidden(e)


def jwt_decode_signed():
    try:
        signed_token = request.args.get('token')
        token = decoder.decode_signed_jwt_token(signed_token)
        return render_template('index.html')
    except NoTokenException as e:
        return errors.unauthorized(e)
    except InvalidTokenException as e:
        return errors.forbidden(e)


def jwt_decode():
    try:
        token = request.args.get('token')
        token = decoder.decode_jwt_token(token)
        print(token)
        return render_template('index.html')
    except NoTokenException as e:
        return errors.unauthorized(e)
    except InvalidTokenException as e:
        return errors.forbidden(e)


@main.route('/', methods=['GET'])
def root():
    return render_template('index.html')


@main.route('/jwt', methods=['GET'])
def jwt():
    return jwt_decode()


@main.route('/jwt_signed', methods=['GET'])
def jwt_signed():
    return jwt_decode_signed()


@main.route('/jwt_encrypted', methods=['GET'])
def jwt_encrypted_key_exchange():
    return jwt_decrypt()

@main.route('/patterns/')
@main.route('/patterns/<pattern>')
def patterns(pattern='index'):
    sections = []
    pattern_name = 'grid-system' if (pattern == 'index') else pattern
    for root, dirs, files in os.walk('app/templates/patterns/components'):
        for file in files:
            if file.endswith('.html'):
                with open(os.path.join(root, file), 'r') as f:
                    title = file.replace('.html', '')
                    sections.append({
                        'title': title,
                        'current': True if (title == pattern) else False
                    })
    return render_template('patterns/index.html', sections=sections, pattern_include='patterns/components/' + pattern_name + '.html', title=pattern)<commit_msg>Updating imports<commit_after>from flask import render_template, request
from .. import main
from app.main import errors
from app.authentication.jwt_decoder import Decoder
from app.authentication.invalid_token_exception import InvalidTokenException
from app.authentication.no_token_exception import NoTokenException
import os

rrm_public_key_file = os.getenv('RRM_PUBLIC_KEY', './jwt-test-keys/rrm-public.pem')
sr_private_key_file = os.getenv('SR_PRIVATE_KEY', './jwt-test-keys/sr-private.pem')


with open(rrm_public_key_file, "rb") as public_key_file:
    rmm_public_key = public_key_file.read()

with open(sr_private_key_file, "rb") as private_key_file:
    sr_private_key = private_key_file.read()

decoder = Decoder(rmm_public_key, sr_private_key, "digitaleq")


# @main.before_request
def jwt_decrypt():
    try:
        encrypted_token = request.args.get('token')
        token = decoder.decrypt_jwt_token(encrypted_token)
        return render_template('index.html')
    except NoTokenException as e:
        return errors.unauthorized(e)
    except InvalidTokenException as e:
        return errors.forbidden(e)


def jwt_decode_signed():
    try:
        signed_token = request.args.get('token')
        token = decoder.decode_signed_jwt_token(signed_token)
        return render_template('index.html')
    except NoTokenException as e:
        return errors.unauthorized(e)
    except InvalidTokenException as e:
        return errors.forbidden(e)


def jwt_decode():
    try:
        token = request.args.get('token')
        token = decoder.decode_jwt_token(token)
        print(token)
        return render_template('index.html')
    except NoTokenException as e:
        return errors.unauthorized(e)
    except InvalidTokenException as e:
        return errors.forbidden(e)


@main.route('/', methods=['GET'])
def root():
    return render_template('index.html')


@main.route('/jwt', methods=['GET'])
def jwt():
    return jwt_decode()


@main.route('/jwt_signed', methods=['GET'])
def jwt_signed():
    return jwt_decode_signed()


@main.route('/jwt_encrypted', methods=['GET'])
def jwt_encrypted_key_exchange():
    return jwt_decrypt()


@main.route('/patterns/')
@main.route('/patterns/<pattern>')
def patterns(pattern='index'):
    sections = []
    pattern_name = 'grid-system' if (pattern == 'index') else pattern
    for root, dirs, files in os.walk('app/templates/patterns/components'):
        for file in files:
            if file.endswith('.html'):
                with open(os.path.join(root, file), 'r') as f:
                    title = file.replace('.html', '')
                    sections.append({
                        'title': title,
                        'current': True if (title == pattern) else False
                    })
    return render_template('patterns/index.html', sections=sections, pattern_include='patterns/components/' + pattern_name + '.html', title=pattern)
{'fraction_non_alphanumeric': 0.1196245733788396, 'fraction_numerical': 0.0, 'mean_word_length': 3.430083144368859, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3476511', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1771, 'n_words': 387}