{ "info": { "author": "Tobias Litherland", "author_email": "tobiaslland@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# fileparse\n[![Build Status](https://travis-ci.org/tobiasli/fileparse.svg?branch=master)](https://travis-ci.org/tobiasli/fileparse)
\n[![Coverage Status](https://coveralls.io/repos/tobiasli/fileparse/badge.svg?branch=master&service=github)](https://coveralls.io/github/tobiasli/fileparse?branch=master)
\n[![PyPI version](https://badge.fury.io/py/fileparse-tobiasli.svg)](https://badge.fury.io/py/fileparse-tobiasli)
\n\n`fileparse` is a package for reading the contents of a file and populating a data model with the information found.\n\n## Install\n\n```\npip install fileparse-tobiasli\n```\n\n## Usage\n\nSay you have som text, and you have an idea of the structure of this text.\n\n```python\nnested_text = \"\"\"# This is a title.\nThis is contents.\nAnd some more.\n\n## This is a subtitle.\nwith subtitle contents.\n\n# This is another title.\nWith some contents.\n\"\"\"\n```\n\nYou can then define some simple classes defining this content structure and patterns that match each content type. Finally we define a model.Finder, which allows us to search for the content type in the text file.\n\n```python\nimport re\n\nfrom fileparse import parse, read\n\nclass Text(parse.Content):\n pass\ntext_match = re.compile('^(?P[^#].+)$')\ntext_finder = parse.ContentFinder(start_pattern=text_match,\n content_type=Text)\n\nclass SubTitle(parse.Content):\n pass\nsubtitle_match = re.compile('^## ?(?P[^#].+)$')\nsubtitle_finder = parse.ContentFinder(start_pattern=subtitle_match,\n content_type=SubTitle,\n sub_content_finders=[text_finder]\n )\n \nclass Title(parse.Content):\n pass\ntitle_match = re.compile('^# ?(?P[^#].+)$')\ntitle_finder = parse.ContentFinder(start_pattern=title_match,\n content_type=Title,\n sub_content_finders=[subtitle_finder, text_finder]) \n```\nNotice two things:\n* The regex patterns are named capture groups. The named capture groups are added as property to their content type. I.e. a `SubTitle` instance will receive a `SubTitle.subtitle` property.\n* `Text` content can be found within both a `Title` and a `SubTitle`. And that a `SubTitle` only can be found within a `Title`. \n\nFinally, we define the Parser.\n\n````python\n file_finder = parse.Parser(finders=[title_finder]) \n````\n\nThe file_finder is now ready to parse text content.\n\nFor this specific content, we need a text stream able to parse a string. We define it like this:\n\n````python\nstream = read.TextStream(reader=read.StringReader(string=nested_text))\n````\n\nWe can now parse the text with the rules defined in file_finder, and se what comes out of it. To get information out of a file-object, use the `file.get_contents_by_type(content_type)` method.\n\n````python\nfile = file_finder.parse_stream(stream)\n\nprint(file.get_contents_by_type(SubTitle)[0].subtitle == 'This is a subtitle.')\nprint(file.get_contents_by_type(SubTitle)[0].contents[0].text == 'with subtitle contents.')\n````\n\nHappy parsing.", "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/tobiasli/fileparse", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "fileparse-tobiasli", "package_url": "https://pypi.org/project/fileparse-tobiasli/", "platform": "", "project_url": "https://pypi.org/project/fileparse-tobiasli/", "project_urls": { "Homepage": "https://github.com/tobiasli/fileparse" }, "release_url": "https://pypi.org/project/fileparse-tobiasli/1.0.7/", "requires_dist": null, "requires_python": "", "summary": "Tools for parsing text content and creating data models for the content found.", "version": "1.0.7", "yanked": false, "yanked_reason": null }, "last_serial": 6054655, "releases": { "1.0.4": [ { "comment_text": "", "digests": { "md5": "23d5f85af1839a7480a40e73c966aaaa", "sha256": "1f4313b90f4045b44767bc7b4b8ddcd820830d1c11df3a8b13a01b5998f3a07e" }, "downloads": -1, "filename": "fileparse-tobiasli-1.0.4.tar.gz", "has_sig": false, "md5_digest": "23d5f85af1839a7480a40e73c966aaaa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4706, "upload_time": "2019-10-27T19:24:06", "upload_time_iso_8601": "2019-10-27T19:24:06.300744Z", "url": "https://files.pythonhosted.org/packages/3f/2c/22d979e07a0116346f217d07cbc42385b7774c23bb39144ff7841d46c8bd/fileparse-tobiasli-1.0.4.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.5": [ { "comment_text": "", "digests": { "md5": "090e0031f308be5ae067a7d54e860840", "sha256": "ac5f82940eff237654fb3871cefb701e1aeabc032ea311e6da771241d0f80d35" }, "downloads": -1, "filename": "fileparse-tobiasli-1.0.5.tar.gz", "has_sig": false, "md5_digest": "090e0031f308be5ae067a7d54e860840", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4657, "upload_time": "2019-10-27T19:50:27", "upload_time_iso_8601": "2019-10-27T19:50:27.198388Z", "url": "https://files.pythonhosted.org/packages/77/d3/8973e4ae6f828fde46db603d89800e1662d2e2424b7a93b628d7e053280c/fileparse-tobiasli-1.0.5.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.6": [ { "comment_text": "", "digests": { "md5": "a280e95b1dc617da1c5f09775f17a139", "sha256": "23b0e60036f47c8395a93751b917688cc2e33cf273112ed4a0cb13a615eaceaf" }, "downloads": -1, "filename": "fileparse-tobiasli-1.0.6.tar.gz", "has_sig": false, "md5_digest": "a280e95b1dc617da1c5f09775f17a139", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4691, "upload_time": "2019-10-27T19:59:30", "upload_time_iso_8601": "2019-10-27T19:59:30.251195Z", "url": "https://files.pythonhosted.org/packages/6d/c9/7838d3190e93a6cb2e9e7ba2d17506ff1d84aef5ab3d4e18d4c5baf03936/fileparse-tobiasli-1.0.6.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.7": [ { "comment_text": "", "digests": { "md5": "6f2d36c629c42a7dd523cc0195a21b7a", "sha256": "e24c54325209be2d7fb7db33d49ad5da2a09e5e0e9b428833274cbcf05b07ce1" }, "downloads": -1, "filename": "fileparse-tobiasli-1.0.7.tar.gz", "has_sig": false, "md5_digest": "6f2d36c629c42a7dd523cc0195a21b7a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4693, "upload_time": "2019-10-30T20:32:20", "upload_time_iso_8601": "2019-10-30T20:32:20.344817Z", "url": "https://files.pythonhosted.org/packages/13/c9/f4e2c05c6bd37f53853ce3251dd8d53cbdb61aac586e309dba5085c858ca/fileparse-tobiasli-1.0.7.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6f2d36c629c42a7dd523cc0195a21b7a", "sha256": "e24c54325209be2d7fb7db33d49ad5da2a09e5e0e9b428833274cbcf05b07ce1" }, "downloads": -1, "filename": "fileparse-tobiasli-1.0.7.tar.gz", "has_sig": false, "md5_digest": "6f2d36c629c42a7dd523cc0195a21b7a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4693, "upload_time": "2019-10-30T20:32:20", "upload_time_iso_8601": "2019-10-30T20:32:20.344817Z", "url": "https://files.pythonhosted.org/packages/13/c9/f4e2c05c6bd37f53853ce3251dd8d53cbdb61aac586e309dba5085c858ca/fileparse-tobiasli-1.0.7.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }