1+ class Action :
2+ def __init__ (self , action , param = None ):
3+ self .action = action
4+ self .param = param
5+
6+ def set_action (self , action , param ):
7+ self .action = action
8+ self .param = param
9+
10+ def to_string (self ):
11+ if self .param :
12+ return f"{ self .action } :{ self .param } "
13+ return self .action
14+
15+ def get_key (self ):
16+ return self .action
17+
18+ def __str__ (self ):
19+ return self .to_string ()
20+
21+
22+ class SeclangActions :
23+ def __init__ (self ):
24+ self .disruptive_action = None
25+ self .non_disruptive_actions = []
26+ self .flow_actions = []
27+ self .data_actions = []
28+
29+ def to_string (self ):
30+ results = []
31+ if self .disruptive_action and self .disruptive_action .action :
32+ results .append (self .disruptive_action .to_string ())
33+ results .extend (action .to_string () for action in self .non_disruptive_actions )
34+ results .extend (action .to_string () for action in self .flow_actions )
35+ results .extend (action .to_string () for action in self .data_actions )
36+ return ", " .join (results )
37+
38+ def __str__ (self ):
39+ return f"Disruptive: { self .disruptive_action } , NonDisruptive: { self .non_disruptive_actions } , Flow: { self .flow_actions } , Data: { self .data_actions } "
40+
41+ def set_disruptive_action_with_param (self , action , value ):
42+ self .disruptive_action = Action (action , value )
43+
44+ def set_disruptive_action_only (self , action ):
45+ self .disruptive_action = Action (action )
46+
47+ def add_non_disruptive_action_with_param (self , action , param ):
48+ self .non_disruptive_actions .append (Action (action , param ))
49+
50+ def add_non_disruptive_action_only (self , action ):
51+ self .non_disruptive_actions .append (Action (action ))
52+
53+ def add_flow_action_with_param (self , action , param ):
54+ self .flow_actions .append (Action (action , param ))
55+
56+ def add_flow_action_only (self , action ):
57+ self .flow_actions .append (Action (action ))
58+
59+ def add_data_action_with_params (self , action , param ):
60+ self .data_actions .append (Action (action , param ))
61+
62+ def get_action_keys (self ):
63+ keys = [action .get_key () for action in self .non_disruptive_actions ]
64+ keys .extend (action .get_key () for action in self .flow_actions )
65+ keys .extend (action .get_key () for action in self .data_actions )
66+ return keys
67+
68+ def get_action_by_key (self , key ):
69+ for action in self .non_disruptive_actions :
70+ if action .get_key () == key :
71+ return action
72+ for action in self .flow_actions :
73+ if action .get_key () == key :
74+ return action
75+ for action in self .data_actions :
76+ if action .get_key () == key :
77+ return action
78+ return None
79+
80+ def get_actions_by_key (self , key ):
81+ actions = [action for action in self .non_disruptive_actions if action .get_key () == key ]
82+ actions .extend (action for action in self .flow_actions if action .get_key () == key )
83+ actions .extend (action for action in self .data_actions if action .get_key () == key )
84+ return actions
0 commit comments