extendparser


Nameextendparser JSON
Version 0.3.1 PyPI version JSON
download
home_pagehttps://github.com/ondratu/extendparser
SummaryExtendParser extend stanrad ConfigParser for some functionality.
upload_time2021-03-05 07:55:34
maintainer
docs_urlNone
authorOndřej Tůma
requires_python
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            extendparser
============

Extend parser is set of ``ConfigParser`` extensions. ``Get`` and ``Include``
extensions are added to one class ``ExtendParser``. For more details see source
code, or use help.


:copyright: 2018, see AUTHORS for more details
:license: BSD, see LICENSE for more details

Library
-------

ExtendParser
~~~~~~~~~~~~

.. code:: python

    >>> from extendparser import ExtendParser
    >>> cp = ExtendParser()

Include
~~~~~~~
Include class can append content from other configuration files. Let's have
these configuration files:

.. code:: ini

  # test.ini
  [main]
  string = value
  .include numbers.ini

.. code:: ini

  # numbers.ini
  integer = 42
  .include const.ini

.. code:: ini

  # const.ini
  pi = 3.14


Here is the string buffer which ConfiguratinParser will read:

.. code:: ini

  # test.ini
  [main]
  string = value
  # numbers.ini
  integer = 42
  # const.ini
  pi = 3.14

Get
~~~
Get class has two smart methods ``get_option`` and ``get_section`` to get
value(s) in any type you want.

.. code:: python

    >>> from extendparser.get import Get
    >>> cp = Get()
    >>> print(cp.get_option("test", "number", target=int, fallback=1))
    1
    >>> print(cp.get_option("test", "list", target=list, fallback=["a"],
    ...                      delimiter=','))
    ['a']
    >>> cp.add_section("test")
    >>> cp.set("test", "tuple", "a:b:c")
    >>> print(cp.get_option("test", "tuple", target=tuple, delimiter=':'))
    ('a', 'b', 'c')
    >>> print(cp.get_section("test", (("tuple", tuple, tuple(), ':'),
    ...                               ("string", str, "value"))))
    {'tuple': ('a', 'b', 'c'), 'string': 'value'}

Environment
~~~~~~~~~~~
Environ module has two classes, which extend ``ConfigParser`` to read
environment variables. There is ``EnvironFirst`` class, which read environment
variables first, and then use original get method.


.. code:: python

    >>> from os import environ
    >>> from configparser import ConfigParser
    >>> from extendparser.environ import EnvironFirst
    >>> cp = EnvironFirst()
    >>> cp.add_section("test")
    >>> cp.getint("test", "number", fallback=1)
    1
    >>> cp.set("test", "number", "7")
    >>> cp.getint("test", "number")
    7
    >>> environ["TEST_NUMBER"] = "42"
    >>> cp.getint("test", "number")
    42

Next ``EnvironLast`` class use environment variable as fallback for original get
method.

.. code:: python

    >>> from os import environ
    >>> from configparser import ConfigParser
    >>> from extendparser.environ import EnvironLast
    >>> cp = EnvironLast()
    >>> cp.add_section("test")
    >>> cp.getfloat("test", "float", fallback=1.0)
    1.0
    >>> environ["TEST_FLOAT"] = "42"
    >>> cp.getfloat("test", "float", fallback=1)
    42.0
    >>> cp.set("test", "float", "3.14")
    >>> cp.getfloat("test", "float")
    3.14

Installation
------------

