def vPikaDispatchOnListener(self, sBody, oProperties=None): #? do we need the oProperties for content-type? # 'content_encoding', 'content_type', 'correlation_id', 'decode', 'delivery_mode', 'encode', 'expiration', 'headers', 'message_id', 'priority', 'reply_to', 'timestamp', 'type', 'user_id' lArgs = lUnFormatMessage(sBody) sMsgType = lArgs[0] sChart = lArgs[1] sIgnore = lArgs[2] # should be a hash on the payload sMark = lArgs[3] sPayloadType = lArgs[4] gPayload = lArgs[4:] # overwritten below if sMsgType == 'cmd': # FixMe; dispatch to the right chart lChartInstances = lFindAllCharts() if not lChartInstances: # this should never happen sys.stdout.write("ERROR: vPikaDispatchOnListener no charts\n") self.eMq4PushQueue(sBody) return if sChart.find('ANY') >= 0: #? use self? oElt =lChartInstances[0] oElt.eMq4PushQueue(sBody) return if sChart.find('ALL') >= 0: for oElt in lChartObjects: oElt.eMq4PushQueue(sBody) return l = oFindChartByName(sChart) if l: if len(l) != 1: sys.stdout.write("ERROR: vPikaDispatchOnListener too many charts named " +sChart +"\n") l[0].eMq4PushQueue(sBody) return sys.stdout.write("WARN: vPikaDispatchOnListener unrecognized sBody " +sBody +"\n") sys.stdout.flush() self.eMq4PushQueue(sBody) return #? assume eval is on any chart? if sMsgType == 'eval': # unused lRetval = ['retval'] lRetval += lArgs[1:3] sCmd = lArgs[4] if len(lArgs) > 5: sCmd += '(' +lArgs[5] +')' sRetval = sPySafeEval(sCmd) if sRetval.find('ERROR:') >= 0: lRetval += ['error', sRetval] else: lRetval += ['string', sRetval] sRetval = '|'.join(lRetval) # FixMe; dispatch to the right chart self.eReturnOnSpeaker('retval', sRetval, sBody) return
def vPikaDispatchOnListener(self, sBody, oProperties=None): #? do we need the oProperties for content-type? # 'content_encoding', 'content_type', 'correlation_id', 'decode', 'delivery_mode', 'encode', 'expiration', 'headers', 'message_id', 'priority', 'reply_to', 'timestamp', 'type', 'user_id' lArgs = lUnFormatMessage(sBody) sMsgType = lArgs[0] sChart = lArgs[1] sIgnore = lArgs[2] # should be a hash on the payload sMark = lArgs[3] sVerbMaybe = lArgs[4] gPayload = lArgs[4:] # overwritten below if sMsgType == 'cmd': # FixMe; dispatch to the right chart lChartInstances = lFindAllCharts() if not lChartInstances: # this should never happen sys.stdout.write("ERROR: vPikaDispatchOnListener no charts\n") self.eMq4PushQueue(sBody) return if sChart.find('ANY') >= 0: #? use self? oElt = lChartInstances[0] oElt.eMq4PushQueue(sBody) return if sChart.find('ALL') >= 0: for oElt in lChartObjects: oElt.eMq4PushQueue(sBody) return o = oFindChartByName(sChart) if o is not None: o.eMq4PushQueue(sBody) return sys.stdout.write( "WARN: vPikaDispatchOnListener unrecognized sBody " + sBody + "\n") sys.stdout.flush() self.eMq4PushQueue(sBody) return #? assume eval is on any chart? if sMsgType == 'eval': # unused lRetval = ['retval'] lRetval += lArgs[1:3] sCmd = lArgs[4] if len(lArgs) > 5: sCmd += '(' + lArgs[5] + ')' sRetval = sPySafeEval(sCmd) if sRetval.find('ERROR:') >= 0: lRetval += ['error', sRetval] else: lRetval += ['string', sRetval] sRetval = '|'.join(lRetval) # FixMe; dispatch to the right chart self.eReturnOnSpeaker('retval', sRetval, sBody) return
def test(): # changing sys.stdout can't be done under doctest if os.path.isfile('test.txt'): os.remove('test.txt') vPyInit('test.txt') assert os.path.isfile('test.txt'), "File not found: 'test.txt'" assert sys.stdout != sys.__stdout__ assert sys.stderr != sys.__stderr__ # This can't be done under doctest s = sPySafeEval('foobar') assert s.find('ERROR:') == 0 assert s == "ERROR: name 'foobar' is not defined" vLog(0, "Level 0") vLog(1, "Level 1") vLog(2, "Level 2") vLog(3, "Level 3") vLog(4, "Level 4") # oLOG.root.setLevel(40) # oLOG.debug("NONONO oLOG.debug") # vLog(4, "NONO vLog 4") vPyDeInit() assert sys.stdout == sys.__stdout__ assert sys.stderr == sys.__stderr__ assert oTKINTER_ROOT is None assert sSTDOUT_FD is None # should check contents of test.txt oFd = open('test.txt', 'r') sContents = oFd.read() oFd.close() assert sContents.find("Level 4") > 0 assert sContents.find("NONO") < 0