<commit_before>"""Set up a bottle server to accept post requests commanding the drone."""
from bottle import post, run, hook, response, get, abort

from venthur_api import libardrone
from server.socket_drone import PORT


@hook('after_request')
def enable_cors():
    """Allow control headers."""
    response.headers['Access-Control-Allow-Origin'] = '*'


@get('/navdata')
def navdata(drone=None):
    """Return packet of navdata."""
    if drone is None:
        drone = GLOBAL_DRONE
    return drone.navdata


@post('/do/<command>')
def do(command, drone=None):
    """Execute the given command from the route."""
    if drone is None:
        drone = GLOBAL_DRONE
    try:
        print('Command received: {}'.format(command))
        getattr(drone, command)()
        print('Command executed: {}'.format(command))
        return 'Command executed: {}'.format(command)
    except AttributeError:
        print('Bad Command: {}'.format(command))
        abort(404, 'Bad Command: {}'.format(command))


if __name__ == "__main__":
    GLOBAL_DRONE = libardrone.ARDrone()
    try:
        run(host='127.0.0.1', port=PORT)
    finally:
        drone.land()
        drone.halt()<commit_msg>Fixed name error<commit_after>"""Set up a bottle server to accept post requests commanding the drone."""
from bottle import post, run, hook, response, get, abort

from venthur_api import libardrone
from server.socket_drone import PORT


@hook('after_request')
def enable_cors():
    """Allow control headers."""
    response.headers['Access-Control-Allow-Origin'] = '*'


@get('/navdata')
def navdata(drone=None):
    """Return packet of navdata."""
    if drone is None:
        drone = GLOBAL_DRONE
    return drone.navdata


@post('/do/<command>')
def do(command, drone=None):
    """Execute the given command from the route."""
    if drone is None:
        drone = GLOBAL_DRONE
    try:
        print('Command received: {}'.format(command))
        getattr(drone, command)()
        print('Command executed: {}'.format(command))
        return 'Command executed: {}'.format(command)
    except AttributeError:
        print('Bad Command: {}'.format(command))
        abort(404, 'Bad Command: {}'.format(command))


if __name__ == "__main__":
    GLOBAL_DRONE = libardrone.ARDrone()
    try:
        run(host='127.0.0.1', port=PORT)
    finally:
        GLOBAL_DRONE.land()
        GLOBAL_DRONE.halt()
{'fraction_non_alphanumeric': 0.14124529878813205, 'fraction_numerical': 0.007521938988717091, 'mean_word_length': 3.329113924050633, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '79768', 'n_tokens_mistral': 753, 'n_tokens_neox': 726, 'n_words': 203}