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

from .Event import Event
from .APIEvents import *
import logging
import time


class APIBase(object):
    """Base class for API objects.

    See also the \"test\" API for an example.

    When creating an API, the class should be derived from APIBase.
    The custom API class must have the name \"API\"
    For example:
    api
    |- skype
    |- tox
    |- irc
    |  |
    |  |- __init__.py
    |  |- ircapi.py

    If ircapi.py contains the class IRCAPI, which is the, as the name says, the
    API to access IRC.
    IRCAPI should be derived from APIBase.
    To work properly, IRCAPI must be imported in __init__,py and renamed to
    \"API\", e.g. by using
        from ircapi import IRCAPI as API
    or by directly renaming IRCAPI to API.
    """

    def __init__(self):
        self._events = {}

    def attach(self):
        raise NotImplementedError

    def detach(self):
        raise NotImplementedError

    def iterate(self):
        """The main loop.
        
        Will sleep for 1 second by default.
        It will be called like
        while True:
            apiobj.iterate()
        """
        time.sleep(1)

    def version(self):
        raise NotImplementedError

    def api_name(self):
        raise NotImplementedError

    @staticmethod
    def get_default_options():
        """Return a dictionary with options and their default values for this API."""
        return {}

    def register_event_handler(self, event, callback):
        """Add an event handler to the given event.
        
        Available events can be found in the APIEvents class.
        The actual API implementation might offer additional events.
        """
        if not self._events.has_key(event):
            self._events[event] = Event()
        return self._events[event].add_handler(callback)

    def unregister_event_handler(self, event, callback):
        """Remove an event handler from the given event.
        
        See also register_event_handler().
        """
        self._events[event].del_handler(callback)

    def _trigger(self, event, *args):
        """Triggers the given event with the given arguments.
        
        Should be used instead of accessing self._events directly.
        """
        if self._events.has_key(event) and len(self._events[event]) > 0:
            self._events[event].trigger(*args)
        else:
            logging.debug("Unhandled event: " + str(event))

    def __str__(self):
        return "API: {}, version {}".format(self.api_name(), self.version())
<commit_msg>Reword docstring<commit_after># -*- coding: utf-8 -*-

from .Event import Event
from .APIEvents import *
import logging
import time


class APIBase(object):
    """Base class for API objects.

    See also the \"test\" API for an example.

    When creating an API, the class should be derived from APIBase.
    The custom API class must have the name \"API\".
    For example:
    api
    |- skype
    |- tox
    |- irc
    |  |
    |  |- __init__.py
    |  |- ircapi.py

    ircapi.py contains the class IRCAPI that is derived from APIBase.
    To work properly, IRCAPI must be imported in __init__,py and renamed to
    \"API\", e.g. by using
        from ircapi import IRCAPI as API
    or by directly renaming IRCAPI to API.
    """

    def __init__(self):
        self._events = {}

    def attach(self):
        raise NotImplementedError

    def detach(self):
        raise NotImplementedError

    def iterate(self):
        """The main loop.
        
        Will sleep for 1 second by default.
        It will be called like
        while True:
            apiobj.iterate()
        """
        time.sleep(1)

    def version(self):
        raise NotImplementedError

    def api_name(self):
        raise NotImplementedError

    @staticmethod
    def get_default_options():
        """Return a dictionary with options and their default values for this API."""
        return {}

    def register_event_handler(self, event, callback):
        """Add an event handler to the given event.
        
        Available events can be found in the APIEvents class.
        The actual API implementation might offer additional events.
        """
        if not self._events.has_key(event):
            self._events[event] = Event()
        return self._events[event].add_handler(callback)

    def unregister_event_handler(self, event, callback):
        """Remove an event handler from the given event.
        
        See also register_event_handler().
        """
        self._events[event].del_handler(callback)

    def _trigger(self, event, *args):
        """Triggers the given event with the given arguments.
        
        Should be used instead of accessing self._events directly.
        """
        if self._events.has_key(event) and len(self._events[event]) > 0:
            self._events[event].trigger(*args)
        else:
            logging.debug("Unhandled event: " + str(event))

    def __str__(self):
        return "API: {}, version {}".format(self.api_name(), self.version())

{'fraction_non_alphanumeric': 0.09182068423122297, 'fraction_numerical': 0.0015729453401494297, 'mean_word_length': 2.1913425345043915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3911347', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1367, 'n_words': 497}