当前位置: 首页>>代码示例>>Python>>正文


Python AssimEvent.registerobserver方法代码示例

本文整理汇总了Python中assimevent.AssimEvent.registerobserver方法的典型用法代码示例。如果您正苦于以下问题:Python AssimEvent.registerobserver方法的具体用法?Python AssimEvent.registerobserver怎么用?Python AssimEvent.registerobserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在assimevent.AssimEvent的用法示例。


在下文中一共展示了AssimEvent.registerobserver方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import registerobserver [as 别名]
    def __init__(self, constraints):
        '''Initializer for AssimEventObserver class.

        Parameters:
        -----------
        constraints: dict-like *or* callable() returning bool
            A dict describing our desired events. The constraints in the dict are
            effectively ANDed together.  Each key is an attribute name in either
            the event itself or its associated object.  The value associated with
            each attribute is either a list or a scalar value or something
            implementing __contains__.  A scalar value implies that it *must* have exactly
            that value, otherwise it must be *in* the associated list/tuple/etc.

            This should be able to constrain the type of event we're looking at, the
            type of event-object we're looking at, and the domain of the event-object -
            and lots of other potentially useful things.

            See the "is_interesting" method below for implementation details...

            If 'constraints' is a callable (that is, callable(constraints) is True), then
            we will just call constraints(event) to see if the event is interesting to
            this observer. Whatever 'constraints' returns will be interpreted in a
            boolean context - so returning a bool would be a good idea...
        '''
        self.constraints = constraints
        AssimEvent.registerobserver(self)
开发者ID:JJediny,项目名称:assimilation-official,代码行数:28,代码来源:assimeventobserver.py

示例2: test_simple_init_bad

# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import registerobserver [as 别名]
 def test_simple_init_bad(self):
     'Perform a few simple AssimEvent bad initializations'
     AssimEvent.enable_all_observers()
     AssimEvent.observers = []
     observer=DummyObserver()
     badobserver=BadObserver()
     AssimEvent.registerobserver(observer)
     self.assertRaises(ValueError, AssimEvent, 'first', 999)
     self.assertRaises(AttributeError, AssimEvent.registerobserver, badobserver)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:11,代码来源:assimevent_test.py

示例3: test_fork_exec_event

# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import registerobserver [as 别名]
    def test_fork_exec_event(self):
        '''This test will create a fork/exec event observer script
        and then test to see if its getting invoked properly...
        '''
        AssimEvent.enable_all_observers()
        tmpdir = tempfile.mkdtemp('.d', 'testexec_')
        (fd, pathname) = tempfile.mkstemp('.out.txt')
        execscript = os.path.join(tmpdir, 'observer.sh')
        makescript(execscript, pathname)
        AssimEvent.observers = []
        observer=ForkExecObserver(scriptdir=tmpdir)
        dummyclient = ClientClass()
        dummyclient.fred='fred'
        dummyclient.sevenofnine='Annika'
        dummyclient.foo = {'foo': 'bar'}

        self.assertEqual(observer.listscripts(), [execscript,])
        AssimEvent.registerobserver(observer)
        AssimEvent(dummyclient, AssimEvent.CREATEOBJ)
        AssimEvent(dummyclient, AssimEvent.OBJUP, extrainfo={'origaddr': '10.10.10.254'})
        os.close(fd)
        expectedcontent=\
'''====START====
ARG1=create
ARG2=ClientClass
ASSIM_fred=fred
ASSIM_nodetype=ClientClass
ASSIM_sevenofnine=Annika
==== JSON START ====
{"associatedobject":{"foo":{"foo":"bar"},"fred":"fred","nodetype":"ClientClass","sevenofnine":"Annika"},"eventtype":0,"extrainfo":null}
==== JSON END ====
====END====
====START====
ARG1=up
ARG2=ClientClass
ASSIM_fred=fred
ASSIM_nodetype=ClientClass
ASSIM_origaddr=10.10.10.254
ASSIM_sevenofnine=Annika
==== JSON START ====
{"associatedobject":{"foo":{"foo":"bar"},"fred":"fred","nodetype":"ClientClass","sevenofnine":"Annika"},"eventtype":1,"extrainfo":{"origaddr":"10.10.10.254"}}
==== JSON END ====
====END====
'''
        TestAssimEvent.waitfor(pathname, expectedcontent)
        f=open(pathname, 'r')
        content=f.read()
        f.close()
        self.assertEqual(content, expectedcontent)
        os.unlink(execscript)
        os.unlink(pathname)
        os.rmdir(tmpdir)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:54,代码来源:assimevent_test.py

