{ "info": { "author": "Christian Maugg", "author_email": "software@christianmaugg.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries" ], "description": "``pystatemachine``\n==================\n\n``pystatemachine`` is a versatile, yet easy-to-use finite-state machine\nlibrary written in python. It provides functions to turn any python\nobject into a finite-state automaton which changes from one ``State`` to\nanother when initiated by a triggering ``event``.\n\nUsage\n=====\n\nA finite-state machine is defined by a list of its states, and the\ntriggering condition for each transition. ``pystatemachine`` offers an\n``event`` decorator for a classes' bound methods, a ``State`` class to\ndefine the finite-state machine's states, and a\n``acts_as_state_machine`` decorator for turning any python (new- or\nold-style) class into a finite-state machine. By default, any\n``event``-decorated method may raise errors. Optionally, a\n``transition_failure_handler`` decorator turns any class method into a\nfailure handler which gets invoked when an ``event``-decorated method\nraises an error.\n\nExample\n=======\n\nFollowing, a turnstile is modeled.\n\n An example of a very simple mechanism that can be modeled by a state\n machine is a turnstile. A turnstile is a gate with three rotating\n arms at waist height, one across the entryway. Initially the arms\n are locked, barring the entry, preventing customers from passing\n through. Depositing a coin or token in a slot on the turnstile\n unlocks the arms, allowing a single customer to push through. After\n the customer passes through, the arms are locked again until another\n coin is inserted. - from [Wikipedia]\n (http://en.wikipedia.org/wiki/Finite-state\\_machine#Example:\\_a\\_turnstile)\n\n.. code:: python\n\n @acts_as_state_machine\n class Turnstile(object):\n locked = State('locked', initial=True)\n unlocked = State('unlocked')\n\n @event(from_states=(locked, unlocked), to_state=unlocked)\n def coin(self):\n assert random.random() > .5, 'failing for demonstration purposes, only ..'\n print('*blingbling* .. unlocked!')\n\n @event(from_states=(locked, unlocked), to_state=locked)\n def push(self):\n print('*push* .. locked!')\n\n @transition_failure_handler(calling_sequence=2)\n def turnstile_malfunction(self, method, from_state, to_state, error):\n print('state transition from {0.name} to {1.name} failed. Reason: {2}'.format(from_state, to_state, error))\n\n @transition_failure_handler(calling_sequence=1)\n def before_turnstile_malfunction(self, method, from_state, to_state, error):\n print('before state transition failure handler ..')\n\n\n import random\n\n turnstile = Turnstile()\n for _ in range(10):\n handler = random.choice([turnstile.coin, turnstile.push])\n handler()\n\nChangelog\n=========\n\n1.2\n---\n\n- exceptions in an event-decorated function are now reraised when no\n transition failure handler was registered\n\n1.1\n---\n\n- added a decorator for registering a class' method as exception\n handler when an 'event'-decorated method fails. multiple methods may\n be registered as transition failure handler: they are invoked in the\n order given by the optional 'calling\\_sequence' keyword\n\n1.0\n---\n\n- first public release\n\nLicense\n=======\n\n``pystatemachine`` is available under `MIT\nLicense `__.\n\nDownload\n========\n\nYou can download\n`pystatemachine.py `__.\n\nAlternatively:\n\n::\n\n git clone git@github.com:cmaugg/pystatemachine", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/cmaugg/pystatemachine/tarball/1.2", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/cmaugg/pystatemachine", "keywords": "state finite-state machine automaton", "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "pystatemachine", "package_url": "https://pypi.org/project/pystatemachine/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pystatemachine/", "project_urls": { "Download": "https://github.com/cmaugg/pystatemachine/tarball/1.2", "Homepage": "https://github.com/cmaugg/pystatemachine" }, "release_url": "https://pypi.org/project/pystatemachine/1.2/", "requires_dist": null, "requires_python": null, "summary": "Simple Finite-State Machines", "version": "1.2" }, "last_serial": 1504585, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "e7dfe10e2ba1ea49a7b3570720907b00", "sha256": "dd54af4b661104b2bfa5d8fd70c39765a26cca25e8e69c5cc347279b3cf41e5d" }, "downloads": -1, "filename": "pystatemachine-1.0.zip", "has_sig": false, "md5_digest": "e7dfe10e2ba1ea49a7b3570720907b00", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7906, "upload_time": "2015-04-08T14:11:24", "url": "https://files.pythonhosted.org/packages/06/a9/19d3679b617eafdd436630dcc01716d73646623ff66077bde7b97e7e9a8f/pystatemachine-1.0.zip" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "290b4d7e61b59065744a9efcc9de8abf", "sha256": "6acb80acdbb0453680fc9c46e8f68fc251cbceae9adf19def8999513c70bfee1" }, "downloads": -1, "filename": "pystatemachine-1.1.zip", "has_sig": false, "md5_digest": "290b4d7e61b59065744a9efcc9de8abf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9217, "upload_time": "2015-04-13T10:04:20", "url": "https://files.pythonhosted.org/packages/a3/75/42715f2542867e4d0778b034d5832b4136b893fb1dfcbe0fcbd3bd6242a5/pystatemachine-1.1.zip" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "5cf8dba7e04c8f55f3508b0a3c0616d8", "sha256": "37601cdd388d15690e6e1d1fc1720e27f011a16e19c31c7c2b5a1d8078a206c0" }, "downloads": -1, "filename": "pystatemachine-1.2.zip", "has_sig": false, "md5_digest": "5cf8dba7e04c8f55f3508b0a3c0616d8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9836, "upload_time": "2015-04-14T09:36:30", "url": "https://files.pythonhosted.org/packages/ba/42/5d8c4601e6b69b8583b449a8a94148bac2e6fe6c8b74bee00145e94839db/pystatemachine-1.2.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5cf8dba7e04c8f55f3508b0a3c0616d8", "sha256": "37601cdd388d15690e6e1d1fc1720e27f011a16e19c31c7c2b5a1d8078a206c0" }, "downloads": -1, "filename": "pystatemachine-1.2.zip", "has_sig": false, "md5_digest": "5cf8dba7e04c8f55f3508b0a3c0616d8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9836, "upload_time": "2015-04-14T09:36:30", "url": "https://files.pythonhosted.org/packages/ba/42/5d8c4601e6b69b8583b449a8a94148bac2e6fe6c8b74bee00145e94839db/pystatemachine-1.2.zip" } ] }