parentheses


Nameparentheses JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/xzripper/parentheses
SummaryLight parentheses parser in Python.
upload_time2024-01-27 16:35:48
maintainer
docs_urlNone
authorIvan Perzhinsky.
requires_python
licenseMIT
keywords utility string parentheses parsing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Parentheses. V1.0.0
===================

Light parentheses parser in Python.

Types (Aliases)
----------------

.. code-block:: python

    ParenthesesSymbol = str
    ParseFlag = int

Constants
---------

.. code-block:: python

    PARENTHESES_ALL: ParseFlag = 1
    PARENTHESES_OPEN: ParseFlag = 2
    PARENTHESES_CLOSE: ParseFlag = 3

    PARENTHESES_ROUND_OPEN: ParenthesesSymbol = '('
    PARENTHESES_ROUND_CLOSE: ParenthesesSymbol = ')'

    PARENTHESES_SQUARE_OPEN: ParenthesesSymbol = '['
    PARENTHESES_SQUARE_CLOSE: ParenthesesSymbol = ']'

    PARENTHESES_CURLY_OPEN: ParenthesesSymbol = '{'
    PARENTHESES_CURLY_CLOSE: ParenthesesSymbol = '}'

    PARENTHESES_DOUBLE_QUOTE: ParenthesesSymbol = '"'

    PARENTHESES_SINGLE_QUOTE: ParenthesesSymbol = '\''

    PARENTHESES_OPEN_SYMBOLS: list[ParenthesesSymbol] = [
        PARENTHESES_ROUND_OPEN,
        PARENTHESES_SQUARE_OPEN,
        PARENTHESES_CURLY_OPEN
    ]

    PARENTHESES_CLOSE_SYMBOLS: list[ParenthesesSymbol] = [
        PARENTHESES_ROUND_CLOSE,
        PARENTHESES_SQUARE_CLOSE,
        PARENTHESES_CURLY_CLOSE
    ]

    PARENTHESES_SYMBOLS = PARENTHESES_OPEN_SYMBOLS + PARENTHESES_CLOSE_SYMBOLS

    PARENTHESES_REGEX = r'\(.*?\)|\[.*?\]|\{.*?\}'

``PPString`` class
--------------------

``PPString`` is a class that represents a parsed parentheses string.

``valid_proc() -> bool``
~~~~~~~~~~~~~~~~~~~~~~~~

Get is parentheses in string valid. (Slower but gives more accurate result).

Examples:

- ``parse('(x)').valid_proc()`` => ``True``
- ``parse('(x').valid_proc()`` => ``False``

``valid() -> bool``
~~~~~~~~~~~~~~~~~~~

Get is parentheses in string valid. (Faster but gives less accurate result).

Examples:

- ``parse('(x)').valid()`` => ``True``
- ``parse('(x').valid()`` => ``False``

``valid_quotes(_escaping: bool=False) -> bool``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Get is quoted parentheses valid.

Examples:

- ``parse('"x"').valid_quotes()`` => ``True``
- ``parse('"x\""').valid_quotes(True)`` => ``True``
- ``parse('"x').valid_quotes()`` => ``False``
- ``parse('"x\""').valid_quotes()`` => ``False``

``count(flag: ParseFlag=PARENTHESES_ALL) -> int``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Count braces in string.

Examples:

- ``parse('(x)').count()`` => ``2``
- ``parse('(x)').count(PARENTHESES_OPEN)`` => ``1``
- ``parse('(x)').count(PARENTHESES_CLOSE)`` => ``1``

``autoclose() -> str``
~~~~~~~~~~~~~~~~~~~~~~

Autoclose brackets.

Examples:

- ``parse('{[(x').autoclose()`` => ``{[(x)]}``

``find(remove_braces: bool=False) -> list``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Get content in braces.

Examples:

- ``parse('(x) [y] {z}').find()`` => ``['(x)', '[y]', '{z}']``
- ``parse('(x) [y] {z}').find(True)`` => ``['x', 'y', 'z']``

``remove_braces() -> str``
~~~~~~~~~~~~~~~~~~~~~~~~~~

Remove braces in string.

Examples:

- ``parse('(x) [y] {z}').remove_braces()`` => ``'x y z'``

``remove(keep_braces: bool=False) -> str``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Remove everything in parentheses.

Examples:

