<commit_before>from vusion.error import VusionError

class CursorInstanciator(object):

    def __init__(self, cursor, instanciator_callback, failure_callbacks=[]):
        self.cursor = cursor
        self.instanciator_callback = instanciator_callback
        self.failure_callbacks = failure_callbacks

    def __iter__(self):
        return self

    def next(self):
        try:
            item = self.cursor.next()
            return self.instanciator_callback(**item)
        except VusionError as e:
            for failure_callback in self.failure_callbacks:
                failure_callback(e, item)

    def add_failure_callback(self, callback):
        self.failure_callbacks.append(callback)

    def __getattr__(self,attr):
        orig_attr = self.cursor.__getattribute__(attr)
        if callable(orig_attr):
            def hooked(*args, **kwargs):
                result = orig_attr(*args, **kwargs)
                # prevent wrapped_class from becoming unwrapped
                if result == self.cursor:<commit_msg>only StopIteration is not catch to keep iterator behavior<commit_after>from vusion.error import VusionError

class CursorInstanciator(object):

    def __init__(self, cursor, instanciator_callback, failure_callbacks=[]):
        self.cursor = cursor
        self.instanciator_callback = instanciator_callback
        self.failure_callbacks = failure_callbacks

    def __iter__(self):
        return self

    def next(self):
        try:
            item = self.cursor.next()
            return self.instanciator_callback(**item)
        except StopIteration as e:
            raise e
        except Exception as e:
            for failure_callback in self.failure_callbacks:
                failure_callback(e, item)

    def add_failure_callback(self, callback):
        self.failure_callbacks.append(callback)

    def __getattr__(self,attr):
        orig_attr = self.cursor.__getattribute__(attr)
        if callable(orig_attr):
            def hooked(*args, **kwargs):
                result = orig_attr(*args, **kwargs)
                # prevent wrapped_class from becoming unwrapped
                if result == self.cursor:
{'fraction_non_alphanumeric': 0.07798800184586986, 'fraction_numerical': 0.0, 'mean_word_length': 2.502423263327948, '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': '4136851', 'n_tokens_mistral': 596, 'n_tokens_neox': 561, 'n_words': 137}