{ "info": { "author": "aimktech", "author_email": "code@aimechanics.tech", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: Education", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# amtFSM - A simple FSM\n\nThis library aims at provide an easy to use Finite State Machine.\n\n## Classes\n\n### **StateType**\nThis class defines the supported types for a State:\n- FSM_BEGIN_STATE: use to define a start point for the FSM\n- FSM_NORMAL_STATE: use to define a normal state for the FSM\n- FSM_END_STATE: use to define a end point for the FSM\n\n### **State**\nThis class defines a FSM State. Properties associated with a State are:\n- name: a unique identifier for this state\n- type: the type of this state as defined by the **StateType** class\n- enter_action: a string sent to the client when entering this state\n- exit_action: a string sent to the client when exiting this state\n\n### **Event**\nThis class defines a FSM Event. Property associated with an Event is:\n- name: a unique identifier for this event\n\n### **Transition**\nA transition describes the next state depending on the current state and the event. \nThe properties associated with a Transition are:\n- event: the Event triggering the transition\n- begin_state: the initial State for the transition\n- end_state: the end State for the transition\n\n### **FSM**\nThis class defines the FSM. \nThe following properties are available:\n- has_ended: True if the FSM is in END state\n- current: The current state for the FSM\n\nTo properly communicates with the client, the FSM needs:\n- a user callback method that takes an argument\n- a user queue where the callback methods will be pushed\n\nEverytime a change of states occured, the FSM will:\n- push the callback in the queue with the exit_action from the previous state\n- push the callback in the queue with the enter_action from the new state\n\n#### Methods available to the client\n\n*setup(user_callback, user_queue)* \n\nThis function is used to initiate the user callback and queue. \nThe user_queue should be an instance of *queue.Queue()* \nThe user_callback must take an argument:\n``` python\ndef user_callback(fsm_action):\n # do something with fsm_action\n #...\n```\n\n**FSMError** will be raise if the user_callback is not callable or if the user_queue is not an instance of *queue.Queue()*.\n\n***\n*add(transitions)* \n\nAdd a list of transitions to the FSM. Upon parsing this list, the FSM will construct its own repository of States and Events.\n\n***\n*state()* \n\nReturn the name of the current state or \"\" if not current state is defined.\n\n***\n*start()* \n\nSet the FSM on the starting point. \n*has_ended* will be set to **False**. \n\n**FSMError** will be raised if no starting point can be found in the list of states.\n\n***\n*stop()*\n\nSet the FSM on the ending point. \n*has_ended* will be set to **True**.\n\n**FSMError** will be raised if no ending point can be found in the list of states.\n\n***\n*update(event)* \n\nUpdate the FSM with the event. If the event is defined for the current state and the move is valid, the transition will occur.\n\n**FSMError** will be raised if:\n- the event is not defined for the current state\n- the end state is None\n\n***\n*can(state)* \n\nReturn **True** if the FSM can move to *state* from the current state. \nReturn **False** otherwise.\n\n***\n*cannot(state)* \n\nReturn **True** if the FSM cannot move to *state* from the current state. \nReturn **False** otherwise.\n\n***\n\n### **FSMBuilder**\nThis helper class is used for creating a FSM object from a **YAML** definition. \nExample:\n``` python\nbuilder = FSMBuilder(\"myFSMDefinition.yml\")\nfsm_composite = builder.parse()\n```\nUpon successful parsing of the YAML file, a **FSMBuilderComposite** object is created.\n\n***\n*FSMBuilder(filename)* \nConstructor.\n\n**FSMBuilderError** will be raised if the file cannot be found on the filesystem.\n\n***\n*parse(event_objects=True)* \n\nParse the file and build the FSMBuilderComposite object. \nIf *event_objects* is True, the parser will map each events to a specific string within the composite object. \nThe string will start with 'E' and follow by an index.\n\n*Example*: \nEvents are defined in the YAML file in this order 'PLAY', 'PAUSE', 'STOP'. \nThe composite object will have the properties:\n- E0 that will map to 'PLAY'\n- E1 that will map to 'PAUSE'\n- E2 that will map to 'STOP'\n\n\n**FSMBuilderError** will be raised in the following cases:\n- if the YAML file is not with the correct version\n- if the specific markers cannot be found in the file (see YAML file definition below)\n\n***\n\n### **FSMBuilderComposite**\nThis composite object is created when parsing a YAML file.\nThe properties available after creation are:\n- FSM: this is the FSM object\n- events: this list contains all the events found in the YAML definition\n- Exxx: mapping for the events in the list (optional)\n\n## Exceptions\n\n### **FSMError**\nThis is the generic Exception raised when a problem occured in the FSM.\n\n### **FSMBuilderError**\nThis is the generic Exception raised when a problem occured while building FSM from YAML file.\n\n## YAML file definition\n\nA set of mandatory markers should be defined in the file.\n\n### **Version**\n\nThis indicates the minimum version of the reader to decode this file. \nFor now, only version **0.1.0** is supported.\n\n### **Events**\n\nThe list of events defined for this FSM\n\n### **States**\n\nThe list of states defined for this FSM.\nThe properties defined for a state are:\n- name (MANDATORY): a unique name for this state\n- type (OPTIONAL): the type of this state (BEGIN, NORMAL, END) or NORMAL by default\n- enter (OPTIONAL): the action string when entering this state\n- exit (OPTIONAL): the action string when leaving this state\n\n### **Transitions**\n\nThe list of transitions for this FSM.\nEach transition should have:\n- event (MANDATORY): the name of the event as defined in Events\n- begin (MANDATORY): the name of the begining state\n- end (MANDATORY): the name of the ending state\n\n### **Example:**\n\n```yaml\n# define the version\nVersion: 0.1.0\n\n# define some events\nEvents:\n - E.PLAY\n - E.PAUSE\n - E.STOP\n\n# define some states\nStates:\n - name: S.PLAY\n type: BEGIN\n enter: \"play\"\n exit: \"\"\n - name: S.PAUSE\n type: NORMAL\n enter: \"pause\"\n - name: S.STOP\n type: END\n enter: \"stop\"\n\n# define some transitions\nTransitions:\n - event: E.PAUSE\n begin: S.PLAY\n end: S.PAUSE\n - event: E.PAUSE\n begin: S.PAUSE\n end: S.PAUSE\n\n - event: E.PLAY\n begin: S.PAUSE\n end: S.PLAY\n - event: E.PLAY\n begin: S.PLAY\n end: S.PLAY\n\n - event: E.STOP\n begin: S.PLAY\n end: S.STOP\n - event: E.STOP\n begin: S.PAUSE\n end: S.STOP\n - event: E.STOP\n begin: S.STOP\n end: S.STOP\n```\n\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/aimktech/amtFSM", "keywords": "", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "amtfsm", "package_url": "https://pypi.org/project/amtfsm/", "platform": "", "project_url": "https://pypi.org/project/amtfsm/", "project_urls": { "Homepage": "https://github.com/aimktech/amtFSM" }, "release_url": "https://pypi.org/project/amtfsm/0.1.0/", "requires_dist": [ "pyyaml (>=5.1.1)" ], "requires_python": "", "summary": "A simple to use Finite State Machine", "version": "0.1.0" }, "last_serial": 5543581, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "36bb4802fa1bb13747b3c60bf40c386b", "sha256": "331be35b4a5e8db7e8ee3c51a7057a0e2a4ceb6d12dadce1fa5fac92dc6d805c" }, "downloads": -1, "filename": "amtfsm-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "36bb4802fa1bb13747b3c60bf40c386b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11056, "upload_time": "2019-07-17T01:58:21", "url": "https://files.pythonhosted.org/packages/7b/a9/72ab20bed0c6e9ce9030f9ff229a5557c3a93aa5130fda2fd5aa661b70c8/amtfsm-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0cbf7d4894a6736c4f4b67d8aac44f71", "sha256": "d4758e4a1f90c293389290bf55a38d4545ca3c4a3ceaf1525c178b0f06043a39" }, "downloads": -1, "filename": "amtfsm-0.1.0.tar.gz", "has_sig": false, "md5_digest": "0cbf7d4894a6736c4f4b67d8aac44f71", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8204, "upload_time": "2019-07-17T01:58:23", "url": "https://files.pythonhosted.org/packages/b6/cf/58acb08984bd66f39bae69590ff54d3c61a223d94bfa20cb0ec19f134086/amtfsm-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "36bb4802fa1bb13747b3c60bf40c386b", "sha256": "331be35b4a5e8db7e8ee3c51a7057a0e2a4ceb6d12dadce1fa5fac92dc6d805c" }, "downloads": -1, "filename": "amtfsm-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "36bb4802fa1bb13747b3c60bf40c386b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11056, "upload_time": "2019-07-17T01:58:21", "url": "https://files.pythonhosted.org/packages/7b/a9/72ab20bed0c6e9ce9030f9ff229a5557c3a93aa5130fda2fd5aa661b70c8/amtfsm-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0cbf7d4894a6736c4f4b67d8aac44f71", "sha256": "d4758e4a1f90c293389290bf55a38d4545ca3c4a3ceaf1525c178b0f06043a39" }, "downloads": -1, "filename": "amtfsm-0.1.0.tar.gz", "has_sig": false, "md5_digest": "0cbf7d4894a6736c4f4b67d8aac44f71", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8204, "upload_time": "2019-07-17T01:58:23", "url": "https://files.pythonhosted.org/packages/b6/cf/58acb08984bd66f39bae69590ff54d3c61a223d94bfa20cb0ec19f134086/amtfsm-0.1.0.tar.gz" } ] }