<commit_before># -*- coding: utf-8 -*-

# FOGLAMP_BEGIN
# See: http://foglamp.readthedocs.io/
# FOGLAMP_END

from aiohttp import web
from foglamp.core.api import common as api_commom
from foglamp.core.api import configuration as api_configuration
from foglamp.core.api import scheduler as api_scheduler
from foglamp.core.api import statistics as api_statistics
from foglamp.core.api import audit as api_audit
from foglamp.core.api import browser

__author__ = "<NAME>, <NAME>"
__copyright__ = "Copyright (c) 2017 OSIsoft, LLC"
__license__ = "Apache 2.0"
__version__ = "${VERSION}"


def setup(app):
    # app.router.add_route('POST', '/foglamp/a-post-req', api_a_post_req, expect_handler = aiohttp.web.Request.json)
    app.router.add_route('GET', '/foglamp/ping', api_commom.ping)

    # Configuration
    app.router.add_route('GET', '/foglamp/categories', api_configuration.get_categories)
    app.router.add_route('GET', '/foglamp/category/{category_name}', api_configuration.get_category)
    app.router.add_route('GET', '/foglamp/category/{category_name}/{config_item}', api_configuration.get_category_item)
    app.router.add_route('PUT', '/foglamp/category/{category_name}/{config_item}', api_configuration.set_configuration_item,
                         expect_handler=web.Request.json)
    app.router.add_route('DELETE', '/foglamp/category/{category_name}/{config_item}', api_configuration.set_configuration_item)

    # Scheduler
    # Scheduled_processes - As per doc
    app.router.add_route('GET', '/foglamp/scheduled/processes', api_scheduler.get_scheduled_processes)
    app.router.add_route('GET', '/foglamp/scheduled/process/{scheduled_process_name}', api_scheduler.get_scheduled_process)

    # Schedules - As per doc
    app.router.add_route('GET', '/foglamp/schedules', api_scheduler.get_schedules)
    app.router.add_route('POST', '/foglamp/schedule', api_scheduler.post_schedule)
    app.router.add_route('GET', '/foglamp/schedule/{schedule_id}', api_scheduler.get_schedule)
    app.router.add_route('GET', '/foglamp/schedule/start/{schedule_id}', api_scheduler.start_schedule)
    app.router.add_route('PUT', '/foglamp/schedule/{schedule_id}', api_scheduler.update_schedule)
    app.router.add_route('DELETE', '/foglamp/schedule/{schedule_id}', api_scheduler.delete_schedule)

    # Tasks - As per doc
    app.router.add_route('GET', '/foglamp/tasks', api_scheduler.get_tasks)
    app.router.add_route('GET', '/foglamp/tasks/latest', api_scheduler.get_tasks_latest)
    app.router.add_route('GET', '/foglamp/tasks/running', api_scheduler.get_tasks_running)
    app.router.add_route('GET', '/foglamp/task/{task_id}', api_scheduler.get_task)
    # TODO: Find out why not DELETE/PUT a task? Cancel flag can be handled in database update.
    app.router.add_route('POST', '/foglamp/task/{task_id}/cancel', api_scheduler.cancel_task)

    browser.setup(app)

    # Statistics - As per doc
    app.router.add_route('GET', '/foglamp/statistics', api_statistics.get_statistics)
    app.router.add_route('GET', '/foglamp/statistics/history', api_statistics.get_statistics_history)

    # Audit trail - As per doc
    app.router.add_route('GET', '/foglamp/audit', api_audit.get_audit_entries)

    # enable cors support
    # enable_cors(app)

    # enable a live debugger (watcher) for requests, see https://github.com/aio-libs/aiohttp-debugtoolbar
    # this will neutralize error middleware
    # Note: pip install aiohttp_debugtoolbar

    # enable_debugger(app)


def enable_cors(app):
    """ implements Cross Origin Resource Sharing (CORS) support """
    import aiohttp_cors

    # Configure default CORS settings.
    cors = aiohttp_cors.setup(app, defaults={
        "*": aiohttp_cors.ResourceOptions(
            allow_credentials=True,
            expose_headers="*",
            allow_headers="*",
        )
    })

    # Configure CORS on all routes.
    for route in list(app.router.routes()):
        cors.add(route)


def enable_debugger(app):<commit_msg>Minor omission, accidently changed, now fixed.<commit_after># -*- coding: utf-8 -*-

