{ "info": { "author": "NVRAM", "author_email": "nvram@users.sourceforge.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Text Processing :: Filters", "Topic :: Utilities" ], "description": "pynumparser 1.4.1\n=================\n\nSummary\n-------\n\nThis library provides two classes for parsing simple integer or floating piont numbers and numeric\nsequences, optionally enforcing value limits. These can be used as explicit objects or as the\n*type* parameter of an argument within an *argparse.ArgumentParser*.\n\n- **NumberSequence** parses an input string and yields a sequence of numbers, optionally ensuring\n they are within the given limits. It will also convert a sequence of numbers into the string form\n *[as of version 1.2]*.\n- **Number** parses an input string and returns a single number; ensuring they are within the given\n limits.\n- Both classes take a **numtype** parameter (*int* or *float*), and a **limits** parameter which\n can be *None* or a 2-tuple; the 2-tuple imposes limits on the parsed values.\n\n.. contents:: **Index**\n :depth: 2\n :local:\n\n----------\n\nInstallation\n------------\nInstall the package using **pip**, eg:\n\n sudo pip install pynumparser\n\nOr for a specific version:\n\n sudo python3 -m pip install pynumparser\n\n*NumberSequence* Syntax\n-----------------------\n\nAllowed inputs are comprised of one (1) or more subsequences separated by a comma (\",\").\nSubsequences can be simple numbers or number ranges with or without a **stride** value.\n\n- Simple number values yield a single value.\n\n- A range is expressed as two (2) number values separated by either a dash/hyphen (\"-\") or a plus\n sign (\"+\") *[as of version 1.3]*, optionally followed by a slash (\"/\") and a **stride** value.\n\n - A range will usually yield multiple values *including both bounds*. This is in contrast to\n the builtin Python *range()* behaviour.\n\n - A **lower bound** and **upper bound** may be separated by a single dash/hyphen (\"-\"). Note\n that it is legal for the upper bound be negative (eg: \"-5--3\").\n\n - A **lower bound** and **range size** may be separated by a single plus sign (\"+\"). Note that\n it is legal for the range size be start with a plus sign (eg: \"8++5\" is equivalent to \"8+5\").\n *[As of version 1.3]* \n\n - Only monotonically increasing ranges are allowed:\n\n - An **upper range** value must not be less than the lower range value (eg: \"5-4\" is illegal).\n\n - The **stride** must be positive (eg: \"5-8/0\" and \"8-1/-2\" are illegal).\n\n - A **range size** must not be negative (eg: \"8+-4\" is illegal) *[as of version 1.3]*.\n\n- By default numbers are of *int* type. But if *numtype=float* is passed to the constructor, the\n inputs are parsed as floating point numbers *with a dot/peroid for a decimial mark*. In other\n words, the representation of *5/4* must be \"*1.2*\" and not \"*1,2*\" since the comma is used as the\n subsequence separator.\n\n- If the difference between the limits is not an even mulitiple of the *stride* value, then the\n second range will *not* be included in the result.\n\n- The parser has a *contains* method, which can be used to check if a number is in the range.\n *[as of version 1.1]*.\n\n- The *Number* class has a *contains* method, which can be check if a number is in the range.\n *[as of version 1.4.1]*.\n\n- **NumberSequence** has a classmethod *encode* that will convert a sequence into a simplified text\n representation. *[as of version 1.2]*.\n\n .. code:: python\n\n >>> import pynumparser\n >>> pynumparser.NumberSequence.encode([1, 2, 3, 7, 13, 19, 25])\n '1-3,7-25/6'\n >>> pynumparser.NumberSequence.encode([1.00, 1.25, 1.5, 1.75, 2, 2.25])\n '1.0-2.25/0.25'\n >>> pynumparser.NumberSequence.encode(range(10, 100, 5))\n '10-95/5'\n\n\n**Exceptions**\n^^^^^^^^^^^^^^\n\nThese apply to both the **NumberSequence** and **Number** classes:\n\n- If the optional constructor **limits** parameter is provided, then a *ValueError* will be raised\n in the constructor if any of the following are violated.\n\n - The **limits** parameter must be either *None* or else a tuple with two (2) values, a *lower\n limit* then an *upper limit*.\n\n - Both of the *limit* values may be either *None* or a valid value of the **numtype**.\n\n - If *lower limit* and *upper limit* are numbers, then the *lower limit* must be less than the\n *upper limit*.\n\n- If **limits** parameter was provided to the constructor, then a *ValueError* will be raised\n during parsing if any of the following are violated.\n\n - If the *lower limit* is a number, then parsed values must not be less than the *lower limit*.\n\n - If the *upper limit* is a number, then parsed values must not be greater than the *upper limit*.\n\n- If any input cannot be parsed as a valid number of given the **numtype** a *ValueError* is raised.\n\n- If any floating point number equates to positive or negative infinity (eg: *\"1e9999\"*) a\n *ValueError* is raised.\n\nThese apply only to the **NumberSequence** class, during parsing:\n\n- If the *upper bound* is less than the *lower bound* (eg: \"*8-5*\") or *[as of version 1.3]* if the\n *range size* is negative (eg: \"*8+-3*\"), then a *ValueError* is raised.\n\n- If the **stride** value is zero or negative, *ValueError* is raised, even if the upper and lower\n limit values are equal (eg: \"*8-8/0*\").\n\n\nIf used within an **argparse.ArgumentParser**, invalid input will raise a *ValueError* and result in\nan error message indicating the specific problem, such as:\n\n.. code:: bash\n\n $ demo.py --fnum 1e20\n usage: demo.py [-h] [-i ISEQ] [-f FSEQ] [-I INUM] [-F FNUM]\n demo.py: error: argument -F/--fnum: invalid Float (from -100 to 1000), ERROR: \"Too High\" value: '1e20'\n\n $ demo.py -i 200-100\n usage: demo.py [-h] [-i ISEQ] [-f FSEQ] [-I INUM] [-F FNUM]\n demo.py: error: argument -i/--iseq: invalid IntSequence (at least -1000), ERROR: \"UPPER`_.\n\n - In the first example (**\"0-13/1.3\"**), the value of **13** is not included since the previous\n value was larger than **11.7**.\n - In the second example (**\"1.2-2.0/0.2\"**) the final value is slightly less than\n **2.0** due to representation error.\n\n .. code:: python\n\n >>> import pynumparser\n >>> parser = pynumparser.NumberSequence(float)\n >>> parser.parse(\"0-13/1.3\")\n (0.0, 1.3, 2.6, 3.9000000000000004, 5.2, 6.5, 7.8, 9.1, 10.4, 11.700000000000001)\n >>> parser.parse(\"1.2-2.0/0.2\")\n (1.2, 1.4, 1.5999999999999999, 1.7999999999999998, 1.9999999999999998)", "description_content_type": "", "docs_url": null, "download_url": "https://gitlab.com/n2vram/pynumparser/archive/1.4.1.zip", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/n2vram/pynumparser", "keywords": "argparse,numparser,parser,numbers,parsing,ArgumentParser,command-line,sequences", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pynumparser", "package_url": "https://pypi.org/project/pynumparser/", "platform": "any", "project_url": "https://pypi.org/project/pynumparser/", "project_urls": { "Download": "https://gitlab.com/n2vram/pynumparser/archive/1.4.1.zip", "Homepage": "https://gitlab.com/n2vram/pynumparser" }, "release_url": "https://pypi.org/project/pynumparser/1.4.1/", "requires_dist": null, "requires_python": "", "summary": "A library to parse arguments of numbers and number sequences, usable directly or with argparse. Allows concise representation of contiguous or non-contiguous sequences. Example: 1,5-10,40-50/5,200+100/25", "version": "1.4.1" }, "last_serial": 4209089, "releases": { "1.4": [ { "comment_text": "", "digests": { "md5": "fa6b6d2bae2eb95cdc71caeca2336a70", "sha256": "0f0c2772f10a1f8a62caafd11817d887547f8c09db73c68b921695bee51ac464" }, "downloads": -1, "filename": "pynumparser-1.4.tar.gz", "has_sig": false, "md5_digest": "fa6b6d2bae2eb95cdc71caeca2336a70", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9424, "upload_time": "2018-03-29T22:32:30", "url": "https://files.pythonhosted.org/packages/3d/6b/41c50baf4bd12a4dc69da7563e4fdd6524aac116f696c52a05a0ae125562/pynumparser-1.4.tar.gz" } ], "1.4.1": [ { "comment_text": "", "digests": { "md5": "4c304e382fb9b2d65612d55048a1acf5", "sha256": "8fbd5280490ef89fb46e817d63067f6e4542a66b0051c0eaa70afb4961f0aa67" }, "downloads": -1, "filename": "pynumparser-1.4.1.tar.gz", "has_sig": false, "md5_digest": "4c304e382fb9b2d65612d55048a1acf5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9520, "upload_time": "2018-08-26T19:45:26", "url": "https://files.pythonhosted.org/packages/8e/04/cf25994a95759a6763ae76e0f0d53d602afaf460acae232b472f1f80a952/pynumparser-1.4.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4c304e382fb9b2d65612d55048a1acf5", "sha256": "8fbd5280490ef89fb46e817d63067f6e4542a66b0051c0eaa70afb4961f0aa67" }, "downloads": -1, "filename": "pynumparser-1.4.1.tar.gz", "has_sig": false, "md5_digest": "4c304e382fb9b2d65612d55048a1acf5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9520, "upload_time": "2018-08-26T19:45:26", "url": "https://files.pythonhosted.org/packages/8e/04/cf25994a95759a6763ae76e0f0d53d602afaf460acae232b472f1f80a952/pynumparser-1.4.1.tar.gz" } ] }