Exemple #1
0
class InvokeSCXML(BaseFetchingInvoke):
    def __init__(self, data):
        BaseFetchingInvoke.__init__(self)
        self.sm = None
        self.parentQueue = None
        self.content = None
        self.initData = data
        self.cancelled = False
        self.default_datamodel = "python"
    
    def start(self, parentId):
        self.parentId = parentId
        if self.src:
            self.getter.get_async(self.src, None)
        else:
            self._start(self.content)
    
    def _start(self, doc):
        if self.cancelled: return
        from scxml.pyscxml import StateMachine
        
        self.sm = StateMachine(doc, 
                               sessionid=self.parentSessionid + "." + self.invokeid, 
                               default_datamodel=self.default_datamodel,
                               log_function=lambda label, val: dispatcher.send(signal="invoke_log", sender=self, label=label, msg=val),
                               setup_session=False)
        self.interpreter = self.sm.interpreter
        self.sm.compiler.initData = self.initData
        self.sm.compiler.parentId = self.parentId
        self.sm.interpreter.parentId = self.parentId
        dispatcher.send("created", sender=self, sm=self.sm)
        self.sm._start_invoke(self.invokeid)
        eventlet.spawn(self.sm.interpreter.mainEventLoop)

    
    def send(self, eventobj):
        if self.sm and not self.sm.isFinished():
            self.sm.interpreter.externalQueue.put(eventobj)
    
    def onHttpResult(self, signal, result, **named):
        self.logger.debug("onHttpResult " + str(named))
        self._start(result)
        
    def cancel(self):
        self.cancelled = True
        if not self.sm: return;
        self.sm.interpreter.cancelled = True
#        self.sm.interpreter.running = False
#        self.sm._send(["cancel", "invoke", self.invokeid], {}, self.invokeid)
        self.sm.interpreter.externalQueue.put(CancelEvent())
Exemple #2
0
 def _start(self, doc):
     if self.cancelled: return
     from scxml.pyscxml import StateMachine
     
     self.sm = StateMachine(doc, 
                            sessionid=self.parentSessionid + "." + self.invokeid, 
                            default_datamodel=self.default_datamodel,
                            log_function=lambda label, val: dispatcher.send(signal="invoke_log", sender=self, label=label, msg=val),
                            setup_session=False)
     self.interpreter = self.sm.interpreter
     self.sm.compiler.initData = self.initData
     self.sm.compiler.parentId = self.parentId
     self.sm.interpreter.parentId = self.parentId
     dispatcher.send("created", sender=self, sm=self.sm)
     self.sm._start_invoke(self.invokeid)
     eventlet.spawn(self.sm.interpreter.mainEventLoop)
Exemple #3
0
from scxml.pyscxml import StateMachine, default_logfunction
from louie import dispatcher
import logging
import os
#os.chdir("assertions_all/failed")
#os.chdir("assertions_ecma/failed")
#os.chdir("stoplist/failed")
# os.chdir("assertions_xpath/failed")
os.chdir("ecma_schema/failed")

logging.basicConfig(level=logging.NOTSET)

nextFile = filter(lambda x: x.endswith("xml"), os.listdir("."))[0]
xml = open(nextFile).read()
import re
#xml = re.sub("datamodel=.python.", 'datamodel="ecmascript"', xml)
dispatcher.connect(default_logfunction, "invoke_log")
sm = StateMachine(xml)
sm.start()



Exemple #4
0
    def testInterpreter(self):
        os.environ["PYSCXMLPATH"] = "../../unittest_xml:./unittest_xml"
        runToCompletionList = ["colors.xml", "parallel.xml", "issue_164.xml", "twolock_door.xml", 
                               "if_block.xml", "parallel2.xml", "parallel3.xml", "parallel4.xml", 
                               "donedata.xml", "error_management.xml", "invoke.xml", "history.xml", 
                               "internal_transition.xml", "binding.xml", "finalize.xml",
                               "internal_parallel.xml", "xpath_basic.xml"]
#        logging.basicConfig(level=logging.NOTSET)
        for name in runToCompletionList:
            print "Running " + name 
            sm = StateMachine(name)
            sm.start()
            self.assert_(sm.isFinished())
        
        sm = StateMachine("factorial.xml")
        sm.start()
        self.assertEquals(sm.datamodel['fac'], 720)

        with StateMachine("all_configs.xml") as sm: 
            sm.send("a")
            sm.send("b")
            sm.send("c")
            sm.send("d")
            sm.send("e")
            sm.send("f")
            sm.send("g")
            sm.send("h")
            self.assert_(sm.isFinished())
        
        # I think this test is obsolete because of the exit in a parallel block
#        sm = StateMachine(open(xmlDir + "issue_626.xml").read())
#        sm.start()
#        self.assertEquals(sm.datamodel["x"], 584346861767418750)

        
        '''
        sm = StateMachine(open(xmlDir + "xinclude.xml").read())
        sm.start()
        
        self.assert_(sm.isFinished())
        '''
        
        listener = '''
            <scxml>
                <state>
                    <transition event="e1" target="f">
                        <send event="e2" targetexpr="_event.origin"  />
                    </transition>
                </state>
                <final id="f" />
            </scxml>
        '''
        sender = '''
        <scxml>
            <state>
                <onentry>
                    <log label="sending event" />
                    <send event="e1" target="#_scxml_session1"  />
                </onentry>
                <transition event="e2" target="f" />
            </state>
            <final id="f" />
        </scxml>
        '''
        
        ms = MultiSession(init_sessions={"session1" : listener, "session2" : sender})
        ms.start()
        self.assert_(all(map(lambda x: x.isFinished(), ms)))
Exemple #5
0
 def on_exit(self, sender, final):
     self.didPass = not self.isCancelled and final == "pass"
     StateMachine.on_exit(self, sender, final)
Exemple #6
0
 def cancel(self):
     StateMachine.cancel(self)
     self.isCancelled = True
Exemple #7
0
 def __init__(self, xml, log_function=lambda fn, y:None, sessionid=None):
     self.didPass = False
     self.isCancelled = False
     
     StateMachine.__init__(self, xml, log_function, None)
Exemple #8
0
 def on_exit(self, sender, final):
     self.didPass = final == "pass"
     StateMachine.on_exit(self, sender, final)