<commit_before># genMixins copyright 2003 by <NAME> <http://cpbotha.net/>
# $Id: genMixins.py,v 1.5 2004/01/15 10:46:21 cpbotha Exp $

class subjectMixin(object):

    def __init__(self):
        self._observers = []

    def addObserver(self, observer):
        """Add an observer to this subject.

        observer is a function that takes the subject instance as parameter.
        """
        if not observer in self._observers:
            self._observers.append(observer)
            return self._observers.index(observer)

        else:
            return -1

    def close(self):
        del self._observers[:]

    def notify(self):
        for observer in self._observers:
            if callable(observer):
                observer(self)

    def removeObserver(self, observer):
        if observer in self._observers:
            self._observers.remove(observer)

class updateCallsExecuteModuleMixin(object):
    """The DeVIDE API requires that calling Update on outputData should
    ensure that that data is current.  This mixin does that by calling
    executeModule on the generating module when Update is invoked.
    """

    def __init__(self, d3Module):
        self._d3Module = d3Module

    def close(self):
        # get rid of our reference
        del self._d3Module

    def Update(self):
        """Part of our API.  If Update is called, we somehow have to make
        sure that we are current.
        """
        if self._d3Module:
            self._d3Module._moduleManager.executeModule(self._d3Module)


<commit_msg>Improvements with regards to inconsistency with observer ID.<commit_after># genMixins copyright 2003 by <NAME> <http://cpbotha.net/>
# $Id: genMixins.py,v 1.6 2004/08/12 16:47:48 cpbotha Exp $

class subjectMixin(object):

    def __init__(self):
        self._observers = []

    def addObserver(self, observer):
        """Add an observer to this subject.

        observer is a function that takes the subject instance as parameter.
        """
        if not observer in self._observers:
            self._observers.append(observer)
            return True

        else:
            return False

    def close(self):
        del self._observers[:]

    def notify(self):
        for observer in self._observers:
            if callable(observer):
                observer(self)

    def removeObserver(self, observer):
        if not callable(observer):
            print "WARNING: subjectMixin.removeObserver() invoked with " \
                  "non-callable."
            
        if observer in self._observers:
            self._observers.remove(observer)
            print "Successfully removed %s as observer." % (observer,)
            return True

        return False

class updateCallsExecuteModuleMixin(object):
    """The DeVIDE API requires that calling Update on outputData should
    ensure that that data is current.  This mixin does that by calling
    executeModule on the generating module when Update is invoked.
    """

    def __init__(self, d3Module):
        self._d3Module = d3Module

    def close(self):
        # get rid of our reference
        del self._d3Module

    def Update(self):
        """Part of our API.  If Update is called, we somehow have to make
        sure that we are current.
        """
        if self._d3Module:
            self._d3Module._moduleManager.executeModule(self._d3Module)



{'fraction_non_alphanumeric': 0.08016504568228706, 'fraction_numerical': 0.016209843796050692, 'mean_word_length': 2.2509578544061304, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7076022', 'n_tokens_mistral': 964, 'n_tokens_neox': 906, 'n_words': 309}