<commit_before>import struct
import logging
import threading
import time


logger = logging.getLogger(__name__)


class EmcyConsumer(object):

    # Error code, error register, vendor specific data
    EMCY_STRUCT = struct.Struct("<HB5s")

    def __init__(self):
        #: Log of all received EMCYs for this node
        self.log = []
        #: Only active EMCYs. Will be cleared on Error Reset
        self.active = []
        self.callbacks = []
        self.emcy_received = threading.Condition()

    def on_emcy(self, can_id, data, timestamp):
        code, register, data = self.EMCY_STRUCT.unpack(data)
        entry = EmcyError(code, register, data, timestamp)

        with self.emcy_received:
             self.log.append(entry)
             self.active.append(entry)
             self.emcy_received.notify_all()

        if code & 0xFFFF == 0:
            # Error reset
            self.active = []
            for callback in self.callbacks:
                callback(None)
        else:
            for callback in self.callbacks:
                callback(entry)

    def add_callback(self, callback):
        """Get notified on EMCY messages from this node.

        :param callback:
            Callable which must take one argument of an
            :class:`~canopen.emcy.EmcyError` instance or ``None`` if an
            error reset is received.
        """
        self.callbacks.append(callback)

    def reset(self):
        """Reset log and active lists."""
        self.log = []
        self.active = []

    def wait(self, emcy_code=None, timeout=10):
        """Wait for a new EMCY to arrive.

        :param int emcy_code: EMCY code to wait for
        :param float timeout: Max time in seconds to wait

        :return: The EMCY exception object or None if timeout
        :rtype: canopen.emcy.EmcyError
        """
        end_time = time.time() + timeout
        while True:
            with self.emcy_received:
                prev_log_size = len(self.log)
                self.emcy_received.wait(timeout)<commit_msg>Represent EMCY reset as EmcyError objects as well<commit_after>import struct
import logging
import threading
import time


logger = logging.getLogger(__name__)


class EmcyConsumer(object):

    # Error code, error register, vendor specific data
    EMCY_STRUCT = struct.Struct("<HB5s")

    def __init__(self):
        #: Log of all received EMCYs for this node
        self.log = []
        #: Only active EMCYs. Will be cleared on Error Reset
        self.active = []
        self.callbacks = []
        self.emcy_received = threading.Condition()

    def on_emcy(self, can_id, data, timestamp):
        code, register, data = self.EMCY_STRUCT.unpack(data)
        entry = EmcyError(code, register, data, timestamp)

        with self.emcy_received:
            if code & 0xFF00 == 0:
                # Error reset
                self.active = []
            else:
                self.active.append(entry)
            self.log.append(entry)
            self.emcy_received.notify_all()

        for callback in self.callbacks:
            callback(entry)

    def add_callback(self, callback):
        """Get notified on EMCY messages from this node.

        :param callback:
            Callable which must take one argument of an
            :class:`~canopen.emcy.EmcyError` instance.
        """
        self.callbacks.append(callback)

    def reset(self):
        """Reset log and active lists."""
        self.log = []
        self.active = []

    def wait(self, emcy_code=None, timeout=10):
        """Wait for a new EMCY to arrive.

        :param int emcy_code: EMCY code to wait for
        :param float timeout: Max time in seconds to wait

        :return: The EMCY exception object or None if timeout
        :rtype: canopen.emcy.EmcyError
        """
        end_time = time.time() + timeout
        while True:
            with self.emcy_received:
                prev_log_size = len(self.log)
                self.emcy_received.wait(timeout)
{'fraction_non_alphanumeric': 0.08927680798004987, 'fraction_numerical': 0.0029925187032418953, 'mean_word_length': 2.004494382022472, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5237437', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1108, 'n_words': 337}