<commit_before>import logging
import sdl2

import sdl2ui.ext


class BaseJoystick(sdl2ui.ext.Extension):
    logger = logging.getLogger(__name__)
    event_handlers = {
        sdl2.SDL_QUIT: 'close',
        sdl2.SDL_JOYDEVICEADDED: 'open',
        sdl2.SDL_JOYDEVICEREMOVED: 'close',
    }
    index = 0

    def init(self):
        sdl2.SDL_InitSubSystem(sdl2.SDL_INIT_JOYSTICK)
        for event_type, handler_name in self._all_event_handlers:
            self.app.register_event_handler(
                event_type, getattr(self, handler_name))

    def open(self, event):
        self.joystick = sdl2.SDL_JoystickOpen(self.index)
        if self.joystick:
            self.logger.info(
                "Joystick %d found: %s",
                self.index, sdl2.SDL_JoystickName(self.joystick).decode())
        else:
            self.logger.warning("Could not find joystick %d", self.index)

    def close(self, event):
        if sdl2.SDL_JoystickGetAttached(self.joystick):
            self.logger.info(
                "Joystick %d removed: %s",
                self.index, sdl2.SDL_JoystickName(self.joystick).decode())
            sdl2.SDL_JoystickClose(self.joystick)

    @property
    def _all_event_handlers(self):
        for cls in reversed(type(self).mro()):
            if hasattr(cls, 'event_handlers'):
                for k, v in cls.event_handlers.items():
                    yield (k, v)


class BaseKeyboardJoystick(BaseJoystick):
    event_handlers = {
        sdl2.SDL_JOYBUTTONDOWN: 'update_button',
    }
    mapping = {
    }

    def update_button(self, event):
        key = self.mapping.get(event.jbutton.button)<commit_msg>Rename method<commit_after>import logging
import sdl2

import sdl2ui.ext


class BaseJoystick(sdl2ui.ext.Extension):
    logger = logging.getLogger(__name__)
    event_handlers = {
        sdl2.SDL_QUIT: 'close',
        sdl2.SDL_JOYDEVICEADDED: 'open',
        sdl2.SDL_JOYDEVICEREMOVED: 'close',
    }
    index = 0

    def init(self):
        sdl2.SDL_InitSubSystem(sdl2.SDL_INIT_JOYSTICK)
        for event_type, handler_name in self._all_event_handlers:
            self.app.register_event_handler(
                event_type, getattr(self, handler_name))

    def open(self, event):
        self.joystick = sdl2.SDL_JoystickOpen(self.index)
        if self.joystick:
            self.logger.info(
                "Joystick %d found: %s",
                self.index, sdl2.SDL_JoystickName(self.joystick).decode())
        else:
            self.logger.warning("Could not find joystick %d", self.index)

    def close(self, event):
        if sdl2.SDL_JoystickGetAttached(self.joystick):
            self.logger.info(
                "Joystick %d removed: %s",
                self.index, sdl2.SDL_JoystickName(self.joystick).decode())
            sdl2.SDL_JoystickClose(self.joystick)

    @property
    def _all_event_handlers(self):
        for cls in reversed(type(self).mro()):
            if hasattr(cls, 'event_handlers'):
                for k, v in cls.event_handlers.items():
                    yield (k, v)


class BaseKeyboardJoystick(BaseJoystick):
    event_handlers = {
        sdl2.SDL_JOYBUTTONDOWN: 'button_down',
    }
    mapping = {
    }

    def button_down(self, event):
        key = self.mapping.get(event.jbutton.button)
{'fraction_non_alphanumeric': 0.10574018126888217, 'fraction_numerical': 0.00906344410876133, 'mean_word_length': 2.311, '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': '733776', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1069, 'n_words': 188}