{ "info": { "author": "manu chatterjee", "author_email": "deftio@deftio.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "[![PyPI version](https://badge.fury.io/py/fifostr.svg)](https://badge.fury.io/py/fifostr)\n[![Build Status](https://travis-ci.org/deftio/fifostr.svg?branch=master)](https://travis-ci.org/deftio/fifostr)\n[![Coverage Status](https://coveralls.io/repos/github/deftio/fifostr/badge.svg?branch=master)](https://coveralls.io/github/deftio/fifostr?branch=master)\n[![License](https://img.shields.io/badge/License-BSD%202--Clause-blue.svg)](https://opensource.org/licenses/BSD-2-Clause)\n\n\n# fifostr.py\n\nFIFOStr - A small python library for mutable strings with a built-in streaming pattern parser. \n\nOriginally a lighter version of this was used in a python serial terminal program dioterm (which allowed the serial terminal to parse commands sent/received by both sides). FIFOstr allowed program actions to be triggered based on patterns received from the incoming serial data content. \n\n## Pattern Triggering Features \n\nBuilt-in pattern matching and triggering: simply add / remove patterns which then call a callback function (E.g. if the pattern is \"seen\" then trigger the function). Patterns can be strings, regexes or user-supplied-functions (parsers written in python). A pattern consists of: \n * pattern: string *or* compiled regex *or* user-supplied-parser-function \n * label: user supplied 'name' for this pattern \n * start index : position in fifostr to begin pattern match. default is 0 (also accepts the character '^' as start anchor for those familiar with regexes)\n * stop index : position in fifostr to end pattern match. default is end of fifostr. the letter '$' has special meaning as end of string no matter the length (again regex)\n * callback_fn : called if pattern is found, fifostr(start:end) and the label are passed to the callback function (callback('thematchingstring','label'))\n * active : default is True, sets whether this pattern should be actively looked for \n\n\n### Installation\n```\npip install fifostr # or just pull fifostr.py from the source repository and put in your source path \n```\n\n### Original Usage\n\nOriginally part of a terminal program called 'dioterm' (albeit in much more compact form), this library was used used to 'listen' to traffic in either direction on a serial port. When certain patterns were found such as a command sent from the host or a special piece of data from the embedded microntroller client, fifostr would trigger a callback to do something. This was very useful when sequences of commands had to be set up between the host and client. Many of these sequences where conditional based on what either the host or client sent resulting in many variations of sequence-test cases, especially if this results in the host then having to make some other call to an unrelated process or hardware to reply correctly.\n\n\n### Functionality \nFIFOStr is a string which is (derived from deque) with these properties: \n * add/remove chars or strings at either end \n * mutable (can set a char to any value like an array with [])\n * use slices, lists, or tuples to retrieve members (just like a real str object) \n * get head/tail (returns as a str) \n * match head/tail --> match a supplied string to either the head or tail \n * use patterns to trigger callbacks --> pattern can be string | regex | user_supplied_parser any of which triggers user supplied callback_fn \n * all patterns can look at either the whole fifostr or any subset e.g. addPattern(\"foo\",myCallback,2,5,\"bar\") \n --> only looks for \"foo\" between positions 2 and 5 in the fifostr and will call myCallback with (\"foo\",\"bar\") if found\n * all patterns have optional label which can be used for logging purposes (eg. when pattern found, in addition to callback, emit label) \n * user supplied callback_fn is called with both the string-match section and the label \n * patterns can be added/deleted from the list of patterns \"watching\" the fifostr content\n * all (active) patterns are always matched. fifostr matches multiple different patterns over the same string. \n * clear all patterns --> removes patterns from processing \n * get/setPattern Active/Inactive --> allows a stored pattern to set on or off \n * Python 2.7+, Python 3+ support with no mods, no dependancies \n * 100% test coverage in both 2.7 and 3.x \n\n### Usage example \n\nSee example.py to run in tests dir -- same examples as here but more comments, more use cases \n\n```python\nfrom fifostr import FIFOStr\ndef main():\n myFifoStr=FIFOStr(5) #make a fifostr of length 5 (for unlimited length omit number)\n myFifoStr+='1234567' #adds 1234567 to fifostr ... but len of fifostr is 5\n # so only 34567 is retained\n\n print \"myFifoStr.head(3)= \",myFifoStr.head(3) #shows 345\n print \"myFifoStr.tail(4)= \",myFifoStr.tail(4) #shows 4567\n\n # the eqhead and eqtail functions allow string compares against\n # the head or the tail\n\n myFifoStr.eqhead(\"3456\") #True\n myFifoStr.eqhead(\"567\") #False\n myFifoStr.eqtail(\"4567\") #True\n myFifoStr.eqtail(\"abc\") #False\n\n #fifostr.testPattern() allows you to test if the pattern is present in the fifostr object\n #test a string pattern directly\n myFifoStr.testPattern('67890') #False\n\n #test a regex pattern directly. to do this pass any valid regex in compiled form\n r1=re.compile(\"[0-9]+\")\n myFifoStr.testPattern(r1) #True\n\n r2=re.compile(\"[a-z]+\")\n myFifoStr.testPattern(r2) #False\n\n #more generally we can add (and remove) patterns which will scan and trigger a call back everytime the fifostr \n #internal content changes (whether adding or deleting chars from either end or even rotating/reversing the fifstr object)\n\n #adding patterns\n p1 = myFifoStr.addPattern(\"234\",logf,label=\"234 was here\") #integer index returned managing pattern \n p2 = myFifoStr.addPattern(\"67890\",logf,label=\"67890 detected\")\n p3 = myFifoStr.addPattern(r1,logf,label=\"r1 detected\")\n myFifoStr.addPattern(r2,logf,label=\"r2 hit\")\n myFifoStr.addPattern(f1,logf,label=\"f1 hit\") \n myFifoStr.addPattern(f2,logf,label=\"f2 hit\") \n\n #patterns can be set active/inactive via pattern management fns \n myFifoStr.setPatternActiveState(p1,False) #based on index returned from addPattern\n\n #now show searching for stored pattern matchers in the pattern dict\n #this is not searching the fifo-string itself, just the stored patterns that we have entered\n print(\"find pattern by label 'foo':\",myFifoStr.findPatternByLabel(\"foo\")) #no matches returns empty list\n print(\"find pattern by label '234 hit':\",myFifoStr.findPatternByLabel(\"234 hit\")) #shows match\n print(\"find pattern by label using regex '[rf][0-9]':\")\n pp.pprint(myFifoStr.findPatternByLabel(re.compile(\"[rf][0-9]\")))\n\n #and finally demonstrate that patterns auto-trigger when items inserted in fifostr .. which afterall\n #is the point of the whole thing.. ;)\n print(\"\\n fifo operations ============\")\n for c in '01234567890abcdefghijklmnop': #show using inc which accomplishes same thing\n myFifoStr += c\n\n myFifoStr+= 'abcdefghi'\n print (myFifoStr.all())\n\n```\n\n### Notes \n\nFIFOstr is not meant replacement for a compiler/parser front end though it can be used as complex tokenizer. Internally just iterates over stored patterns every time something is added to the fifostr object. If you do have a parser you wish to be called then just add it as a callback function so that every time the fifostr is updated with a char(s) it will call your parser to do the work. Your parser must return a boolean result if you wish to use the callback based triggering. Multiple custom parsers can be run in along with static string patterns or regexes.\n\n\n```python\n#let your own parser do the work \n myFifo = fifostr(20) # make a 20 char fifostr\n myFifo.addPattern(myParser,myCallbk) #myParser passed entire fifostr (as str) when char(s) added\n myFifo.addPattern(myParser,myCallbk2,3,5) #myParser passed fifostr btw (3,5). My Parser must return True if match found for callback to be invoked\n\n```\n\n### Source code \nall source is at github: \nhttps://github.com/deftio/fifostr \n\n### Project Home\nhttps://deftio.com/fifostr\n\n### Company Home\ndocs and other projects at \nhttps://deftio.com/ \n\n### Tests & Coverage\nfor quick usage see \nsee __main__ in example.py file \n\nfor test coverage look in the /tests directory \nto run tests pytest needs to be installed. \n\n#### on Ubuntu \n```bash\npip install -U pytest pytest-cov \npip install coveralls \n```\nnote: more info at pytest.org for installation on other OSes \n\n```bash\n# running basic tests\ncd tests\npytest #or py.test \n\n# coverage stats below\ncoverage run --source fifostr -m pytest \ncoverage report -m\n```\n### Generating docs\nDocumenation is generated using pandoc and pydoc from the build scripts.\n\n```bash\nsudo apt-get install pandoc\n```\ndocumentation is in /docs directory (generated by pydoc)\nto (re)generate the docs. cd to the docs directory. then type:\n```bash\npydoc -w ../fifostr.py \n```\nnote that as of this writing pydoc generates its output in the current directory and doesn't seem to be pipeable to another. \n\n### Release History \n* 1.1.11 updated PyPi to use README.md instead of README.rst (no other changes)\n* 1.1.10 Updated docs and related usage info for repo\n* 1.1.9 rebuild for README.md to README.rst conversion using pandoc (no code changes) for PyPi\n* 1.1.8 rebuild to make sure proper pkg loaded to PyPi (no code changes) \n* 1.1.7 updated MANIFEST.in to use README.rst \n* 1.1.6 added PyPi version badge in README.md\n* 1.1.5 coverage to 100%, added badging, added README.rst\n* 1.1.x changed class name from fifostr to FIFOStr to make PEP8 compliant. fixed bug in setup.py (package_dir)\n* 1.0.x documentation clean up\n* 1.0.0 Initial release \n\n\n### README.md vs README.rst \nThe README.rst is generated from the README.md using pandoc but the content is identical. (used for PyPi in earlier releases)\n\n\n### License\nSee LICENSE.txt file in this directory. The license is the OSI approved \"FreeBSD\" 2 clause license.\n\n\n\n(c) 2018 m a chatterjee\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://pypi.python.org/pypi/fifostr", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/deftio/fifostr", "keywords": "string stream parsing,parser utilities", "license": "BSD License", "maintainer": "", "maintainer_email": "", "name": "fifostr", "package_url": "https://pypi.org/project/fifostr/", "platform": "", "project_url": "https://pypi.org/project/fifostr/", "project_urls": { "Download": "https://pypi.python.org/pypi/fifostr", "Homepage": "https://github.com/deftio/fifostr" }, "release_url": "https://pypi.org/project/fifostr/1.1.15/", "requires_dist": [ "check-manifest; extra == 'dev'", "pytest; extra == 'test'" ], "requires_python": "", "summary": "fifostr - A FIFO (first in first out) buffer for strings derived from deque with pattern match callbacks", "version": "1.1.15" }, "last_serial": 4474876, "releases": { "1.0.8": [ { "comment_text": "", "digests": { "md5": "a97aa504e973d7dccc7aa001f538bb15", "sha256": "7bda5a923e71cdacb29ca51ae5f7affffeed30c86b48d0bf2111a607e625bd61" }, "downloads": -1, "filename": "fifostr-1.0.8.tar.gz", "has_sig": false, "md5_digest": "a97aa504e973d7dccc7aa001f538bb15", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12342, "upload_time": "2016-07-17T07:35:09", "url": "https://files.pythonhosted.org/packages/73/10/8bc4211fba97591848a322a8cb00dda87d81da8f8ea10a4e738b9799e37d/fifostr-1.0.8.tar.gz" } ], "1.0.81": [ { "comment_text": "", "digests": { "md5": "03ae30ff655ef203b23979c422c741f3", "sha256": "316fa0d60ceae01c93c5948635597e90484b5683429973f7fa587e5e66d95928" }, "downloads": -1, "filename": "fifostr-1.0.81.tar.gz", "has_sig": false, "md5_digest": "03ae30ff655ef203b23979c422c741f3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12414, "upload_time": "2016-07-17T15:41:53", "url": "https://files.pythonhosted.org/packages/b2/33/45a315b1353567e4c2dd4df3a2de37ce840452c33af563a785ee1e646e09/fifostr-1.0.81.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "9d7675ba4c0e0ccb567fcfd28442f442", "sha256": "cb0abf062ec49689e7abb48f32f9b2a3a894fb064a8e17d6cd2927675ebcd907" }, "downloads": -1, "filename": "FIFOStr-1.1.0.tar.gz", "has_sig": false, "md5_digest": "9d7675ba4c0e0ccb567fcfd28442f442", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12835, "upload_time": "2016-07-22T07:39:31", "url": "https://files.pythonhosted.org/packages/00/13/0be2efd7e74ea8787db16fd4293dfb42b06d72921134439ea908b45109bf/FIFOStr-1.1.0.tar.gz" } ], "1.1.10": [ { "comment_text": "", "digests": { "md5": "3a75eb8ac8cdacbf77df3ac5057a4579", "sha256": "aab4806f27d34ebfcfe6e2a1dc3b1c74d3df3703984d2c189c879e62231190f8" }, "downloads": -1, "filename": "FIFOStr-1.1.10.tar.gz", "has_sig": false, "md5_digest": "3a75eb8ac8cdacbf77df3ac5057a4579", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17492, "upload_time": "2018-11-10T00:55:24", "url": "https://files.pythonhosted.org/packages/c9/79/f1263a6e246f812e22fcf05456a30435f365389a595f927164503d13a7c5/FIFOStr-1.1.10.tar.gz" } ], "1.1.15": [ { "comment_text": "", "digests": { "md5": "67d8c8d565697744c276117c67609644", "sha256": "9bf7d5183eff943cbc00e1429855219702797f046299f62e728ddc2fdf505fc4" }, "downloads": -1, "filename": "FIFOStr-1.1.15-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "67d8c8d565697744c276117c67609644", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12558, "upload_time": "2018-11-11T18:15:40", "url": "https://files.pythonhosted.org/packages/8f/89/46f6560f6ba2dd009c9948237e58be246200b652ddb4aec03b21cd55a1ab/FIFOStr-1.1.15-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6431119a2e38d875a1ff54e262587700", "sha256": "968a2d41a7f232e56c8d0378deff0c2ce3c94fe7125ad2271d7ef84ec8f156d2" }, "downloads": -1, "filename": "FIFOStr-1.1.15.tar.gz", "has_sig": false, "md5_digest": "6431119a2e38d875a1ff54e262587700", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17268, "upload_time": "2018-11-11T18:15:41", "url": "https://files.pythonhosted.org/packages/b1/47/05024f47425aa29199fb3cfeba34225309cee0934c9d5d18e7decec5421f/FIFOStr-1.1.15.tar.gz" } ], "1.1.3": [ { "comment_text": "", "digests": { "md5": "2f3359235157d1d41a1adbea1a6336d1", "sha256": "983e58cf73cdfed1a6d25c08755497ad96d08873f0a1614cdf58f9e7ca2e5717" }, "downloads": -1, "filename": "FIFOStr-1.1.3.tar.gz", "has_sig": false, "md5_digest": "2f3359235157d1d41a1adbea1a6336d1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12884, "upload_time": "2017-03-22T23:51:53", "url": "https://files.pythonhosted.org/packages/2e/c4/72dbd3c77b649b95a71dbba065dd4abfdeece9e27ad6c8bab5e80967b376/FIFOStr-1.1.3.tar.gz" } ], "1.1.4": [ { "comment_text": "", "digests": { "md5": "dcfe48744baab47e505dbc2ce0babeb8", "sha256": "2926d4401b8a85fc62f45f993d70e6e64aaacc8949ce482457d18b24c01e3e30" }, "downloads": -1, "filename": "FIFOStr-1.1.4.tar.gz", "has_sig": false, "md5_digest": "dcfe48744baab47e505dbc2ce0babeb8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14808, "upload_time": "2017-03-26T18:53:15", "url": "https://files.pythonhosted.org/packages/0c/bb/f49a621032258eef307547e9ba44677ad5acb8342b9d5f4c1a76a7bbf4f6/FIFOStr-1.1.4.tar.gz" } ], "1.1.5": [ { "comment_text": "", "digests": { "md5": "0d6fa9d8c406270c16c54473581731a5", "sha256": "87c27b96c0af39844d395a615aa1fe7111c2515df66a1b5d1336c8a7b2a4674d" }, "downloads": -1, "filename": "FIFOStr-1.1.5.tar.gz", "has_sig": false, "md5_digest": "0d6fa9d8c406270c16c54473581731a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15352, "upload_time": "2017-03-26T19:08:00", "url": "https://files.pythonhosted.org/packages/bd/96/d8308d15ee7fd4398378ec54105a561b15033a82f40a3e9f9f866f9598ab/FIFOStr-1.1.5.tar.gz" } ], "1.1.7": [ { "comment_text": "", "digests": { "md5": "05eba2ff1dc9680f83a0da1c69843bb9", "sha256": "c67dc80363038b65a61d69d2df220f0fd3a674420bab3812f13a0476ef637eac" }, "downloads": -1, "filename": "FIFOStr-1.1.7.tar.gz", "has_sig": false, "md5_digest": "05eba2ff1dc9680f83a0da1c69843bb9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15482, "upload_time": "2017-03-29T01:05:13", "url": "https://files.pythonhosted.org/packages/19/37/c5639ac5683d01ef90913f81a3dcd9a32213389b1d4a471229498466c023/FIFOStr-1.1.7.tar.gz" } ], "1.1.8": [ { "comment_text": "", "digests": { "md5": "0de6182e25d8248f7808fead545a4722", "sha256": "731b74d2eee34e990d0143b09dafb986338b73e7d192f8795e69524f8256d200" }, "downloads": -1, "filename": "FIFOStr-1.1.8.tar.gz", "has_sig": false, "md5_digest": "0de6182e25d8248f7808fead545a4722", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15533, "upload_time": "2017-03-29T06:19:32", "url": "https://files.pythonhosted.org/packages/91/a7/e71283b166a88dac494d403b552c93ea63f330e5eefd6d75ebfc472786b3/FIFOStr-1.1.8.tar.gz" } ], "1.1.9": [ { "comment_text": "", "digests": { "md5": "7508770c1b9b2264d332e8aa745ebf6e", "sha256": "d95f7097f9f455885b915cf90dee4465b8c56bee92abe59beb34a03926f46eb5" }, "downloads": -1, "filename": "FIFOStr-1.1.9.tar.gz", "has_sig": false, "md5_digest": "7508770c1b9b2264d332e8aa745ebf6e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15632, "upload_time": "2017-03-30T21:36:34", "url": "https://files.pythonhosted.org/packages/df/7b/e259eb789f5de2137b4e9443cd9651c8057fa71676f2793c5b735421f554/FIFOStr-1.1.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "67d8c8d565697744c276117c67609644", "sha256": "9bf7d5183eff943cbc00e1429855219702797f046299f62e728ddc2fdf505fc4" }, "downloads": -1, "filename": "FIFOStr-1.1.15-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "67d8c8d565697744c276117c67609644", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12558, "upload_time": "2018-11-11T18:15:40", "url": "https://files.pythonhosted.org/packages/8f/89/46f6560f6ba2dd009c9948237e58be246200b652ddb4aec03b21cd55a1ab/FIFOStr-1.1.15-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6431119a2e38d875a1ff54e262587700", "sha256": "968a2d41a7f232e56c8d0378deff0c2ce3c94fe7125ad2271d7ef84ec8f156d2" }, "downloads": -1, "filename": "FIFOStr-1.1.15.tar.gz", "has_sig": false, "md5_digest": "6431119a2e38d875a1ff54e262587700", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17268, "upload_time": "2018-11-11T18:15:41", "url": "https://files.pythonhosted.org/packages/b1/47/05024f47425aa29199fb3cfeba34225309cee0934c9d5d18e7decec5421f/FIFOStr-1.1.15.tar.gz" } ] }