本文整理汇总了Python中EventHandlers.EventRouterLoad.EventRouterLoader类的典型用法代码示例。如果您正苦于以下问题:Python EventRouterLoader类的具体用法?Python EventRouterLoader怎么用?Python EventRouterLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventRouterLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Root
class Root(controllers.Root):
# Class attributes overridden by instance value in start() method
# (tested by stop() method below.)
despatch = None
discover = None
def start(self):
# Load and start the event dispatcher,
# and associated logic that performs WebBrick discovery
self.eventloader = EventRouterLoader()
# system files first.
self.eventloader.loadHandlers( despatchConfig )
if self.eventloader:
self.eventloader.start()
# now disovery handler.
self.discover = Discovery.DiscoverHandler()
self.discover.start(self.eventloader.getEventRouter())
# wbtst = WebBrick.WebBrickTest()
# Assignments to the controller instance (or class) are used to define handing
# of URIs. See cherrypy_cputil.get_object_trail() for some of the details.
# (TODO: consider how this is affected by local instance attributes like
# 'despatch' and 'discover' above.)
if 0:
# Local testing
self.wbcnf = MockWbConfig.MockWebBrickCfgEdit()
else:
# Production / live WebBricks
self.wbcnf = WbCfgManagerForm.WbCfgManagerForm(self.discover )
self.testwbcnf = MockWbConfig.MockWebBrickCfgEdit()
# self._log.warning( "**** System Configured ****" )
def stop(self):
"""
helper to shut down some class stuff.
"""
if self.despatch:
self.discover.stop(self.despatch)
self.despatch.stop()
@turbogears.expose(template="WebBrickConfig.templates.WbCfgWelcome")
def index(self):
return dict(now=time.ctime())
@turbogears.expose(template="WebBrickConfig.templates.quiet")
def quiet(self):
return dict()
# @turbogears.expose()
def default(self,*args):
raise cherrypy.HTTPRedirect(turbogears.url("/panels"))
示例2: testTimeEvent4
def testTimeEvent4(self):
"""
Run test with time interval in seconds.
"""
self._log.debug( "\n\ntestTimeEvent4" )
loader = EventRouterLoader()
loader.loadHandlers( getDictFromXmlString(testConfigTime4) )
loader.start() # all tasks
self._router = loader.getEventRouter()
self.waitNEvents( 1 )
TestEventLogger.logEvents()
# first event should be isDark
self.assert_( len(TestEventLogger._events) > 0)
self.assertEqual( TestEventLogger._events[0].getType(), u'http://id.webbrick.co.uk/events/time/isDark' )
self.assertEqual( TestEventLogger._events[0].getSource(), "time/isDark" )
self.waitNEvents( 5 )
TestEventLogger.logEvents()
self.assert_( len(TestEventLogger._events) > 4)
evt = TestEventLogger._events[1]
od = evt.getPayload()
self.assertEqual( len(od["timestr"]),8 )
self.assertEqual( len(od["datestr"]),10 )
self.assertEqual( len(od["datetimestr"]),19 )
loader.stop() # all tasks
self.dumpEvents = False
示例3: TestEventState
class TestEventState(unittest.TestCase):
def setUp(self):
self._log = logging.getLogger( "TestEventState" )
self.router = None
self.loader = None
self.eventState = None
return
def tearDown(self):
if self.eventState:
self.eventState.stop( self.router )
self.eventState = None
if self.loader:
self.loader.stop() # all tasks
self.loader = None
self.router = None
time.sleep(1)
# Actual tests follow
def TestEventState(self):
# create testDespatch
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigEvent) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.eventState = EventState()
self.eventState.start( self.router );
# request URL from ..
q1 = self.eventState.queryCache( 'webbrick/100/DO/0', 'state' )
self.assertEqual( q1["stsval"], None )
self.assertEqual( q1["stserr"], 'Not Known' )
# send event
self.router.publish( EventSource("TestEventState"), EventHandlers.tests.Events.evtDO_0_off ) # 0 Off
# request good URL
q2 = self.eventState.queryCache( 'webbrick/100/DO/0', 'state' )
self.assertEqual( q2["stsval"], '0' )
self.assertEqual( q2["stserr"], None )
# request bad URL
q3 = self.eventState.queryCache( 'webbrick/100/DO/1', 'state' )
self.assertEqual( q3["stsval"], None )
self.assertEqual( q3["stserr"], 'Not Known' )
示例4: testSingleDirectoryAbsoluteLocal
def testSingleDirectoryAbsoluteLocal(self):
_log.debug( "\ntestSingleDirectoryAbsoluteLocal" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigSingleDirectoryAbsolute) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.waitForFile(fname01)
self.router.publish( EventAgent("TestBackup"), Events.evtMinute1 ) # do initial backup
self.waitForFile(fname01)
self.loader.stop() # all tasks
self.loader = None
# now verify file exists.
self.failUnless( isfile( fname01 ) )
self.failUnless( zipfile.is_zipfile( fname01 ) )
# read zip info.
zf = zipfile.ZipFile(fname01, 'r' ) # read only
zfi = zf.infolist()
self.assertEqual( len(zfi), 2 ) # two entrys
self.failUnless( zfi[0].filename.endswith("/work/file1.txt") )
self.failUnless( zfi[1].filename.endswith("/work/file2.txt") )
zf.close()
示例5: testSingleFileLocalDelete
def testSingleFileLocalDelete(self):
"""
Initial single file backup
"""
_log.debug( "\ntestSingleFileLocalDelete" )
copyfile( testdata1, testdata3 )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigSingleFileDelete) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.router.publish( EventAgent("TestBackup"), Events.evtMinute1 ) # do initial backup
self.waitForFile(fname01)
self.loader.stop() # all tasks
self.loader = None
# now verify file exists.
self.failUnless( isfile( fname01 ) )
self.failUnless( zipfile.is_zipfile( fname01 ) )
# read zip info.
zf = zipfile.ZipFile(fname01, 'r' ) # read only
zfi = zf.infolist()
self.assertEqual( len(zfi), 1 ) # one entry
self.assertEqual( zfi[0].filename, "work/file1_delete.txt" )
self.failIf( isfile( testdata3 ) ) # should be deleted
zf.close()
示例6: testCompress
def testCompress(self):
"""
Test database compression
"""
self._aofFilePath = "/home/tombushby/Documents/Redis/redis2rc/redis-2.0.0-rc2/appendonly.aof"
self._startSize = os.path.getsize(self._aofFilePath)
self.persistDatabaseEmpty()
self.persistDatabaseWrite4()
self.persistDatabaseWrite4()
self.persistDatabaseWrite4()
self.persistDatabaseWrite4()
self.persistDatabaseWrite4()
self._log.debug("\ntestDatabaseCompress")
self.loader = EventRouterLoader()
self.loader.loadHandlers(getDictFromXmlString(testPersistCfg))
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.router.publish(
EventAgent("TestPersistDatabase"),
Event("http://id.webbrick.co.uk/events/time/minute", "test/source", {"hour": 2, "minute": 5}),
)
time.sleep(5) # BGREWRITEAOF (compressing the AOF file) is a background process, it needs time
self._endSize = os.path.getsize(self._aofFilePath)
self.assertEqual(self._startSize > self._endSize, True)
示例7: testStartStop
def testStartStop(self):
self._log.debug( "\ntestStartStop" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigUPNP) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
time.sleep(5)
self.router.publish( EventAgent("testITunes"), evt_Play )
time.sleep(5)
self.router.publish( EventAgent("testITunes"), evt_Next )
time.sleep(5)
self.router.publish( EventAgent("testITunes"), evt_Next )
time.sleep(5)
self.router.publish( EventAgent("testITunes"), evt_Pause )
time.sleep(5)
self.router.publish( EventAgent("testITunes"), evt_Play )
time.sleep(5)
self.router.publish( EventAgent("testITunes"), evt_Prev )
time.sleep(5)
self.router.publish( EventAgent("testITunes"), evt_Stop )
time.sleep(5)
示例8: testTimerHoldPI
def testTimerHoldPI(self):
self._log.debug( "\n\ntestTimerHoldPI" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigTimer2) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.router.publish( EventAgent("TestTimerAction"), Events.evtTimerConEnable )
self.router.publish( EventAgent("TestTimerAction"), Events.evtTimerConDuration )
self.router.publish( EventAgent("TestTimerAction"), Events.evtHome )
self.router.publish( EventAgent("TestTimerAction"), Events.evtDark )
self.router.publish( EventAgent("TestTimerAction"), Events.evtMorningDark )
self.router.publish( EventAgent("TestTimerAction"), Events.evtDO_1_on ) # this should NOT create a hold state (because invert is set)
self.router.publish( EventAgent("TestTimerAction"), Events.evtDO_0_on ) # this should kick presence
self.router.publish( EventAgent("TestTimerAction"), Events.evtSecond0 ) # Create a 'second'
self.router.publish( EventAgent("TestTimerAction"), Events.evtSecond1 ) # Create a 'second'
self.router.publish( EventAgent("TestTimerAction"), Events.evtSecond2 ) # Create a 'second'
self.router.publish( EventAgent("TestTimerAction"), Events.evtSecond3 ) # Create a 'second'
self.expectNevents( 13 )
self.assertEqual( TestEventLogger._events[11].getType(), u'http://id.webbrick.co.uk/events/timer' )
self.assertEqual( TestEventLogger._events[11].getSource(), "testing/timer/1" )
self.assertEqual( TestEventLogger._events[12].getType(), u'testing' )
self.assertEqual( TestEventLogger._events[12].getSource(), "result/timertest" )
示例9: testWebbrickStatusQuery
def testWebbrickStatusQuery(self):
self._log.debug( "\n\ntestWebbrickStatusQuery" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigWebbrickStatusQuery) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.router.publish( EventAgent("TestWebbrickStatusMonitor"), Events.evtSecond5 ) # so webbrick is in list for recover
self.router.publish( EventAgent("TestWebbrickStatusMonitor"), Events.evtMinute1 ) # do recover
waitNSeconds(2) # recover is async
self.router.publish( EventAgent("TestWebbrickStatusMonitor"), Events.evtSecond5 ) # do scan
waitNSeconds(2) # scan is async
# We should see lots of events here as initial pass.
# my test rig only has 1 temp sensors.
# so:
# 1 temp sensors
# 4 analogue in
# 4 analogue out
# 12 digital in
# 8 digital out
# 8 mimic out
self.assert_( TestEventLogger.expectAtLeastNevents(36+NUM_TEMP_SENSORS), "expecting %u events" % (36+NUM_TEMP_SENSORS) )
oldLen = len(TestEventLogger._events)
self.router.publish( EventAgent("TestWebbrickStatusMonitor"), Events.evtSecond5 ) # do scan
waitNSeconds(2) # scan is async
TestEventLogger.logEvents()
self.assert_( oldLen <= len(TestEventLogger._events) )
示例10: testCompoundNewState
def testCompoundNewState(self):
self._log.debug( "\ntestCompoundNewState" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigCompoundEventNewState) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
# initial state is all things off.
self.router.publish( EventAgent("TestCompound"), Events.evtMinute1 )
TestEventLogger.logEvents()
self.expectNevents( 1 )
self.router.publish( EventAgent("TestCompound"), Events.evtMinute2 )
self.expectNevents( 3 )
self.assertEqual( TestEventLogger._events[2].getType(), u'internal' )
self.assertEqual( TestEventLogger._events[2].getSource(), "testState" )
od = TestEventLogger._events[2].getPayload()
self.assertEqual( od["idx"], '1' )
self.router.publish( EventAgent("TestCompound"), Events.evtMinute3 )
self.expectNevents( 4 )
self.router.publish( EventAgent("TestCompound"), Events.evtMinute4 )
self.expectNevents( 6 )
self.assertEqual( TestEventLogger._events[5].getType(), u'internal' )
self.assertEqual( TestEventLogger._events[5].getSource(), "testState" )
od = TestEventLogger._events[5].getPayload()
self.assertEqual( od["idx"], 3 ) # previous minute
示例11: testCompoundEvent2
def testCompoundEvent2(self):
# What happens if an updated updates multiple bits of local state
# and gets repeated events
self._log.debug( "\n\ntestCompoundEvent2" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigCompoundEvent2) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
# initial state is all things off.
self.router.publish( EventAgent("TestCompound"), Events.evtMinute1 )
self.expectNevents( 1 )
self.router.publish( EventAgent("TestCompound"), Events.evtMinute2 )
self.expectNevents( 3 )
self.assertEqual( TestEventLogger._events[2].getType(), u'http://simple' )
self.assertEqual( TestEventLogger._events[2].getSource(), "garage1/Open" )
self.router.publish( EventAgent("TestCompound"), Events.evtMinute3 )
self.expectNevents( 5 )
self.assertEqual( TestEventLogger._events[4].getType(), u'http://simple' )
self.assertEqual( TestEventLogger._events[4].getSource(), "garage1/Closed" )
self.router.publish( EventAgent("TestCompound"), Events.evtMinute2 )
self.expectNevents( 7 )
self.assertEqual( TestEventLogger._events[6].getType(), u'http://simple' )
self.assertEqual( TestEventLogger._events[6].getSource(), "garage1/Open" )
示例12: testConvertIntToHexBytes
def testConvertIntToHexBytes(self):
self._log.debug("\ntestConvertHexToInt")
self.loader = EventRouterLoader()
self.loader.loadHandlers(getDictFromXmlString(testConvertHexIntConfig2))
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.router.publish(EventAgent("TestValueConvert"), Events.evtINT_0) # dec 50, i.e. hex 32
self.router.publish(EventAgent("TestValueConvert"), Events.evtINT_50) # dec 50, i.e. hex 32
self.router.publish(EventAgent("TestValueConvert"), Events.evtINT_100) # dec 50, i.e. hex 32
self.expectNevents(6)
# first is subscribe event
self.assertEqual(TestEventLogger._events[0].getSource(), "testing/converion/dec_to_hex")
self.assertEqual(TestEventLogger._events[1].getSource(), "testing/converion/dec_to_hex")
self.assertEqual(TestEventLogger._events[2].getSource(), "testing/converion/dec_to_hex")
self.assertEqual(TestEventLogger._events[3].getType(), "local/value")
self.assertEqual(TestEventLogger._events[3].getSource(), "testing/converion/dec_to_hex/result")
self.assertEqual(TestEventLogger._events[3].getPayload()["val1"], 48)
self.assertEqual(TestEventLogger._events[3].getPayload()["val2"], 48)
self.assertEqual(TestEventLogger._events[3].getPayload()["oldval"], "0")
self.assertEqual(TestEventLogger._events[4].getType(), "local/value")
self.assertEqual(TestEventLogger._events[4].getSource(), "testing/converion/dec_to_hex/result")
self.assertEqual(TestEventLogger._events[4].getPayload()["val1"], 51)
self.assertEqual(TestEventLogger._events[4].getPayload()["val2"], 50)
self.assertEqual(TestEventLogger._events[4].getPayload()["oldval"], "50")
self.assertEqual(TestEventLogger._events[5].getType(), "local/value")
self.assertEqual(TestEventLogger._events[5].getSource(), "testing/converion/dec_to_hex/result")
self.assertEqual(TestEventLogger._events[5].getPayload()["val1"], 54)
self.assertEqual(TestEventLogger._events[5].getPayload()["val2"], 52)
self.assertEqual(TestEventLogger._events[5].getPayload()["oldval"], "100")
示例13: testConvertHexToInt
def testConvertHexToInt(self):
self._log.debug("\ntestConvertHexToInt")
self.loader = EventRouterLoader()
self.loader.loadHandlers(getDictFromXmlString(testConvertHexIntConfig1))
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.router.publish(EventAgent("TestValueConvert"), Events.evtHEX_0) # Hex 0 i.e. dec 0
self.router.publish(EventAgent("TestValueConvert"), Events.evtHEX_32) # Hex 32 i.e. dec 50
self.router.publish(EventAgent("TestValueConvert"), Events.evtHEX_64) # Hex 64 i.e. dec 100
self.expectNevents(6)
# first is subscribe event
self.assertEqual(TestEventLogger._events[0].getSource(), "testing/converion/hex_to_dec")
self.assertEqual(TestEventLogger._events[1].getSource(), "testing/converion/hex_to_dec")
self.assertEqual(TestEventLogger._events[2].getSource(), "testing/converion/hex_to_dec")
self.assertEqual(TestEventLogger._events[3].getType(), "local/value")
self.assertEqual(TestEventLogger._events[3].getSource(), "testing/converion/hex_to_dec/result")
self.assertEqual(TestEventLogger._events[3].getPayload()["val"], 0)
self.assertEqual(TestEventLogger._events[3].getPayload()["oldval"], "0")
self.assertEqual(TestEventLogger._events[4].getType(), "local/value")
self.assertEqual(TestEventLogger._events[4].getSource(), "testing/converion/hex_to_dec/result")
self.assertEqual(TestEventLogger._events[4].getPayload()["val"], 50)
self.assertEqual(TestEventLogger._events[4].getPayload()["oldval"], "32")
self.assertEqual(TestEventLogger._events[5].getType(), "local/value")
self.assertEqual(TestEventLogger._events[5].getSource(), "testing/converion/hex_to_dec/result")
self.assertEqual(TestEventLogger._events[5].getPayload()["val"], 100)
self.assertEqual(TestEventLogger._events[5].getPayload()["oldval"], "64")
示例14: testDeltaTime2
def testDeltaTime2(self):
"""
Test the delta time event generator.
"""
self._log.debug( "\n\ntestDeltaTime2" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigDeltaTime2) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
self.router.publish( EventAgent("TestDelayedEvent"), Events.evtTD0 ) # TD0 0 Off
# time events are not in the log.
TestEventLogger.logEvents()
self.assertEqual( len(TestEventLogger._events), 2)
self.assertEqual( TestEventLogger._events[0].getType(), "http://id.webbrick.co.uk/events/webbrick/TD" )
self.assertEqual( TestEventLogger._events[1].getType(), "http://id.webbrick.co.uk/events/time/delta" )
self.router.publish( EventAgent("TestDelayedEvent"), Events.evtMinute ) # minute
self.router.publish( EventAgent("TestDelayedEvent"), Events.evtMinute ) # minute
# delayed event should now be here.
self.assertEqual( len(TestEventLogger._events), 4)
self.assertEqual( TestEventLogger._events[2].getType(), "delta/delay" )
self.assertEqual( TestEventLogger._events[2].getSource(), "delta/delay1" )
self.assertEqual( TestEventLogger._events[3].getType(), "delta/delay" )
self.assertEqual( TestEventLogger._events[3].getSource(), "delta/delay2" )
示例15: testHttpAction2RequestsSpaced
def testHttpAction2RequestsSpaced(self):
self._log.debug( "\ntestHttpAction2RequestsSpaced" )
self.loader = EventRouterLoader()
self.loader.loadHandlers( getDictFromXmlString(testConfigHttpAction) )
self.loader.start() # all tasks
self.router = self.loader.getEventRouter()
time.sleep(1)
self.router.publish( EventAgent("TestHttpAction"), Events.evtTD0 ) # 0 Off
maxTime = 10
while (len(self.httpServer.requests()) < 1) and (maxTime > 0):
maxTime -= 1
time.sleep(1)
self.router.publish( EventAgent("TestHttpAction"), Events.evtTD0 ) # 0 Off
maxTime = 10
while (len(self.httpServer.requests()) < 2) and (maxTime > 0):
maxTime -= 1
time.sleep(1)
TestEventLogger.logEvents()
# now look for correct url requests
self._log.debug( "testHttpAction %s", self.httpServer.requests() )
self.assertEqual( len(self.httpServer.requests()), 2)
self.assertEqual( self.httpServer.requests()[0], "/test?medianame=ITunes&mediacmd=volup" )
self.assertEqual( self.httpServer.requests()[1], "/test?medianame=ITunes&mediacmd=volup" )