コード例 #1
0
ファイル: pyscxml_server.py プロジェクト: bollwyvl/PySCXML
 def set_processors(self, sm):
     MultiSession.set_processors(self, sm)
     d = dict( (io_type, {"location" : "http://%s:%s" % (self.host, self.port) + "/".join([self.session_path, sm.datamodel.sessionid, io_type])} ) 
               for io_type in handler_mapping)
     
     for k, v in d.items():
         sm.datamodel[k] = v
コード例 #2
0
ファイル: pyscxml_server.py プロジェクト: goncheff/PySCXML
 def set_processors(self, sm):
     MultiSession.set_processors(self, sm)
     d = dict( (io_type, {"location" : "http://%s:%s/" % (self.host, self.port) + "/".join([sm.datamodel.sessionid, io_type])} ) 
               for io_type in handler_mapping)
     
     if isinstance(sm.datamodel, XPathDatamodel):
         del sm.datamodel["_ioprocessors"]
         sm.datamodel["_ioprocessors"] = d
     else:
         for k, v in d.items():
             sm.datamodel["_ioprocessors"][k] = v
コード例 #3
0
ファイル: pyscxml_server.py プロジェクト: su6838354/PySCXML
    def set_processors(self, sm):
        MultiSession.set_processors(self, sm)
        d = dict((io_type, {
            "location":
            "http://%s:%s/" % (self.host, self.port) +
            "/".join([sm.datamodel.sessionid, io_type])
        }) for io_type in handler_mapping)

        if isinstance(sm.datamodel, XPathDatamodel):
            del sm.datamodel["_ioprocessors"]
            sm.datamodel["_ioprocessors"] = d
        else:
            for k, v in d.items():
                sm.datamodel["_ioprocessors"][k] = v
コード例 #4
0
ファイル: pyscxml_server.py プロジェクト: su6838354/PySCXML
    def __init__(self,
                 host,
                 port,
                 default_scxml_source=None,
                 init_sessions={},
                 session_path="/",
                 default_datamodel="python"):
        '''
        @param host: the hostname on which to serve.
        @param port: the port on which to serve.
        @param default_scxml_source: an scxml document source (see StateMachine for the format).
        If one is provided, each call to a sessionid will initialize a new 
        StateMachine instance at that session, running the default document.
        If default_scxml_source is None, a call to an address that hasn't been 
        pre-initialized will fail with HTTP error 403 FORBIDDEN.
        @param init_sessions: a mapping where the keys correspond to sesssionids you 
        would like the server to be initialized with and the values to scxml document 
        strings you want those sessions to run. These will be constructed in the server 
        constructor and started as serve_forever() is called. Any key with the value of None 
        will instead execute the default_scxml_source. If default_scxml_source is None and a value 
        in init_sessions is None, AssertionError will be raised.    
        
        WARNING: this documentation is deprecated, since server_forever no longer exists. i'll fix this soon.
        Example:
        # when queried with a POST at http://localhost:8081/any_legal_url_string/basichttp,
        # this server will initialize a new StateMachine instance at that location, as well as
        # send it the http.post event.  
        server = PySCXMLServer("localhost", 8081, default_scxml_source=myStateMachine)
        server.serve_forever()
        
        # when queried with a POST at http://localhost:8081/any_legal_url_string/basichttp,
        # this server will respond with 403 FORBIDDEN if 
        # any_legal_url_string != "session1" and any_legal_url_string != "session2" 
        server = PySCXMLServer("localhost", 8081, 
                                init_sessions={"session1" : myStateMachine, "session2" : myStateMachine})
        
        
        
        '''
        self.session_path = session_path.strip("/") + "/"
        self.logger = logging.getLogger("pyscxml.pyscxml_server")
        self.host = host
        self.port = port
        MultiSession.__init__(self, default_scxml_source, init_sessions,
                              default_datamodel)

        self.start()
コード例 #5
0
ファイル: pyscxml_server.py プロジェクト: goncheff/PySCXML
 def __init__(self, host, port, default_scxml_source=None, init_sessions={}, 
              session_path="/", default_datamodel="python"):
     '''
     @param host: the hostname on which to serve.
     @param port: the port on which to serve.
     @param default_scxml_source: an scxml document source (see StateMachine for the format).
     If one is provided, each call to a sessionid will initialize a new 
     StateMachine instance at that session, running the default document.
     If default_scxml_source is None, a call to an address that hasn't been 
     pre-initialized will fail with HTTP error 403 FORBIDDEN.
     @param init_sessions: a mapping where the keys correspond to sesssionids you 
     would like the server to be initialized with and the values to scxml document 
     strings you want those sessions to run. These will be constructed in the server 
     constructor and started as serve_forever() is called. Any key with the value of None 
     will instead execute the default_scxml_source. If default_scxml_source is None and a value 
     in init_sessions is None, AssertionError will be raised.    
     
     WARNING: this documentation is deprecated, since server_forever no longer exists. i'll fix this soon.
     Example:
     # when queried with a POST at http://localhost:8081/any_legal_url_string/basichttp,
     # this server will initialize a new StateMachine instance at that location, as well as
     # send it the http.post event.  
     server = PySCXMLServer("localhost", 8081, default_scxml_source=myStateMachine)
     server.serve_forever()
     
     # when queried with a POST at http://localhost:8081/any_legal_url_string/basichttp,
     # this server will respond with 403 FORBIDDEN if 
     # any_legal_url_string != "session1" and any_legal_url_string != "session2" 
     server = PySCXMLServer("localhost", 8081, 
                             init_sessions={"session1" : myStateMachine, "session2" : myStateMachine})
     
     
     
     '''
     self.session_path = session_path.strip("/") + "/"
     self.logger = logging.getLogger("pyscxml.pyscxml_server")
     self.host = host
     self.port = port
     MultiSession.__init__(self, default_scxml_source, init_sessions, default_datamodel)
         
     #the connected websocket clients
     
     self.start()
コード例 #6
0
ファイル: pyscxmlTest.py プロジェクト: bollwyvl/PySCXML
    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)))
コード例 #7
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)))