77import defusedxml .ElementTree as ET
88
99
10- def ReadStateMachineFile (xml_file : str ):
10+ def ReadStateMachineFile (xml_file : str ):
1111 states = {}
1212 initial_state = ""
1313 tree = ET .parse (xml_file )
1414 root = tree .getroot ()
1515 for states_child in root :
1616 #print(states_child.tag, states_child.attrib)
1717 # States Element
18- if states_child .tag == "State" :
18+ if states_child .tag == "State" :
1919 #print("State element")
2020 # State Element
2121 state_name = ""
@@ -27,13 +27,13 @@ def ReadStateMachineFile(xml_file : str):
2727 # State->Event Element
2828 event_name = ""
2929 to_state = ""
30- pre_conditions = None # dummy
31- post_conditions = None # dummy
32- pre_actions = None # dummy
33- post_actions = None # dummy
34-
30+ pre_conditions = None # dummy
31+ post_conditions = None # dummy
32+ pre_actions = None # dummy
33+ post_actions = None # dummy
34+
3535 for event_child in state_child :
36-
36+
3737 #print(event_child.tag, event_child.attrib)
3838 if event_child .tag == "Name" :
3939 #print("Name element = ", event_child.text)
@@ -47,7 +47,7 @@ def ReadStateMachineFile(xml_file : str):
4747 # State->Event->PreConditions Element
4848 pre_condition_elements = []
4949 for preconditions_child in event_child :
50- #print(preconditions_child.text)
50+ # print(preconditions_child.text)
5151 # State->Event->PreConditions->Condition Element
5252 if preconditions_child .tag == "Condition" :
5353 expression = ""
@@ -57,13 +57,14 @@ def ReadStateMachineFile(xml_file : str):
5757 expression = condition_child .text
5858 elif condition_child .tag == "Result" :
5959 result = condition_child .text
60- pre_condition_elements .append (Condition (expression ,result ))
60+ pre_condition_elements .append (
61+ Condition (expression , result ))
6162 pre_conditions = Conditions (pre_condition_elements )
6263 elif event_child .tag == "PostConditions" :
6364 # State->Event->PostConditions Element
6465 post_condition_elements = []
6566 for postconditions_child in event_child :
66- #print(postconditions_child.text)
67+ # print(postconditions_child.text)
6768 # State->Event->PostConditions->Condition Element
6869 if postconditions_child .tag == "Condition" :
6970 expression = ""
@@ -73,48 +74,53 @@ def ReadStateMachineFile(xml_file : str):
7374 expression = condition_child .text
7475 elif condition_child .tag == "Result" :
7576 result = condition_child .text
76- post_condition_elements .append (Condition (expression ,result ))
77- post_conditions = Conditions (post_condition_elements )
77+ post_condition_elements .append (
78+ Condition (expression , result ))
79+ post_conditions = Conditions (
80+ post_condition_elements )
7881 elif event_child .tag == "PreActions" :
7982 # State->Event->PreActions Element
8083 pre_action_elements = []
8184 for preactions_child in event_child :
82- #print(preactions_child.text)
85+ # print(preactions_child.text)
8386 # State->Event->PreActions->Action Element
8487 if preactions_child .tag == "Action" :
85- expression = ""
88+ expression = ""
8689 for action_child in preactions_child :
8790 if action_child .tag == "Expression" :
8891 expression = action_child .text
89- pre_action_elements .append (Action (expression ))
92+ pre_action_elements .append (
93+ Action (expression ))
9094 pre_actions = Actions (pre_action_elements )
9195
9296 elif event_child .tag == "PostActions" :
9397 # State->Event->PostActions Element
9498 post_action_elements = []
9599 for postactions_child in event_child :
96- #print(postactions_child.text)
100+ # print(postactions_child.text)
97101 # State->Event->PostActions->Action Element
98102 if postactions_child .tag == "Action" :
99- expression = ""
103+ expression = ""
100104 for action_child in postactions_child :
101105 if action_child .tag == "Expression" :
102106 expression = action_child .text
103- post_action_elements .append (Action (expression ))
107+ post_action_elements .append (
108+ Action (expression ))
104109 post_actions = Actions (post_action_elements )
105-
106- events [event_name ] = Event (event_name ,to_state ,pre_conditions ,post_conditions ,pre_actions ,post_actions )
107- #print(event.to_string())
110+
111+ events [event_name ] = Event (
112+ event_name , to_state , pre_conditions , post_conditions , pre_actions , post_actions )
113+ # print(event.to_string())
108114 elif state_child .tag == "Name" :
109115 #print("Name element = ", state_child.text)
110116 # State->Name Element
111117 state_name = state_child .text
112-
118+
113119 states [state_name ] = State (state_name , events )
114-
115- elif states_child .tag == "Initial_State" :
120+
121+ elif states_child .tag == "Initial_State" :
116122 #print ("Initial_State element = ", states_child.text)
117123 # Initial_State Element
118- initial_state = states_child .text
119-
120- return states , initial_state
124+ initial_state = states_child .text
125+
126+ return states , initial_state
0 commit comments