Most viewed recipes tagged "state"http://code.activestate.com/recipes/tags/state/views/2015-07-15T12:37:13-07:00ActiveState Code Recipessimple state machine implementation (Python)
2010-07-15T17:54:17-07:00David Klaffenbachhttp://code.activestate.com/recipes/users/2007923/http://code.activestate.com/recipes/577308-simple-state-machine-implementation/
<p style="color: grey">
Python
recipe 577308
by <a href="/recipes/users/2007923/">David Klaffenbach</a>
(<a href="/recipes/tags/machine/">machine</a>, <a href="/recipes/tags/state/">state</a>).
</p>
<p>A very simple idiom for implementing a state machine.</p>
State FIPS Codes Dict (Python)
2011-07-01T17:22:36-07:00Zach Williamshttp://code.activestate.com/recipes/users/4178496/http://code.activestate.com/recipes/577775-state-fips-codes-dict/
<p style="color: grey">
Python
recipe 577775
by <a href="/recipes/users/4178496/">Zach Williams</a>
(<a href="/recipes/tags/fips/">fips</a>, <a href="/recipes/tags/fips_codes/">fips_codes</a>, <a href="/recipes/tags/state/">state</a>, <a href="/recipes/tags/states/">states</a>).
</p>
<p>Had to put state codes with their FIPS code into a dict, and took way longer than I expected. Thought someone else might benefit from this.</p>
Dynamically Generated Python State Machine (Python)
2011-09-30T05:16:56-07:00__nerohttp://code.activestate.com/recipes/users/4177968/http://code.activestate.com/recipes/577693-dynamically-generated-python-state-machine/
<p style="color: grey">
Python
recipe 577693
by <a href="/recipes/users/4177968/">__nero</a>
(<a href="/recipes/tags/dynamically/">dynamically</a>, <a href="/recipes/tags/finite/">finite</a>, <a href="/recipes/tags/generated/">generated</a>, <a href="/recipes/tags/machine/">machine</a>, <a href="/recipes/tags/state/">state</a>).
Revision 6.
</p>
<p>This is a state machine template. It can be used as a state machine, or a state machine tester. There is very little setup required and all the states are added based on the state docstring. I made this after a friend came to me asking how I'd implement one, complaining that he couldn't find a nice example. I hope this helps.</p>
Pretty and Stated HTMLParsers (Python)
2013-12-14T00:28:36-08:00Ádám Szieberthhttp://code.activestate.com/recipes/users/4188745/http://code.activestate.com/recipes/578787-pretty-and-stated-htmlparsers/
<p style="color: grey">
Python
recipe 578787
by <a href="/recipes/users/4188745/">Ádám Szieberth</a>
(<a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/htmlparser/">htmlparser</a>, <a href="/recipes/tags/state/">state</a>).
Revision 2.
</p>
<p>Extensions of html.parser.HTMLParser().</p>
<p>PrettyHTMLParser() does not splits data into chuncks by HTML entities.
StatedHTMLParser() can have many state-dependent handlers which helps parsing HTML pages alot.</p>
Hivemind (Python)
2015-07-15T12:37:13-07:00Oscar Byrnehttp://code.activestate.com/recipes/users/4192487/http://code.activestate.com/recipes/579082-hivemind/
<p style="color: grey">
Python
recipe 579082
by <a href="/recipes/users/4192487/">Oscar Byrne</a>
(<a href="/recipes/tags/borg/">borg</a>, <a href="/recipes/tags/defaultdict/">defaultdict</a>, <a href="/recipes/tags/hash/">hash</a>, <a href="/recipes/tags/hashing/">hashing</a>, <a href="/recipes/tags/hivemind/">hivemind</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/singleton/">singleton</a>, <a href="/recipes/tags/state/">state</a>).
</p>
<p>Inspired by the ever-popular Borg pattern, objects inheriting from Hivemind share state if initialised with the same arguments</p>
Save and restore SHA-512 internal state (Python)
2013-03-03T18:05:42-08:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/578479-save-and-restore-sha-512-internal-state/
<p style="color: grey">
Python
recipe 578479
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
(<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/inner/">inner</a>, <a href="/recipes/tags/pickle/">pickle</a>, <a href="/recipes/tags/restore/">restore</a>, <a href="/recipes/tags/sha512/">sha512</a>, <a href="/recipes/tags/state/">state</a>).
</p>
<p>If you have a very long input to hash, you may want to save your progress.</p>
<p>CPython doesn't normally let you, but it's easy to hack around via ctypes</p>
Generator Attributes (Python)
2010-02-18T17:23:59-08:00Longpokehttp://code.activestate.com/recipes/users/4173085/http://code.activestate.com/recipes/577057-generator-attributes/
<p style="color: grey">
Python
recipe 577057
by <a href="/recipes/users/4173085/">Longpoke</a>
(<a href="/recipes/tags/concurrency/">concurrency</a>, <a href="/recipes/tags/state/">state</a>).
</p>
<p>A decorator that creates a generator factory that creates generators that can have attributes set on them (like a normal python class).</p>