{ "info": { "author": "Konstantin V.", "author_email": "mail@k-vinogradov.ru", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# FAVink\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/7134fd6ab3adcd626ac9/maintainability)](https://codeclimate.com/github/k-vinogradov/favink/maintainability)\n[![CodeFactor](https://www.codefactor.io/repository/github/k-vinogradov/favink/badge)](https://www.codefactor.io/repository/github/k-vinogradov/favink)\n[![Build Status](https://travis-ci.org/k-vinogradov/favink.svg?branch=master)](https://travis-ci.org/k-vinogradov/favink)\n\n- [FAVink](#favink)\n - [Getting Started](#getting-started)\n - [Transition Table and Initial State](#transition-table-and-initial-state)\n - [Events](#events)\n - [Event Handler Definitions](#event-handler-definitions)\n - [Car Example](#car-example)\n - [API Reference](#api-reference)\n - [Predefined `FiniteAutomata` Methods](#predefined-finiteautomata-methods)\n - [`FiniteAutomata.get_state(self)`](#finiteautomatagetstateself)\n - [`FiniteAutomata.get_allowed_transitions(self)`](#finiteautomatagetallowedtransitionsself)\n - [`FiniteAutomata.is_allowed(self, transition)`](#finiteautomataisallowedself-transition)\n - [Transition Methods](#transition-methods)\n\nOver-simple python finite automata (finite-state machine) implementation\n\n## Getting Started\n\nTo install favink use the package from the PyPI repository:\n\n```sh\npip install favink\n```\n\nTo add finite automata feature to the class in your code you have to inherit\nFiniteAutomata class and define the following members:\n\n- transitions table `transitions`\n- initial state `init_state`\n- event handlers methods.\n\nFor every transition the constructor creates a dynamic method with argument mask\n`(self, *args, **kwargs)`. Each method is named after the transition.\n\nTo make the transition you should call the transition method. After the method\nhas been called it changes the instance state and invoke related event handlers.\nIf the called transition isn't allowed for the current state `InvalidTransition`\nextension will be raised.\n\n## Transition Table and Initial State\n\nThe `transitions` is a dictionary where keys are transition names,\nvalues define the allowed and target states:\n\n```Python\ntransitions = {\n \"transition_1\":\n [\n \"allowed_state_1\",\n \"target_state_1\"\n ],\n \"transition_2\":\n [\n [\n \"allowed_state_2\",\n \"allowed_state_3\"\n ],\n \"target_state_2\"\n ]\n}\n```\n\nInitial state is defined by `init_state` member.\n\n## Events\n\n![Transition Life Cycle](https://github.com/k-vinogradov/favink/raw/master/docs/images/lifecycle.svg?sanitize=true)\n\nMaking of transition triggers the following events and invokes the related handlers\n(if they have been implemented in the class):\n\n- `after`\n- `before`\n- `on`\n\n### Event Handler Definitions\n\nFor every state (for example `state_name`) the following methods can be defined:\n\n```Python\ndef before_state_name(self, transition_detail):\n ...\n\n\ndef on_state_name(self, transition_detail, origin_state):\n ...\n\n\ndef after_state_name(self, transition_detail):\n ...\n```\n\nTransition detail is a 3-item tuple `(name, args, kwargs)` where\n\n- `name` is a transition name;\n- `args` is a list contains the positional arguments passed to the transition call,\n- `kwargs` is a dictionary with keyword arguments passed to the transition call,\n\nIf `after_...` or `before...` handlers raise the exception transition is aborted.\n\n## Car Example\n\n![Transition Life Cycle](https://github.com/k-vinogradov/favink/raw/master/docs/images/car.svg?sanitize=true)\n\n```Python\nclass Car(FiniteAutomata):\n init_state = \"stopped\"\n transitions = {\n \"start_engine\": [\"stopped\", \"idle\"],\n \"stop_engine\": [\"idle\", \"stopped\"],\n \"forward\": [\"idle\", \"moving_forward\"],\n \"backward\": [\"idle\", \"moving_backward\"],\n \"stop\": [[\"moving_forward\", \"moving_backward\"], \"idle\"],\n }\n\n def on_stopped(self, transition, origin):\n print(\"Engine has been stopped\")\n\n def on_idle(self, transition, origin):\n print(\"I'm not moving, but engine is on\")\n\n def on_moving_forward(self, transition, origin):\n print(\"Let's go!\")\n\n def on_moving_backward(self, transition, origin):\n print(\"Why are we retreating?\")\n\ncar = Car()\n\ncar.start_engine()\ncar.forward()\ncar.stop()\ncar.backward()\ncar.stop()\ncar.stop_engine()\n```\n\nOutput:\n\n```plain\nI'm not moving, but engine is on\nLet's go!\nI'm not moving, but engine is on\nWhy are we retreating?\nI'm not moving, but engine is on\nEngine has been stopped\n```\n\n## API Reference\n\n### Predefined `FiniteAutomata` Methods\n\n#### `FiniteAutomata.get_state(self)`\n\nReturns the current instance state name as a string.\n\n#### `FiniteAutomata.get_allowed_transitions(self)`\n\nReturn the list contains all transactions which are allowed for the current instance state.\n\n#### `FiniteAutomata.is_allowed(self, transition)`\n\n### Transition Methods\n\nDynamically defined methods for every transition (key) in the `transitions` dictionary.\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/k-vinogradov/favink", "keywords": "finite automata,finite state machine,state machine,vink", "license": "MIT", "maintainer": "Konstantin V.", "maintainer_email": "mail@k-vinogradov.ru", "name": "favink", "package_url": "https://pypi.org/project/favink/", "platform": "", "project_url": "https://pypi.org/project/favink/", "project_urls": { "Homepage": "https://github.com/k-vinogradov/favink" }, "release_url": "https://pypi.org/project/favink/1.1.1/", "requires_dist": null, "requires_python": ">=3.5,<4.0", "summary": "Over-simple Python finite automata (finite-state machine) implementation", "version": "1.1.1" }, "last_serial": 5632860, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "ba13c004400b8a442dc4763b8ac50a1a", "sha256": "6a43901fe7701961562b00a54dbe66b340639d12bcd122c76fb4abf2b7b830ff" }, "downloads": -1, "filename": "favink-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "ba13c004400b8a442dc4763b8ac50a1a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 4305, "upload_time": "2019-05-23T11:08:43", "url": "https://files.pythonhosted.org/packages/7f/49/daa98765e6436d811c3d777dcc83225e030db30789f07b5f56e5aeef6fa6/favink-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9d3c1b71f42fd32b7b2daeda3ab097bd", "sha256": "b4e90c95ff2452573249a094a72fae4b74020386bb4fea4e52be9e3b049628e1" }, "downloads": -1, "filename": "favink-0.1.0.tar.gz", "has_sig": false, "md5_digest": "9d3c1b71f42fd32b7b2daeda3ab097bd", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 4396, "upload_time": "2019-05-23T11:08:45", "url": "https://files.pythonhosted.org/packages/f2/dc/8c87dbee8a3d33d65a5e49c1e60a32adc1b179c65318413f5119f43d450b/favink-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "5d33e9d2f8d585c60441fb2b395ddd83", "sha256": "b1e8fc043afebffe49b2ed8128001bc553ae97bd593880381941e44383725fa9" }, "downloads": -1, "filename": "favink-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "5d33e9d2f8d585c60441fb2b395ddd83", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 4366, "upload_time": "2019-05-23T11:28:02", "url": "https://files.pythonhosted.org/packages/3c/3e/106df8117da0a02c71a31ccf6cda8d3eb68ec9b39f4b926ba07ef5086b77/favink-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d11fc0c2141efef1b0e7d4cd69584dbd", "sha256": "43b82cd4cf03d5ac755f34ec8d7de2007888839d120d4010ebbeb327e550bf77" }, "downloads": -1, "filename": "favink-0.1.1.tar.gz", "has_sig": false, "md5_digest": "d11fc0c2141efef1b0e7d4cd69584dbd", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 4534, "upload_time": "2019-05-23T11:28:03", "url": "https://files.pythonhosted.org/packages/eb/c3/ca866891aba525c0004aadeef6323cbb38c103beb6890a5c35ebd3347b90/favink-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "ded97e980947ad77d971c2c30a2d80f5", "sha256": "a4a6ecb52ca886928a622c514e28fc2c8033ce58f15ed235aae18b8793168533" }, "downloads": -1, "filename": "favink-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "ded97e980947ad77d971c2c30a2d80f5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 4417, "upload_time": "2019-05-25T03:19:55", "url": "https://files.pythonhosted.org/packages/19/a1/c1a4d7362d5829fba90cb7abd9d95a02f28819bfdc575c7f64712ecf2abc/favink-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8161937a5f749a77f9d4f18300de1660", "sha256": "0f75c25cc79874abc41fd1052060568af8bdfcdc6abbf910157154b13d963c4a" }, "downloads": -1, "filename": "favink-0.1.2.tar.gz", "has_sig": false, "md5_digest": "8161937a5f749a77f9d4f18300de1660", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 4584, "upload_time": "2019-05-25T03:19:56", "url": "https://files.pythonhosted.org/packages/ea/9e/99f3b6f497ed05c589d37b951c4e425d526a33aae6a57be2a879f0fcba1e/favink-0.1.2.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "cbeacde729a78b935c88d0f52e8aa1d3", "sha256": "8c310edff199285a52370486751056d57fcfaca590afab1902b6b7c437cac3e9" }, "downloads": -1, "filename": "favink-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "cbeacde729a78b935c88d0f52e8aa1d3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 4565, "upload_time": "2019-06-03T09:10:50", "url": "https://files.pythonhosted.org/packages/44/cb/bcc329ae2426464c56bd51a889f17dd89bf76ce7055625406ef9d13a0440/favink-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e1c026e3929f659f603220cc14fd7eb9", "sha256": "f11f588d4aae0b07995f578b978b287758e9109fdb8354901bd0c7bf694677bb" }, "downloads": -1, "filename": "favink-1.0.0.tar.gz", "has_sig": false, "md5_digest": "e1c026e3929f659f603220cc14fd7eb9", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 4748, "upload_time": "2019-06-03T09:10:51", "url": "https://files.pythonhosted.org/packages/12/fe/35bbe02b659e17dc1ac2d9ee56e5975c0ed6f7e9f6929338987c3cd5f41a/favink-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "1da93cebca8debce0f7fa954f1513706", "sha256": "73b635a4c198a44c2df6997f67bbf9886279248b730f2c6d3e3b47f03dbf0c0b" }, "downloads": -1, "filename": "favink-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "1da93cebca8debce0f7fa954f1513706", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5,<4.0", "size": 4581, "upload_time": "2019-08-05T05:03:17", "url": "https://files.pythonhosted.org/packages/ef/c7/f9614c3dc3bf5cc7ac53428b4213271d01e8b3a220d4cab28d9d606078d0/favink-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ccc84df40040496fb25e7a6ef2cc7885", "sha256": "64b47b95a622ab69056bad094e932bbb26b1dfcc34fe7b3d98ea6652d91d47ca" }, "downloads": -1, "filename": "favink-1.1.0.tar.gz", "has_sig": false, "md5_digest": "ccc84df40040496fb25e7a6ef2cc7885", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5,<4.0", "size": 4777, "upload_time": "2019-08-05T05:03:19", "url": "https://files.pythonhosted.org/packages/6f/5a/cce13c7666816d656bb27d4876b860c17870e9518b882edffd704a73f58b/favink-1.1.0.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "5c29153e2aea8ed01d9ae086713989d5", "sha256": "5f258f2df15df96a7bad1384aed2f4eec1dc59e6b5f6d8b541611eb98175602d" }, "downloads": -1, "filename": "favink-1.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "5c29153e2aea8ed01d9ae086713989d5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5,<4.0", "size": 4580, "upload_time": "2019-08-05T06:55:50", "url": "https://files.pythonhosted.org/packages/66/97/ff08361ccaee06b76615b2dcbe6955dcb01dd1abe41261101f76ebff8a8d/favink-1.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c796c4db1ac70357f5d85fc69337fe7a", "sha256": "1f3fc3554663af6124f988d52d797e0bfbdbcc5c9307a6bc8aa0b2e101314c8d" }, "downloads": -1, "filename": "favink-1.1.1.tar.gz", "has_sig": false, "md5_digest": "c796c4db1ac70357f5d85fc69337fe7a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5,<4.0", "size": 4789, "upload_time": "2019-08-05T06:55:52", "url": "https://files.pythonhosted.org/packages/b1/04/c6c7929dc9bdc2e12ee61289d03a86c29b37b093863e8bfc7bb0d9b365b9/favink-1.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5c29153e2aea8ed01d9ae086713989d5", "sha256": "5f258f2df15df96a7bad1384aed2f4eec1dc59e6b5f6d8b541611eb98175602d" }, "downloads": -1, "filename": "favink-1.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "5c29153e2aea8ed01d9ae086713989d5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5,<4.0", "size": 4580, "upload_time": "2019-08-05T06:55:50", "url": "https://files.pythonhosted.org/packages/66/97/ff08361ccaee06b76615b2dcbe6955dcb01dd1abe41261101f76ebff8a8d/favink-1.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c796c4db1ac70357f5d85fc69337fe7a", "sha256": "1f3fc3554663af6124f988d52d797e0bfbdbcc5c9307a6bc8aa0b2e101314c8d" }, "downloads": -1, "filename": "favink-1.1.1.tar.gz", "has_sig": false, "md5_digest": "c796c4db1ac70357f5d85fc69337fe7a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5,<4.0", "size": 4789, "upload_time": "2019-08-05T06:55:52", "url": "https://files.pythonhosted.org/packages/b1/04/c6c7929dc9bdc2e12ee61289d03a86c29b37b093863e8bfc7bb0d9b365b9/favink-1.1.1.tar.gz" } ] }