<s> """<STR_LIT>""" <EOL> from model import Model <EOL> class FSM ( Model ) : <EOL> def __init__ ( self , module , exclude , include ) : <EOL> Model . __init__ ( self , module , exclude , include ) <EOL> def post_init ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self . module , '<STR_LIT>' ) : <EOL> self . actions = list ( self . actions_in_graph ( ) ) <EOL> else : <EOL> self . actions = list ( self . module . actions ) <EOL> Model . post_init ( self ) <EOL> self . graph = [ ( current , ( action , args , result ) , next ) <EOL> for ( current , ( action , args , result ) , next ) in <EOL> self . module . graph if action in self . actions ] <EOL> self . current = self . module . initial <EOL> def actions_in_graph ( self ) : <EOL> return tuple ( set ( [ action for ( current , ( action , args , result ) , next ) in <EOL> self . module . graph ] ) ) <EOL> def make_properties ( self , state ) : <EOL> return { '<STR_LIT>' : state in self . module . accepting , '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True } <EOL> def Properties ( self ) : <EOL> return self . make_properties ( self . current ) <EOL> def Reset ( self ) : <EOL> self . current = self . module . initial <EOL> def CleanupGraph ( self , cleanup = False ) : <EOL> """<STR_LIT>""" <EOL> if cleanup : <EOL> graph = [ ( current , ( action , args , result ) , next ) <EOL> for ( current , ( action , args , result ) , next ) in self . graph <EOL> if action in self . module . cleanup ] <EOL> else : <EOL> graph = self . graph <EOL> return graph <EOL> def ActionEnabled ( self , a , args ) : <EOL> """<STR_LIT>""" <EOL> return any ( [ ( a == action and ( not arguments or args == arguments ) ) <EOL> for ( current , ( action , arguments , result ) , next ) <EOL> in self . graph <EOL> if current == self . current ] ) <EOL> def EnabledTransitions ( self , cleanup = False ) : <EOL> """<STR_LIT>""" <EOL> graph = self . CleanupGraph ( cleanup ) <EOL> return [ ( action , args , result , next , self . make_properties ( next ) ) <EOL> for ( current , ( action , args , result ) , next ) in graph <EOL> if current == self . current ] <EOL> def DoAction ( self , a , arguments ) : <EOL> ts = [ ( current , ( action , args , result ) , next ) <EOL> for ( current , ( action , args , result ) , next ) in self . graph <EOL> if current == self . current and action == a <EOL> and args == arguments [ <NUM_LIT:0> : len ( args ) ] ] <EOL> current , ( action , args , result ) , self . current = ts [ <NUM_LIT:0> ] <EOL> return result <EOL> def Current ( self ) : <EOL> return self . current <EOL> def Restore ( self , state ) : <EOL> self . current = state </s>
