<commit_before>"""FunctionInterval module: contains the FunctionInterval class"""

from PandaModules import *
from MessengerGlobal import *
from DirectNotifyGlobal import *
import Interval
import types


#############################################################
###                                                       ###
### See examples of function intervals in IntervalTest.py ###
###                                                       ###
#############################################################

class FunctionInterval(Interval.Interval):
    # Name counter
    functionIntervalNum = 1

    # create FunctionInterval DirectNotify category
    notify = directNotify.newCategory('FunctionInterval')

    # Class methods
    def __init__(self, function, name = None, openEnded = 1, extraArgs = []):
        """__init__(function, name = None)
        """
        # Record instance variables
        self.function = function
        # Create a unique name for the interval if necessary
        if (name == None):
            name = 'Func-%s-%d' % (function.__name__, FunctionInterval.functionIntervalNum)
            FunctionInterval.functionIntervalNum += 1
        assert(isinstance(name, types.StringType))
        # Record any arguments
        self.extraArgs = extraArgs
        # Initialize superclass
        # Set openEnded true if privInitialize after end time cause interval
        # function to be called.  If false, privInitialize calls have no effect
        # Event, Accept, Ignore intervals default to openEnded = 0
        # Parent, Pos, Hpr, etc intervals default to openEnded = 1
        Interval.Interval.__init__(self, name, duration = 0.0, openEnded = openEnded)
    
    def privInstant(self):
        # Evaluate the function
        apply(self.function, self.extraArgs)
        # Print debug information
        self.notify.debug(
            'updateFunc() - %s: executing Function' % self.name)

### FunctionInterval subclass for throwing events ###
class EventInterval(FunctionInterval):
    # Initialization
    def __init__(self, event, sentArgs=[]):
        """__init__(event, sentArgs)
        """
        def sendFunc(event = event, sentArgs = sentArgs):
            messenger.send(event, sentArgs)
        # Create function interval
        FunctionInterval.__init__(self, sendFunc, name = event,
                                  openEnded = 0)

### FunctionInterval subclass for accepting hooks ###
class AcceptInterval(FunctionInterval):
    # Initialization
    def __init__(self, dirObj, event, function, name = None):
        """__init__(dirObj, event, function, name)<commit_msg>pass most keyword arguments through to function<commit_after>"""FunctionInterval module: contains the FunctionInterval class"""

from PandaModules import *
from MessengerGlobal import *
from DirectNotifyGlobal import *
import Interval
import types


#############################################################
###                                                       ###
### See examples of function intervals in IntervalTest.py ###
###                                                       ###
#############################################################

class FunctionInterval(Interval.Interval):
    # Name counter
    functionIntervalNum = 1

    # create FunctionInterval DirectNotify category
    notify = directNotify.newCategory('FunctionInterval')

    # Class methods
    def __init__(self, function, **kw):
        """__init__(function, name = None, openEnded = 1, extraArgs = [])
        """
        name = kw.get('name', None)
        openEnded = kw.get('openEnded', 1)
        extraArgs = kw.get('extraArgs', [])
        if kw.has_key('name'):
            del kw['name']
        if kw.has_key('openEnded'):
            del kw['openEnded']
        if kw.has_key('extraArgs'):
            del kw['extraArgs']
        
        # Record instance variables
        self.function = function
        # Create a unique name for the interval if necessary
        if (name == None):
            name = 'Func-%s-%d' % (function.__name__, FunctionInterval.functionIntervalNum)
            FunctionInterval.functionIntervalNum += 1
        assert(isinstance(name, types.StringType))
        # Record any arguments
        self.extraArgs = extraArgs
        self.kw = kw
        # Initialize superclass
        # Set openEnded true if privInitialize after end time cause interval
        # function to be called.  If false, privInitialize calls have no effect
        # Event, Accept, Ignore intervals default to openEnded = 0
        # Parent, Pos, Hpr, etc intervals default to openEnded = 1
        Interval.Interval.__init__(self, name, duration = 0.0, openEnded = openEnded)
    
    def privInstant(self):
        # Evaluate the function
        self.function(*self.extraArgs, **self.kw)
        # Print debug information
        self.notify.debug(
            'updateFunc() - %s: executing Function' % self.name)

### FunctionInterval subclass for throwing events ###
class EventInterval(FunctionInterval):
    # Initialization
    def __init__(self, event, sentArgs=[]):
        """__init__(event, sentArgs)
        """
        def sendFunc(event = event, sentArgs = sentArgs):
            messenger.send(event, sentArgs)
        # Create function interval
        FunctionInterval.__init__(self, sendFunc, name = event,
                                  openEnded = 0)

### FunctionInterval subclass for accepting hooks ###
class AcceptInterval(FunctionInterval):
    # Initialization
    def __init__(self, dirObj, event, function, name = None):
        """__init__(dirObj, event, function, name)
{'fraction_non_alphanumeric': 0.1321991848307638, 'fraction_numerical': 0.003012581959950381, 'mean_word_length': 2.5744141861937937, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7306180', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1326, 'n_words': 410}