<commit_before>from __future__ import unicode_literals, division, absolute_import
from builtins import *  # pylint: disable=unused-import, redefined-builtin

from flask import jsonify
from flask_restplus import inputs
from flexget.api import api, APIResource
from flexget.api.app import BadRequest, NotFoundError, success_response, base_message_schema

irc_api = api.namespace('irc', description='View and manage IRC connections')

irc_parser = api.parser()
irc_parser.add_argument('name', help='Name of connection. Leave empty to apply to all connections.')


@irc_api.route('/connections/')
@api.doc(parser=irc_parser)
class IRCStatus(APIResource):
    @api.response(200)
    @api.response(NotFoundError)
    @api.response(BadRequest)
    def get(self, session=None):
        """Returns status of IRC connections"""
        from flexget.plugins.daemon.irc import irc_manager
        if irc_manager is None:
            raise BadRequest('IRC daemon does not appear to be running')

        args = irc_parser.parse_args()
        connection = args.get('name')
        if connection:
            try:
                status = irc_manager.status(connection)
            except ValueError as e:
                raise NotFoundError(e.args[0])
        else:
            status = irc_manager.status_all()
        return jsonify(status)


@irc_api.route('/restart/')
@api.doc(parser=irc_parser)
class IRCRestart(APIResource):
    @api.response(200, model=base_message_schema)
    @api.response(NotFoundError)
    @api.response(BadRequest)
    def get(self, session=None):
        """Restarts IRC connections"""
        from flexget.plugins.daemon.irc import irc_manager
        if irc_manager is None:
            raise BadRequest('IRC daemon does not appear to be running')

        args = irc_parser.parse_args()
        connection = args.get('name')
        try:
            if connection:
                irc_manager.restart_connection(connection)
            else:
                irc_manager.restart_connections()
        except KeyError:
            raise NotFoundError('Connection {} is not a valid IRC connection'.format(connection))
        return success_response('Successfully restarted connection(s)')


irc_stop_parser = irc_parser.copy()
irc_stop_parser.add_argument('wait', type=inputs.boolean, default=False, help='Wait for connection to exit gracefully')


@irc_api.route('/stop/')
@api.doc(parser=irc_stop_parser)
class IRCStop(APIResource):
    @api.response(200, model=base_message_schema)
    @api.response(NotFoundError)
    @api.response(BadRequest)
    def get(self, session=None):
        """Stops IRC connections"""
        from flexget.plugins.daemon.irc import irc_manager
        if irc_manager is None:
            raise BadRequest('IRC daemon does not appear to be running')

        args = irc_stop_parser.parse_args()
        connection = args.get('name')
        wait = args.get('wait')
        try:
            if connection:
                irc_manager.stop_connection(connection)
            else:
                irc_manager.stop_connections(wait)
        except KeyError:
            raise NotFoundError('Connection {} is not a valid IRC connection'.format(connection))
        return success_response('Successfully stopped connection(s)')
<commit_msg>Added enum dict<commit_after>from __future__ import unicode_literals, division, absolute_import
from builtins import *  # pylint: disable=unused-import, redefined-builtin

from flask import jsonify
from flask_restplus import inputs
from flexget.api import api, APIResource
from flexget.api.app import BadRequest, NotFoundError, success_response, base_message_schema, empty_response

irc_api = api.namespace('irc', description='View and manage IRC connections')

irc_parser = api.parser()
irc_parser.add_argument('name', help='Name of connection. Leave empty to apply to all connections.')


@irc_api.route('/connections/')
@api.doc(parser=irc_parser)
class IRCStatus(APIResource):
    @api.response(200)
    @api.response(NotFoundError)
    @api.response(BadRequest)
    def get(self, session=None):
        """Returns status of IRC connections"""
        from flexget.plugins.daemon.irc import irc_manager
        if irc_manager is None:
            raise BadRequest('IRC daemon does not appear to be running')

        args = irc_parser.parse_args()
        connection = args.get('name')
        if connection:
            try:
                status = irc_manager.status(connection)
            except ValueError as e:
                raise NotFoundError(e.args[0])
        else:
            status = irc_manager.status_all()
        return jsonify(status)


@irc_api.route('/connections/enums/')
class IRCEnums(APIResource):
    @api.response(200, model=empty_response)
    def get(self, session=None):
        """Get channel status enumeration meaning"""
        try:
            from irc_bot import irc_bot
        except ImportError:
            raise BadRequest('irc_bot dep is not installed')
        return jsonify(irc_bot.IRCChannelStatus().enum_dict)


@irc_api.route('/restart/')
@api.doc(parser=irc_parser)
class IRCRestart(APIResource):
    @api.response(200, model=base_message_schema)
    @api.response(NotFoundError)
    @api.response(BadRequest)
    def get(self, session=None):
        """Restarts IRC connections"""
        from flexget.plugins.daemon.irc import irc_manager
        if irc_manager is None:
            raise BadRequest('IRC daemon does not appear to be running')

        args = irc_parser.parse_args()
        connection = args.get('name')
        try:
            if connection:
                irc_manager.restart_connection(connection)
            else:
                irc_manager.restart_connections()
        except KeyError:
            raise NotFoundError('Connection {} is not a valid IRC connection'.format(connection))
        return success_response('Successfully restarted connection(s)')


irc_stop_parser = irc_parser.copy()
irc_stop_parser.add_argument('wait', type=inputs.boolean, default=False, help='Wait for connection to exit gracefully')


@irc_api.route('/stop/')
@api.doc(parser=irc_stop_parser)
class IRCStop(APIResource):
    @api.response(200, model=base_message_schema)
    @api.response(NotFoundError)
    @api.response(BadRequest)
    def get(self, session=None):
        """Stops IRC connections"""
        from flexget.plugins.daemon.irc import irc_manager
        if irc_manager is None:
            raise BadRequest('IRC daemon does not appear to be running')

        args = irc_stop_parser.parse_args()
        connection = args.get('name')
        wait = args.get('wait')
        try:
            if connection:
                irc_manager.stop_connection(connection)
            else:
                irc_manager.stop_connections(wait)
        except KeyError:
            raise NotFoundError('Connection {} is not a valid IRC connection'.format(connection))
        return success_response('Successfully stopped connection(s)')

{'fraction_non_alphanumeric': 0.09526534115291088, 'fraction_numerical': 0.003289944213989415, 'mean_word_length': 3.0769679300291544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2729768', 'n_tokens_mistral': 2034, 'n_tokens_neox': 1924, 'n_words': 485}