示例4: test_fork_exec_killchild

# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import registerobserver [as 别名]
    def test_fork_exec_killchild(self):
        '''This test will create a fork/exec event observer script
        and then kill the child listener and verify that it is handled
        correctly.
        '''
        AssimEvent.enable_all_observers()
        tmpdir = tempfile.mkdtemp('.d', 'testexec_')
        (fd, pathname) = tempfile.mkstemp('.out.txt')
        execscript = os.path.join(tmpdir, 'observer.sh')
        makescript(execscript, pathname)
        AssimEvent.observers = []
        observer=ForkExecObserver(scriptdir=tmpdir)
        dummyclient = ClientClass()
        dummyclient.fred='fred'
        dummyclient.sevenofnine='Annika'
        dummyclient.foo = {'foo': 'bar'}
        AssimEvent.registerobserver(observer)
        try:
            os.kill(observer.childpid, signal.SIGKILL)
        except OSError:
            # "docker build" doesn't let us kill processes...
            # so we give up on this test and call it good...
            os.unlink(execscript)
            os.unlink(pathname)
            os.rmdir(tmpdir)
            return
        time.sleep(0.1)
        AssimEvent(dummyclient, AssimEvent.CREATEOBJ)
        # Death of our FIFO child will cause it to get respawned, and
        # message sent to new child.  No messages should be lost.
        expectedcontent=\
'''====START====
ARG1=create
ARG2=ClientClass
ASSIM_fred=fred
ASSIM_nodetype=ClientClass
ASSIM_sevenofnine=Annika
==== JSON START ====
{"associatedobject":{"foo":{"foo":"bar"},"fred":"fred","nodetype":"ClientClass","sevenofnine":"Annika"},"eventtype":0,"extrainfo":null}
==== JSON END ====
====END====
'''
        TestAssimEvent.waitfor(pathname, expectedcontent)
        f=open(pathname, 'r')
        content=f.read()
        f.close()
        self.assertEqual(content, expectedcontent)
        os.close(fd)
        os.unlink(execscript)
        os.unlink(pathname)
        os.rmdir(tmpdir)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:53,代码来源:assimevent_test.py

示例5: test_simple_init_good

# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import registerobserver [as 别名]
 def test_simple_init_good(self):
     'Perform a few simple AssimEvent good initializations'
     AssimEvent.enable_all_observers()
     AssimEvent.observers = []
     observer=DummyObserver()
     AssimEvent.registerobserver(observer)
     event1 = AssimEvent('first', AssimEvent.CREATEOBJ)
     self.assertEqual(len(observer.events), 1)
     self.assertTrue(observer.events[0], event1)
     self.assertEqual(AssimEvent.unregisterobserver(observer), True)
     event2 = AssimEvent('second', AssimEvent.CREATEOBJ)
     self.assertEqual(len(observer.events), 1)
     self.assertTrue(observer.events[0], event1)
     AssimEvent.registerobserver(observer)
     event3 = AssimEvent('third', AssimEvent.CREATEOBJ)
     self.assertEqual(len(observer.events), 2)
     self.assertTrue(observer.events[0], event3)
开发者ID:Alan-R,项目名称:assimilation-persistent-events,代码行数:19,代码来源:assimevent_test.py

示例6: __init__

# 需要导入模块: from assimevent import AssimEvent [as 别名]
# 或者: from assimevent.AssimEvent import registerobserver [as 别名]
    def __init__(self, constraints):
        '''Initializer for AssimEventObserver class.

        Parameters:
        -----------
        constraints: dict
            A dict describing our desired events. The constraints in the dict are
            effectively ANDed together.  Each key is an attribute name in either
            the event itself or its associated object.  The value associated with
            each attribute is either a list or a scalar value.  A list implies that
            any one of those values is acceptable.  A scalar value implies that it
            *must* have that value.

            This should be able to constrain the type of event we're looking at, the
            type of event-object we're looking at, and the domain of the event-object -
            and lots of other potentially useful things.

            See the "is_interesting" method below for implementation details...
        '''
        self.constraints = constraints
        AssimEvent.registerobserver(self)
开发者ID:borgified,项目名称:assimilation,代码行数:23,代码来源:assimeventobserver.py


注:本文中的assimevent.AssimEvent.registerobserver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。