Exemple #1
0
#---------------------------------------------------------------------------

from core.datamsg import Message

#---------------------------------------------------------------------------

def setupForTesting():
    """This is used only by testing modules. Use at your own risk ;)"""
    global TopicTreeRoot, TopicTreeNode, paramMinCount, setDeadCallback
    TopicTreeRoot = _TopicTreeRoot
    TopicTreeNode = _TopicTreeNode
    paramMinCount = _paramMinCount

    def _setDeadCallback(newCallback):
        """When a message is sent via sendMessage(), the listener is tested 
        for "livelyhood" (ie there must be at least one place in your code 
        that is still referring to it). If it is dead, newCallback will be 
        called as newCallback(weakref), where weakref is the weak reference
        object created for the listener when the listener subscribed. 
        This is useful primarily for testing."""
        _NodeCallback.preNotify = newCallback

    setDeadCallback = _setDeadCallback

#---------------------------------------------------------------------------

import pubsubconf
pubsubconf.pubModuleLoaded()
del pubsubconf
Exemple #2
0
        message of type 'cls.childA.subChildB' is sent, listeners of 
        type cls.childA and of type cls get it too. '''
        # parent:
        if parents:
            cls._parentClass = parents[-1]
            lineage = parents[:] + [cls]
            cls._type = '.'.join(item.__name__ for item in lineage)
            if _log:
                _log('%s will chain up to %s\n' %
                     (cls._type, cls._parentClass.getType()))
        else:
            cls._parentClass = None
            lineage = [cls]
            cls._type = cls.__name__
            if _log:
                _log('%s is at root (top) of messaging tree\n' % cls._type)

        # go down into children:
        cls._childrenClasses = []
        for childName, child in vars(cls).iteritems():
            if (not childName.startswith('_')) and issubclass(child, Message):
                cls._childrenClasses.append(child)
                child._setupChaining(lineage)


#---------------------------------------------------------------------------

import pubsubconf
pubsubconf.pubModuleLoaded()
del pubsubconf