<commit_before>from flask import Flask, jsonify
from flask.ext import restful
from .flask import auth

API_VERSION = '1'
config = None

def jsonify_nl(*args, **kwargs):
    resp = jsonify(*args, **kwargs)
    resp.set_data(resp.get_data() + b'\n')
    return resp


def app(config):
    auth.Username  = config['Webserver'].get('Username')
    auth.Password  = config['Webserver'].get('Password')

    app = Flask(config['Webserver'].get('BasicRealm'))
    auth.for_all_routes(app)
    app.config['SERVER_NAME'] = config['Webserver'].get('ServerName')

    api = restful.Api(
        app = app,
        prefix = '/v{}'.format(API_VERSION)
    )

    if config['Modules'].getboolean('PXE'):
        from . import pxe
        api.add_resource(pxe.PXECollection, '/pxe')
        api.add_resource(pxe.PXEObject, '/pxe/<ip_address>')

    if config['Modules'].getboolean('VM'):
        from . import vm
        api.add_resource(vm.VMCollection, '/vm')
        api.add_resource(vm.VMObject, '/vm/<uuid>')
        api.add_resource(vm.VMCommand, '/vm/<uuid>/action')

    @app.errorhandler(404)
    def not_found(ex):
        resp = jsonify_nl(message="Route not found.", status=404)
        resp.status_code = 404
        return resp
<commit_msg>Add endpoint v1/installimage/<mac> to webserver<commit_after>from flask import Flask, jsonify
from flask.ext import restful
from .flask import auth

API_VERSION = '1'
config = None

def jsonify_nl(*args, **kwargs):
    resp = jsonify(*args, **kwargs)
    resp.set_data(resp.get_data() + b'\n')
    return resp


def app(config):
    auth.Username  = config['Webserver'].get('Username')
    auth.Password  = config['Webserver'].get('Password')

    app = Flask(config['Webserver'].get('BasicRealm'))
    auth.for_all_routes(app)
    app.config['SERVER_NAME'] = config['Webserver'].get('ServerName')

    api = restful.Api(
        app = app,
        prefix = '/v{}'.format(API_VERSION)
    )

    if config['Modules'].getboolean('PXE'):
        from . import pxe
        api.add_resource(pxe.PXECollection, '/pxe')
        api.add_resource(pxe.PXEObject, '/pxe/<ip_address>')

    if config['Modules'].getboolean('VM'):
        from . import vm
        api.add_resource(vm.VMCollection, '/vm')
        api.add_resource(vm.VMObject, '/vm/<uuid>')
        api.add_resource(vm.VMCommand, '/vm/<uuid>/action')

    if config['Modules'].getboolean('INSTALLIMAGE'):
        from . import installimage
        api.add_resource(installimage.InstallimageObject, '/installimage/<mac>')

    @app.errorhandler(404)
    def not_found(ex):
        resp = jsonify_nl(message="Route not found.", status=404)
        resp.status_code = 404
        return resp

{'fraction_non_alphanumeric': 0.15436241610738255, 'fraction_numerical': 0.007829977628635347, 'mean_word_length': 3.2185534591194966, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1053624', 'n_tokens_mistral': 906, 'n_tokens_neox': 879, 'n_words': 163}