<commit_before>from flask.ext.restful_swagger import swagger
from CairisHTTPError import CairisHTTPError
from Borg import Borg
from flask import request, make_response, session
from flask.ext.restful import Resource
from tools.ModelDefinitions import UserConfigModel
from tools.SessionValidator import validate_proxy

__author__ = '<NAME>'


def set_dbproxy(conf):
    b = Borg()
    db_proxy = validate_proxy(None, -1, conf)
    pSettings = db_proxy.getProjectSettings()

    id = b.init_settings()
    session['session_id'] = id
    b.settings[id]['dbProxy'] = db_proxy
    b.settings[id]['dbUser'] = conf['user']
    b.settings[id]['dbPasswd'] = conf['<PASSWORD>']
    b.settings[id]['dbHost'] = conf['host']
    b.settings[id]['dbPort'] = conf['port']
    b.settings[id]['dbName'] = conf['db']
    b.settings[id]['fontSize'] = pSettings['Font Size']
    b.settings[id]['apFontSize'] = pSettings['AP Font Size']
    b.settings[id]['fontName'] = pSettings['Font Name']
    b.settings[id]['jsonPrettyPrint'] = conf.get('jsonPrettyPrint', False)

    return b.settings[id]

class UserConfigAPI(Resource):
    @swagger.operation(
        notes='Sets up the user session',
        nickname='user-config-post',
        parameters=[
            {
                'name': 'body',
                "description": "The configuration settings for the user's session",
                "required": True,
                "allowMultiple": False,
                'type': UserConfigModel.__name__,
                'paramType': 'body'
            }
        ],
        responseMessages=[
            {
                'code': 400,
                'message': 'The provided file is not a valid XML file'
            },
            {
                'code': 405,
                'message': '''Some parameters are missing.'''
            }
        ]
    )
    def post(self):
        try:<commit_msg>Implemented better exception raising<commit_after>from flask.ext.restful_swagger import swagger
from CairisHTTPError import CairisHTTPError
from Borg import Borg
from flask import request, make_response, session
from flask.ext.restful import Resource
from tools.ModelDefinitions import UserConfigModel
from tools.SessionValidator import validate_proxy

__author__ = '<NAME>'


def set_dbproxy(conf):
    b = Borg()
    db_proxy = validate_proxy(None, -1, conf)
    pSettings = db_proxy.getProjectSettings()

    id = b.init_settings()
    session['session_id'] = id
    b.settings[id]['dbProxy'] = db_proxy
    b.settings[id]['dbUser'] = conf['user']
    b.settings[id]['dbPasswd'] = conf['passwd']
    b.settings[id]['dbHost'] = conf['host']
    b.settings[id]['dbPort'] = conf['port']
    b.settings[id]['dbName'] = conf['db']
    b.settings[id]['fontSize'] = pSettings['Font Size']
    b.settings[id]['apFontSize'] = pSettings['AP Font Size']
    b.settings[id]['fontName'] = pSettings['Font Name']
    b.settings[id]['jsonPrettyPrint'] = conf.get('jsonPrettyPrint', False)

    return b.settings[id]

class UserConfigAPI(Resource):
    @swagger.operation(
        notes='Sets up the user session',
        nickname='user-config-post',
        parameters=[
            {
                'name': 'body',
                "description": "The configuration settings for the user's session",
                "required": True,
                "allowMultiple": False,
                'type': UserConfigModel.__name__,
                'paramType': 'body'
            }
        ],
        responseMessages=[
            {
                'code': 400,
                'message': 'The method is not callable without setting up a database connection'
            },
            {
                'code': 405,
                'message': 'The provided parameters are invalid'
            }
        ]
    )
    def post(self):
        try:
{'fraction_non_alphanumeric': 0.13110877561744613, 'fraction_numerical': 0.0036784025223331584, 'mean_word_length': 2.479890310786106, 'pattern_counts': {'":': 6, '<': 6, '<?xml version=': 0, '>': 6, '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': '6428522', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1067, 'n_words': 253}