- ``parse('(x) [y] {z}').remove()`` => ``'   '``
- ``parse('(x) [y] {z}').remove(True)`` => ``'() [] {}'``

``as_str() -> str``
~~~~~~~~~~~~~~~~~~~

Get string.

Examples:

- ``parse('x').as_str()`` => ``'x'``

Global functions
------------------

``parse(string: str) -> PPString``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Parse string.

Examples:

- ``parse('(x)')`` => ``PPString('x')``

``new_parentheses_symbols(open_symbol: ParenthesesSymbol, close_symbol: ParenthesesSymbol) -> None``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add new parentheses symbols.

Examples:

- ``new_parentheses_symbols('<', '>')`` => ``None``

``remove_parentheses_symbols(open_symbol: ParenthesesSymbol, close_symbol: ParenthesesSymbol) -> None``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Remove parentheses symbols.

Examples:

- ``remove_parentheses_symbols('<', '>')`` => ``None``

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/xzripper/parentheses",
    "name": "parentheses",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "utility,string,parentheses,parsing",
    "author": "Ivan Perzhinsky.",
    "author_email": "name1not1found.com@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/68/71/adc587578298d87b9d00d9fbdfe381cc6635c9ee68818c59cdca6edd4a48/parentheses-1.0.1.tar.gz",
    "platform": null,
    "description": "Parentheses. V1.0.0\r\n===================\r\n\r\nLight parentheses parser in Python.\r\n\r\nTypes (Aliases)\r\n----------------\r\n\r\n.. code-block:: python\r\n\r\n    ParenthesesSymbol = str\r\n    ParseFlag = int\r\n\r\nConstants\r\n---------\r\n\r\n.. code-block:: python\r\n\r\n    PARENTHESES_ALL: ParseFlag = 1\r\n    PARENTHESES_OPEN: ParseFlag = 2\r\n    PARENTHESES_CLOSE: ParseFlag = 3\r\n\r\n    PARENTHESES_ROUND_OPEN: ParenthesesSymbol = '('\r\n    PARENTHESES_ROUND_CLOSE: ParenthesesSymbol = ')'\r\n\r\n    PARENTHESES_SQUARE_OPEN: ParenthesesSymbol = '['\r\n    PARENTHESES_SQUARE_CLOSE: ParenthesesSymbol = ']'\r\n\r\n    PARENTHESES_CURLY_OPEN: ParenthesesSymbol = '{'\r\n    PARENTHESES_CURLY_CLOSE: ParenthesesSymbol = '}'\r\n\r\n    PARENTHESES_DOUBLE_QUOTE: ParenthesesSymbol = '\"'\r\n\r\n    PARENTHESES_SINGLE_QUOTE: ParenthesesSymbol = '\\''\r\n\r\n    PARENTHESES_OPEN_SYMBOLS: list[ParenthesesSymbol] = [\r\n        PARENTHESES_ROUND_OPEN,\r\n        PARENTHESES_SQUARE_OPEN,\r\n        PARENTHESES_CURLY_OPEN\r\n    ]\r\n\r\n    PARENTHESES_CLOSE_SYMBOLS: list[ParenthesesSymbol] = [\r\n        PARENTHESES_ROUND_CLOSE,\r\n        PARENTHESES_SQUARE_CLOSE,\r\n        PARENTHESES_CURLY_CLOSE\r\n    ]\r\n\r\n    PARENTHESES_SYMBOLS = PARENTHESES_OPEN_SYMBOLS + PARENTHESES_CLOSE_SYMBOLS\r\n\r\n    PARENTHESES_REGEX = r'\\(.*?\\)|\\[.*?\\]|\\{.*?\\}'\r\n\r\n``PPString`` class\r\n--------------------\r\n\r\n``PPString`` is a class that represents a parsed parentheses string.\r\n\r\n``valid_proc() -> bool``\r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nGet is parentheses in string valid. (Slower but gives more accurate result).\r\n\r\nExamples:\r\n\r\n- ``parse('(x)').valid_proc()`` => ``True``\r\n- ``parse('(x').valid_proc()`` => ``False``\r\n\r\n``valid() -> bool``\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\nGet is parentheses in string valid. (Faster but gives less accurate result).\r\n\r\nExamples:\r\n\r\n- ``parse('(x)').valid()`` => ``True``\r\n- ``parse('(x').valid()`` => ``False``\r\n\r\n``valid_quotes(_escaping: bool=False) -> bool``\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nGet is quoted parentheses valid.\r\n\r\nExamples:\r\n\r\n- ``parse('\"x\"').valid_quotes()`` => ``True``\r\n- ``parse('\"x\\\"\"').valid_quotes(True)`` => ``True``\r\n- ``parse('\"x').valid_quotes()`` => ``False``\r\n- ``parse('\"x\\\"\"').valid_quotes()`` => ``False``\r\n\r\n``count(flag: ParseFlag=PARENTHESES_ALL) -> int``\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nCount braces in string.\r\n\r\nExamples:\r\n\r\n- ``parse('(x)').count()`` => ``2``\r\n- ``parse('(x)').count(PARENTHESES_OPEN)`` => ``1``\r\n- ``parse('(x)').count(PARENTHESES_CLOSE)`` => ``1``\r\n\r\n``autoclose() -> str``\r\n~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nAutoclose brackets.\r\n\r\nExamples:\r\n\r\n- ``parse('{[(x').autoclose()`` => ``{[(x)]}``\r\n\r\n``find(remove_braces: bool=False) -> list``\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nGet content in braces.\r\n\r\nExamples:\r\n\r\n- ``parse('(x) [y] {z}').find()`` => ``['(x)', '[y]', '{z}']``\r\n- ``parse('(x) [y] {z}').find(True)`` => ``['x', 'y', 'z']``\r\n\r\n``remove_braces() -> str``\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nRemove braces in string.\r\n\r\nExamples:\r\n\r\n- ``parse('(x) [y] {z}').remove_braces()`` => ``'x y z'``\r\n\r\n``remove(keep_braces: bool=False) -> str``\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nRemove everything in parentheses.\r\n\r\nExamples:\r\n\r\n- ``parse('(x) [y] {z}').remove()`` => ``'   '``\r\n- ``parse('(x) [y] {z}').remove(True)`` => ``'() [] {}'``\r\n\r\n``as_str() -> str``\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\nGet string.\r\n\r\nExamples:\r\n\r\n- ``parse('x').as_str()`` => ``'x'``\r\n\r\nGlobal functions\r\n------------------\r\n\r\n``parse(string: str) -> PPString``\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nParse string.\r\n\r\nExamples:\r\n\r\n- ``parse('(x)')`` => ``PPString('x')``\r\n\r\n``new_parentheses_symbols(open_symbol: ParenthesesSymbol, close_symbol: ParenthesesSymbol) -> None``\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nAdd new parentheses symbols.\r\n\r\nExamples:\r\n\r\n- ``new_parentheses_symbols('<', '>')`` => ``None``\r\n\r\n``remove_parentheses_symbols(open_symbol: ParenthesesSymbol, close_symbol: ParenthesesSymbol) -> None``\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nRemove parentheses symbols.\r\n\r\nExamples:\r\n\r\n- ``remove_parentheses_symbols('<', '>')`` => ``None``\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Light parentheses parser in Python.",
    "version": "1.0.1",
    "project_urls": {
        "Download": "https://github.com/xzripper/parentheses/archive/refs/tags/v1.0.0-r.tar.gz",
        "Homepage": "https://github.com/xzripper/parentheses"
    },
    "split_keywords": [
        "utility",
        "string",
        "parentheses",
        "parsing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6871adc587578298d87b9d00d9fbdfe381cc6635c9ee68818c59cdca6edd4a48",
                "md5": "4c9fb07f74cdf38d3a9176bc22f61ded",
                "sha256": "2c418939db0c285a6a547c630fc2775add119d6f8bc284e15e480c7efaeca8ba"
            },
            "downloads": -1,
            "filename": "parentheses-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "4c9fb07f74cdf38d3a9176bc22f61ded",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4193,
            "upload_time": "2024-01-27T16:35:48",
            "upload_time_iso_8601": "2024-01-27T16:35:48.581762Z",
            "url": "https://files.pythonhosted.org/packages/68/71/adc587578298d87b9d00d9fbdfe381cc6635c9ee68818c59cdca6edd4a48/parentheses-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-27 16:35:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "xzripper",
    "github_project": "parentheses",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "parentheses"
}
        
Elapsed time: 0.31977s