.. code:: sh

  ~$ pip install extendparser


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ondratu/extendparser",
    "name": "extendparser",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Ond\u0159ej T\u016fma",
    "author_email": "mcbig@zeropage.cz",
    "download_url": "https://files.pythonhosted.org/packages/2f/c4/4fa9b3d5d7bdee4b8eac324832d783dfdcd813b72bb86a5c8b5e117afd31/extendparser-0.3.1.tar.gz",
    "platform": "",
    "description": "extendparser\n============\n\nExtend parser is set of ``ConfigParser`` extensions. ``Get`` and ``Include``\nextensions are added to one class ``ExtendParser``. For more details see source\ncode, or use help.\n\n\n:copyright: 2018, see AUTHORS for more details\n:license: BSD, see LICENSE for more details\n\nLibrary\n-------\n\nExtendParser\n~~~~~~~~~~~~\n\n.. code:: python\n\n    >>> from extendparser import ExtendParser\n    >>> cp = ExtendParser()\n\nInclude\n~~~~~~~\nInclude class can append content from other configuration files. Let's have\nthese configuration files:\n\n.. code:: ini\n\n  # test.ini\n  [main]\n  string = value\n  .include numbers.ini\n\n.. code:: ini\n\n  # numbers.ini\n  integer = 42\n  .include const.ini\n\n.. code:: ini\n\n  # const.ini\n  pi = 3.14\n\n\nHere is the string buffer which ConfiguratinParser will read:\n\n.. code:: ini\n\n  # test.ini\n  [main]\n  string = value\n  # numbers.ini\n  integer = 42\n  # const.ini\n  pi = 3.14\n\nGet\n~~~\nGet class has two smart methods ``get_option`` and ``get_section`` to get\nvalue(s) in any type you want.\n\n.. code:: python\n\n    >>> from extendparser.get import Get\n    >>> cp = Get()\n    >>> print(cp.get_option(\"test\", \"number\", target=int, fallback=1))\n    1\n    >>> print(cp.get_option(\"test\", \"list\", target=list, fallback=[\"a\"],\n    ...                      delimiter=','))\n    ['a']\n    >>> cp.add_section(\"test\")\n    >>> cp.set(\"test\", \"tuple\", \"a:b:c\")\n    >>> print(cp.get_option(\"test\", \"tuple\", target=tuple, delimiter=':'))\n    ('a', 'b', 'c')\n    >>> print(cp.get_section(\"test\", ((\"tuple\", tuple, tuple(), ':'),\n    ...                               (\"string\", str, \"value\"))))\n    {'tuple': ('a', 'b', 'c'), 'string': 'value'}\n\nEnvironment\n~~~~~~~~~~~\nEnviron module has two classes, which extend ``ConfigParser`` to read\nenvironment variables. There is ``EnvironFirst`` class, which read environment\nvariables first, and then use original get method.\n\n\n.. code:: python\n\n    >>> from os import environ\n    >>> from configparser import ConfigParser\n    >>> from extendparser.environ import EnvironFirst\n    >>> cp = EnvironFirst()\n    >>> cp.add_section(\"test\")\n    >>> cp.getint(\"test\", \"number\", fallback=1)\n    1\n    >>> cp.set(\"test\", \"number\", \"7\")\n    >>> cp.getint(\"test\", \"number\")\n    7\n    >>> environ[\"TEST_NUMBER\"] = \"42\"\n    >>> cp.getint(\"test\", \"number\")\n    42\n\nNext ``EnvironLast`` class use environment variable as fallback for original get\nmethod.\n\n.. code:: python\n\n    >>> from os import environ\n    >>> from configparser import ConfigParser\n    >>> from extendparser.environ import EnvironLast\n    >>> cp = EnvironLast()\n    >>> cp.add_section(\"test\")\n    >>> cp.getfloat(\"test\", \"float\", fallback=1.0)\n    1.0\n    >>> environ[\"TEST_FLOAT\"] = \"42\"\n    >>> cp.getfloat(\"test\", \"float\", fallback=1)\n    42.0\n    >>> cp.set(\"test\", \"float\", \"3.14\")\n    >>> cp.getfloat(\"test\", \"float\")\n    3.14\n\nInstallation\n------------\n\n.. code:: sh\n\n  ~$ pip install extendparser\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "ExtendParser extend stanrad ConfigParser for some functionality.",
    "version": "0.3.1",
    "project_urls": {
        "Homepage": "https://github.com/ondratu/extendparser"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c616070ec7b689e84b2c6d224733d207eef8e434340b2a9a82c8244ef93516cd",
                "md5": "36d59234390a052fc68f8d88ce58acfd",
                "sha256": "f22dd3e19cabf4cb0108ab194d1251498167cd53e369ec6bb7e6311eb3765780"
            },
            "downloads": -1,
            "filename": "extendparser-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "36d59234390a052fc68f8d88ce58acfd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11396,
            "upload_time": "2021-03-05T07:55:33",
            "upload_time_iso_8601": "2021-03-05T07:55:33.613171Z",
            "url": "https://files.pythonhosted.org/packages/c6/16/070ec7b689e84b2c6d224733d207eef8e434340b2a9a82c8244ef93516cd/extendparser-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2fc44fa9b3d5d7bdee4b8eac324832d783dfdcd813b72bb86a5c8b5e117afd31",
                "md5": "b2902fc595e7017ff3cc760f48f67626",
                "sha256": "91bd3117a48806aead792200aff889ee76b35fe305c3398021b3362ddc0ec2ac"
            },
            "downloads": -1,
            "filename": "extendparser-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b2902fc595e7017ff3cc760f48f67626",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8706,
            "upload_time": "2021-03-05T07:55:34",
            "upload_time_iso_8601": "2021-03-05T07:55:34.722778Z",
            "url": "https://files.pythonhosted.org/packages/2f/c4/4fa9b3d5d7bdee4b8eac324832d783dfdcd813b72bb86a5c8b5e117afd31/extendparser-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-03-05 07:55:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ondratu",
    "github_project": "extendparser",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "extendparser"
}
        
Elapsed time: 0.08409s