<commit_before>import os
from flask import Flask, jsonify, request
from tinydb import TinyDB, where

class Driver:
    '''
        Holds the driver state so the flasked script can change behaviour based
        on what the user injects via HTTP
    '''
    name = None
    base_path = None
    db = None

    def root(self, base_path):
        self.base_path = base_path

    def start(self, name):
        filename = os.path.join(self.base_path,
                                "{}.yaml".format(name))

        if not os.path.exists(filename):
            return {"state": "error", "message": "Driver {} not found".format(filename)}

        self.name = name
        self.db = TinyDB(os.path.join(self.base_path,
                                      "{}-store.json".format(name)))

        return {"driver": self.name, "state": "started"}

    def stop(self):
        if self.name == None:
            return {"driver": None, "state": None}

        message = {"driver": self.name, "state": "stopped"}
        self.name = None
        self.db.close()
        self.db = None
        return message

    def state(self):
        if self.name == None:
            return {"driver": None, "state": None}

        return {"driver": self.name, "state": "running"}

driver_host = "proxapp"
driver_port = 5000
driver_endpoint = "http://{}:{}".format(driver_host, driver_port)
app = Flask(driver_host)
app.host = '127.0.0.1'
driver = Driver()

def register(context):
    driver.root(context.source_dir)
    context.app_registry.add(app, driver_host, driver_port)
    return context

# Links use https://tools.ietf.org/html/rfc6570 URI templates
# The data structure is close to JSON API http://jsonapi.org/
@app.route('/', defaults={"path": ""})
@app.route('/<path:path>/')
def index(path):
    return jsonify({"links": {"start": "/{driver}/start/",
                              "stop": "/stop/",
                              "state": "/state/"}})

@app.route('/state/')
def state():
    message = driver.state()
    print(message)
    return jsonify(message)

@app.route('/stop/')
def stop_driver():
    message = driver.stop()<commit_msg>Fix index API documentation<commit_after>import os
from flask import Flask, jsonify, request
from tinydb import TinyDB, where

class Driver:
    '''
        Holds the driver state so the flasked script can change behaviour based
        on what the user injects via HTTP
    '''
    name = None
    base_path = None
    db = None

    def root(self, base_path):
        self.base_path = base_path

    def start(self, name):
        filename = os.path.join(self.base_path,
                                "{}.yaml".format(name))

        if not os.path.exists(filename):
            return {"state": "error", "message": "Driver {} not found".format(filename)}

        self.name = name
        self.db = TinyDB(os.path.join(self.base_path,
                                      "{}-store.json".format(name)))

        return {"driver": self.name, "state": "started"}

    def stop(self):
        if self.name == None:
            return {"driver": None, "state": None}

        message = {"driver": self.name, "state": "stopped"}
        self.name = None
        self.db.close()
        self.db = None
        return message

    def state(self):
        if self.name == None:
            return {"driver": None, "state": None}

        return {"driver": self.name, "state": "running"}

driver_host = "proxapp"
driver_port = 5000
driver_endpoint = "http://{}:{}".format(driver_host, driver_port)
app = Flask(driver_host)
app.host = '127.0.0.1'
driver = Driver()

def register(context):
    driver.root(context.source_dir)
    context.app_registry.add(app, driver_host, driver_port)
    return context

# Links use https://tools.ietf.org/html/rfc6570 URI templates
# The data structure is close to JSON API http://jsonapi.org/
@app.route('/', defaults={"path": ""})
@app.route('/<path:path>/')
def index(path):
    return jsonify({"links": {"start": "/{driver}/start/",
                              "stop": "/stop/",
                              "state": "/state/",
                              "exceptions": "/{driver}/exceptions/"}})

@app.route('/state/')
def state():
    message = driver.state()
    print(message)
    return jsonify(message)

@app.route('/stop/')
def stop_driver():
    message = driver.stop()
{'fraction_non_alphanumeric': 0.14955203308063406, 'fraction_numerical': 0.006432345508844475, 'mean_word_length': 2.3110266159695816, 'pattern_counts': {'":': 35, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1835281', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1286, 'n_words': 342}