Most viewed recipes tagged "state_machine"http://code.activestate.com/recipes/tags/state_machine/views/2013-09-12T19:50:06-07:00ActiveState Code RecipesEasy State Pattern - support for implementing state machines (Python) 2009-06-15T11:25:17-07:00Rodney Drenthhttp://code.activestate.com/recipes/users/4050661/http://code.activestate.com/recipes/576613-easy-state-pattern-support-for-implementing-state-/ <p style="color: grey"> Python recipe 576613 by <a href="/recipes/users/4050661/">Rodney Drenth</a> (<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/metaclasses/">metaclasses</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/state_machine/">state_machine</a>, <a href="/recipes/tags/state_pattern/">state_pattern</a>). Revision 3. </p> <p>Provides is a module that gives support for implementing state machines. States are implemented as subclasses, derived from the state machine class. Methods that are state dependant or which cause transitions are declared using decorators. Because states can be subclasses of other states, common behaviour among several states is easily supported. The implementation allows for implementing multiple states or substates within a class.</p> <p>This module best support statem achines implemeting controllers for embedded systems, implementing user interfaces, or in discrete event model simulation. Parsers, which generally have many states and where you would need to define a Transaction method for each different character encountered would be more easily implemented by other means.</p> State Machine Framework (AI) (Python) 2013-09-12T19:50:06-07:00Matt Joneshttp://code.activestate.com/recipes/users/4182764/http://code.activestate.com/recipes/578656-state-machine-framework-ai/ <p style="color: grey"> Python recipe 578656 by <a href="/recipes/users/4182764/">Matt Jones</a> (<a href="/recipes/tags/artificial_intelligence/">artificial_intelligence</a>, <a href="/recipes/tags/state_machine/">state_machine</a>). </p> <p>A simple state machine framework that could be used for AI or long processing operations. A simple example is provided as well.</p> <p>Python 3.2 required</p> State Machine for Text Processing (Python) 2009-01-21T14:01:23-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/576624-state-machine-for-text-processing/ <p style="color: grey"> Python recipe 576624 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/state_machine/">state_machine</a>, <a href="/recipes/tags/text_processing/">text_processing</a>). </p> <p>General state machine mechanism plus a specialized version, LineStateMachine, for processing text files based by using regular expressions to determine state transitions.</p> SyncFiles (Python) 2008-12-13T21:28:57-08:00Collin Stockshttp://code.activestate.com/recipes/users/4149235/http://code.activestate.com/recipes/576584-syncfiles/ <p style="color: grey"> Python recipe 576584 by <a href="/recipes/users/4149235/">Collin Stocks</a> (<a href="/recipes/tags/backup/">backup</a>, <a href="/recipes/tags/consistency/">consistency</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/gnu/">gnu</a>, <a href="/recipes/tags/gpl/">gpl</a>, <a href="/recipes/tags/just_in_case/">just_in_case</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/pickle/">pickle</a>, <a href="/recipes/tags/state_machine/">state_machine</a>, <a href="/recipes/tags/storage/">storage</a>, <a href="/recipes/tags/sync/">sync</a>, <a href="/recipes/tags/synchronize/">synchronize</a>). Revision 3. </p> <p>This module allows you to handle and protect from inconsistencies sets of files that must all be saved at the same time. It does this be creating backups and temporary files. It has been moderately tested for bugs.</p> Recursive Functional State Machine (Python) 2011-05-20T13:46:48-07:00Stefan Tunschhttp://code.activestate.com/recipes/users/4178042/http://code.activestate.com/recipes/577709-recursive-functional-state-machine/ <p style="color: grey"> Python recipe 577709 by <a href="/recipes/users/4178042/">Stefan Tunsch</a> (<a href="/recipes/tags/functional/">functional</a>, <a href="/recipes/tags/recursion/">recursion</a>, <a href="/recipes/tags/state_machine/">state_machine</a>). </p> <p>This is a simple state machine that takes a functional approach. It requires trampoline from pysistence.func to avoid the recursion limit.</p> <p>Namedtuples are used to define the different states. globals() is used to reference the states. (This could also be done putting states into a separate module and getting them through getattr.)</p> <p>In this recipe the functions called in the different states need to return a boolean, which defines the success or failure event.</p> A flexible state machine class (Python) 2011-05-18T15:17:02-07:00Mike Sweeneyhttp://code.activestate.com/recipes/users/4177990/http://code.activestate.com/recipes/577701-a-flexible-state-machine-class/ <p style="color: grey"> Python recipe 577701 by <a href="/recipes/users/4177990/">Mike Sweeney</a> (<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/state_machine/">state_machine</a>). Revision 2. </p> <p>The operation of the state machine is defined by transitions. The transitions control what value is returned and which new state to switch to, given an "event" input when in a certain current "state". State machines have many applications such as games, process controls, and language parsing.</p> Parser Keylogger based on a Finite State Machine (Python) 2011-11-21T14:53:52-08:00Filippo Squillacehttp://code.activestate.com/recipes/users/4174931/http://code.activestate.com/recipes/577952-parser-keylogger-based-on-a-finite-state-machine/ <p style="color: grey"> Python recipe 577952 by <a href="/recipes/users/4174931/">Filippo Squillace</a> (<a href="/recipes/tags/keylogger/">keylogger</a>, <a href="/recipes/tags/parser/">parser</a>, <a href="/recipes/tags/state_machine/">state_machine</a>). Revision 3. </p> <p>This program parses the logfile given by the execution of the keylogger command <strong>'script -c "xinput test ID_CODE" | cat LOG_FILE'</strong> and it is based on a Finite State Machine (FSM) to manage all the possible combinations of the modifiers that represent the state of the FSM. The parser gets the mapping between the couple of keycode and modifier typed and the corresponding char by xmodmap command. The parser is able to manage also extended combinations such as Control or Super that don't give a real char. To introduce new possible states that represent new combinations between modifiers, it's just necessary to update the list of state (<em>mod_keys</em>) and add new rules in the transition function properly. For example to introduce the Caps Lock state just add it in mod_keys and the data structure transition has to handle the release event of the corresponding key. For the dependency of xmodmap the parser works only in X11 based systems.</p>