From 733185805591cbfb08b9845c5f51a07401f2c974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 10 Apr 2018 11:19:53 +0200 Subject: [PATCH] Add LinearFSM example to test project --- solvable/src/sql_injection_fsm.py | 26 -------------------------- solvable/src/test_fsm.py | 26 ++++++++++++++++++++++++++ solvable/src/tfw_server.py | 6 ++++-- 3 files changed, 30 insertions(+), 28 deletions(-) delete mode 100644 solvable/src/sql_injection_fsm.py create mode 100644 solvable/src/test_fsm.py diff --git a/solvable/src/sql_injection_fsm.py b/solvable/src/sql_injection_fsm.py deleted file mode 100644 index 550fc00..0000000 --- a/solvable/src/sql_injection_fsm.py +++ /dev/null @@ -1,26 +0,0 @@ -from tfw.fsm_base import FSMBase - - -class SQLInjectionFSM(FSMBase): - states = [ - 'start', - 'stripped_code', - 'sql', - 'commented_code', - 'sql_with_substitutions', - 'sql_output', - 'end', - ] - transitions = [ - {'trigger': 'webide', 'source': '*', 'dest': 'stripped_code'}, # TODO: delet this - {'trigger': 'webide', 'source': 'start', 'dest': 'stripped_code'}, - {'trigger': 'login', 'source': 'stripped_code', 'dest': 'sql'}, - {'trigger': 'logger', 'source': 'sql', 'dest': 'commented_code'}, - {'trigger': 'webide', 'source': 'commented_code', 'dest': 'sql_with_substitutions'}, - {'trigger': 'logger', 'source': 'sql_with_substitutions', 'dest': 'sql_output'}, - {'trigger': 'logger', 'source': 'sql_output', 'dest': 'end'}, - {'trigger': 'reset', 'source': 'end', 'dest': 'start'}, - ] - - def __init__(self): - super().__init__('start') diff --git a/solvable/src/test_fsm.py b/solvable/src/test_fsm.py new file mode 100644 index 0000000..b5d8b2b --- /dev/null +++ b/solvable/src/test_fsm.py @@ -0,0 +1,26 @@ +from tfw import LinearFSM +from tfw.networking import MessageSender + + +class TestFSM(LinearFSM): + def __init__(self, number_of_steps): + super().__init__(number_of_steps) + self.message_sender = MessageSender() + + def on_enter_1(self, event_data): + self.state_notify(1) + + def on_enter_2(self, event_data): + self.state_notify(2) + + def on_enter_3(self, event_data): + self.state_notify(3) + + def on_enter_4(self, event_data): + self.state_notify(4) + + def on_enter_5(self, event_data): + self.state_notify(5) + + def state_notify(self, state): + self.message_sender.send('TestFSM', 'Entered state {}!'.format(state)) diff --git a/solvable/src/tfw_server.py b/solvable/src/tfw_server.py index 116e2a9..e0545b7 100644 --- a/solvable/src/tfw_server.py +++ b/solvable/src/tfw_server.py @@ -1,9 +1,11 @@ import sys +from functools import partial + import zmq import tornado from tornado.ioloop import IOLoop -from sql_injection_fsm import SQLInjectionFSM +from test_fsm import TestFSM from tfw.networking import TFWServer from tfw.config import TFWENV from tfw.config.logs import logging @@ -12,7 +14,7 @@ LOG = logging.getLogger(__name__) if __name__ == '__main__': - TFWServer(SQLInjectionFSM).listen(TFWENV.WEB_PORT) + TFWServer(partial(TestFSM, 5)).listen(TFWENV.WEB_PORT) LOG.debug('Python version: %s', sys.version[:5]) LOG.debug('Tornado version: %s', tornado.version) LOG.debug('ZeroMQ version: %s', zmq.zmq_version())