# FOGLAMP_BEGIN
# See: http://foglamp.readthedocs.io/
# FOGLAMP_END

from aiohttp import web
from foglamp.core.api import common as api_commom
from foglamp.core.api import configuration as api_configuration
from foglamp.core.api import scheduler as api_scheduler
from foglamp.core.api import statistics as api_statistics
from foglamp.core.api import audit as api_audit
from foglamp.core.api import browser

__author__ = "<NAME>, <NAME>"
__copyright__ = "Copyright (c) 2017 OSIsoft, LLC"
__license__ = "Apache 2.0"
__version__ = "${VERSION}"


def setup(app):
    # app.router.add_route('POST', '/foglamp/a-post-req', api_a_post_req, expect_handler = aiohttp.web.Request.json)
    app.router.add_route('GET', '/foglamp/ping', api_commom.ping)

    # Configuration
    app.router.add_route('GET', '/foglamp/categories', api_configuration.get_categories)
    app.router.add_route('GET', '/foglamp/category/{category_name}', api_configuration.get_category)
    app.router.add_route('GET', '/foglamp/category/{category_name}/{config_item}', api_configuration.get_category_item)
    app.router.add_route('PUT', '/foglamp/category/{category_name}/{config_item}', api_configuration.set_configuration_item,
                         expect_handler=web.Request.json)
    app.router.add_route('DELETE', '/foglamp/category/{category_name}/{config_item}', api_configuration.set_configuration_item)

    # Scheduler
    # Scheduled_processes - As per doc
    app.router.add_route('GET', '/foglamp/scheduled/processes', api_scheduler.get_scheduled_processes)
    app.router.add_route('GET', '/foglamp/scheduled/process/{scheduled_process_name}', api_scheduler.get_scheduled_process)

    # Schedules - As per doc
    app.router.add_route('GET', '/foglamp/schedules', api_scheduler.get_schedules)
    app.router.add_route('POST', '/foglamp/schedule', api_scheduler.post_schedule)
    app.router.add_route('GET', '/foglamp/schedule/{schedule_id}', api_scheduler.get_schedule)
    app.router.add_route('GET', '/foglamp/schedule/start/{schedule_id}', api_scheduler.start_schedule)
    app.router.add_route('PUT', '/foglamp/schedule/{schedule_id}', api_scheduler.update_schedule)
    app.router.add_route('DELETE', '/foglamp/schedule/{schedule_id}', api_scheduler.delete_schedule)

    # Tasks - As per doc
    app.router.add_route('GET', '/foglamp/tasks', api_scheduler.get_tasks)
    app.router.add_route('GET', '/foglamp/tasks/latest', api_scheduler.get_tasks_latest)
    app.router.add_route('GET', '/foglamp/tasks/running', api_scheduler.get_tasks_running)
    app.router.add_route('GET', '/foglamp/task/{task_id}', api_scheduler.get_task)
    # TODO: Find out why not DELETE/PUT a task? Cancel flag can be handled in database update.
    app.router.add_route('POST', '/foglamp/task/{task_id}/cancel', api_scheduler.cancel_task)

    browser.setup(app)

    # Statistics - As per doc
    app.router.add_route('GET', '/foglamp/statistics', api_statistics.get_statistics)
    app.router.add_route('GET', '/foglamp/statistics/history', api_statistics.get_statistics_history)

    # Audit trail - As per doc
    app.router.add_route('GET', '/foglamp/audit', api_audit.get_audit_entries)

    # enable cors support
    enable_cors(app)

    # enable a live debugger (watcher) for requests, see https://github.com/aio-libs/aiohttp-debugtoolbar
    # this will neutralize error middleware
    # Note: pip install aiohttp_debugtoolbar

    # enable_debugger(app)


def enable_cors(app):
    """ implements Cross Origin Resource Sharing (CORS) support """
    import aiohttp_cors

    # Configure default CORS settings.
    cors = aiohttp_cors.setup(app, defaults={
        "*": aiohttp_cors.ResourceOptions(
            allow_credentials=True,
            expose_headers="*",
            allow_headers="*",
        )
    })

    # Configure CORS on all routes.
    for route in list(app.router.routes()):
        cors.add(route)


def enable_debugger(app):
{'fraction_non_alphanumeric': 0.12945145570411096, 'fraction_numerical': 0.0017493439960014994, 'mean_word_length': 4.386271870794078, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '5811255', 'n_tokens_mistral': 2714, 'n_tokens_neox': 2640, 'n_words': 464}