textwrapre


Nametextwrapre JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/textwrapre
SummarySplits large texts into smaller ones that can't exceed a certain limit, but need to be split where a certain regular expression matches
upload_time2023-04-03 03:02:05
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords textwrap text wrap regex
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# textwrapre



A Python package to split text into smaller blocks based on regular expressions. 

It's useful to split large texts into smaller ones that can't exceed a certain limit, 

but need to be split where a certain regular expression matches. 



### pip install textwrapre



## Usage



```python

from textwrapre import wrapre

import regex



text = r"""

Python was created in the early 1990s by Guido van Rossum at Stichting Mathematisch 

Centrum (CWI, see https://www.cwi.nl/) in the Netherlands as a successor of a 

language called ABC. Guido remains Python’s principal author, although it includes

many contributions from others.



In 1995, Guido continued his work on Python at the Corporation for 

National Research Initiatives 

(CNRI, see https://www.cnri.reston.va.us/) in Reston, 

Virginia where he released several versions of the software.



""".strip()



# Split the text using the default regex separator

splitted = wrapre(text, blocksize=150, raisewhenlonger=True, removenewlines_from_result=True)



for s in splitted:

    print(len(s), s)



# Split the text using a custom regex separator

splitted = wrapre(text, blocksize=50, regexsep=r"[\r\n\s]+", raisewhenlonger=True, removenewlines_from_result=False, flags=regex.I)



for s in splitted:

    print(len(s), s)



# Split the text and raise an exception when the blocks are bigger than the limit

splitted = wrapre(text, blocksize=20, regexsep=r"[\r\n\s]+", raisewhenlonger=True, flags=regex.I)







85 Python was created in the early 1990s by Guido van Rossum at Stichting Mathematisch  

79 Centrum (CWI, see https://www.cwi.nl/) in the Netherlands as a successor of a  

115 language called ABC. Guido remains Python’s principal author, although it includes many contributions from others. 

99 In 1995, Guido continued his work on Python at the Corporation for  National Research Initiatives  

115 (CNRI, see https://www.cnri.reston.va.us/) in Reston,  Virginia where he released several versions of the software.

---------------------

47 Python was created in the early 1990s by Guido 

46 van Rossum at Stichting Mathematisch 

Centrum 

38 (CWI, see https://www.cwi.nl/) in the 

49 Netherlands as a successor of a 

language called 

46 ABC. Guido remains Python’s principal author, 

45 although it includes

many contributions from 

46 others.

In 1995, Guido continued his work on 

49 Python at the Corporation for 

National Research 

24 Initiatives 

(CNRI, see 

44 https://www.cnri.reston.va.us/) in Reston, 

47 Virginia where he released several versions of 

13 the software.

---------------------

Traceback (most recent call last):

  File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.3\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode

    coro = func()

  File "<input>", line 41, in <module>

  File "C:\ProgramData\anaconda3\envs\adda\textwrapre.py", line 73, in wrapre

    raise ValueError(

ValueError: Some blocks are bigger than the limit! Try again with another separator or a bigger limit!

```



## Parameters



```python

def wrapre(

    text: Union[str, bytes], 

    blocksize: int, 

    regexsep: str = r"[\r\n]", 

    raisewhenlonger: bool = True, 

    removenewlines_from_result: bool = False, 

    *args, 

    **kwargs

) -> List[Union[str, bytes]]:

    """

    Split a text into blocks of a given size using a regex expression.



    :param text: the text to be splitted

    :param blocksize: the maximum size of each block

    :param regexsep: the regex expression used as separator (default: r"[\r\n]")

    :param raisewhenlonger: whether or not to raise an exception when a block is bigger than the limit (default: True)

    :param removenewlines_from_result: whether or not to remove new lines from the result (default: False)

    :param *args: additional arguments passed to the regex.compile() function

    :param **kwargs: additional keyword arguments passed to the regex.compile() function

    :return: a list of blocks

    """

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/textwrapre",
    "name": "textwrapre",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "textwrap,text,wrap,regex",
    "author": "Johannes Fischer",
    "author_email": "<aulasparticularesdealemaosp@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/20/9f/b139d5de9374218fa8345f1d732a5e30b8f93239ae8d19d2f1c775640d40/textwrapre-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# textwrapre\r\n\r\n\r\n\r\nA Python package to split text into smaller blocks based on regular expressions. \r\n\r\nIt's useful to split large texts into smaller ones that can't exceed a certain limit, \r\n\r\nbut need to be split where a certain regular expression matches. \r\n\r\n\r\n\r\n### pip install textwrapre\r\n\r\n\r\n\r\n## Usage\r\n\r\n\r\n\r\n```python\r\n\r\nfrom textwrapre import wrapre\r\n\r\nimport regex\r\n\r\n\r\n\r\ntext = r\"\"\"\r\n\r\nPython was created in the early 1990s by Guido van Rossum at Stichting Mathematisch \r\n\r\nCentrum (CWI, see https://www.cwi.nl/) in the Netherlands as a successor of a \r\n\r\nlanguage called ABC. Guido remains Python\u2019s principal author, although it includes\r\n\r\nmany contributions from others.\r\n\r\n\r\n\r\nIn 1995, Guido continued his work on Python at the Corporation for \r\n\r\nNational Research Initiatives \r\n\r\n(CNRI, see https://www.cnri.reston.va.us/) in Reston, \r\n\r\nVirginia where he released several versions of the software.\r\n\r\n\r\n\r\n\"\"\".strip()\r\n\r\n\r\n\r\n# Split the text using the default regex separator\r\n\r\nsplitted = wrapre(text, blocksize=150, raisewhenlonger=True, removenewlines_from_result=True)\r\n\r\n\r\n\r\nfor s in splitted:\r\n\r\n    print(len(s), s)\r\n\r\n\r\n\r\n# Split the text using a custom regex separator\r\n\r\nsplitted = wrapre(text, blocksize=50, regexsep=r\"[\\r\\n\\s]+\", raisewhenlonger=True, removenewlines_from_result=False, flags=regex.I)\r\n\r\n\r\n\r\nfor s in splitted:\r\n\r\n    print(len(s), s)\r\n\r\n\r\n\r\n# Split the text and raise an exception when the blocks are bigger than the limit\r\n\r\nsplitted = wrapre(text, blocksize=20, regexsep=r\"[\\r\\n\\s]+\", raisewhenlonger=True, flags=regex.I)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n85 Python was created in the early 1990s by Guido van Rossum at Stichting Mathematisch  \r\n\r\n79 Centrum (CWI, see https://www.cwi.nl/) in the Netherlands as a successor of a  \r\n\r\n115 language called ABC. Guido remains Python\u2019s principal author, although it includes many contributions from others. \r\n\r\n99 In 1995, Guido continued his work on Python at the Corporation for  National Research Initiatives  \r\n\r\n115 (CNRI, see https://www.cnri.reston.va.us/) in Reston,  Virginia where he released several versions of the software.\r\n\r\n---------------------\r\n\r\n47 Python was created in the early 1990s by Guido \r\n\r\n46 van Rossum at Stichting Mathematisch \r\n\r\nCentrum \r\n\r\n38 (CWI, see https://www.cwi.nl/) in the \r\n\r\n49 Netherlands as a successor of a \r\n\r\nlanguage called \r\n\r\n46 ABC. Guido remains Python\u2019s principal author, \r\n\r\n45 although it includes\r\n\r\nmany contributions from \r\n\r\n46 others.\r\n\r\nIn 1995, Guido continued his work on \r\n\r\n49 Python at the Corporation for \r\n\r\nNational Research \r\n\r\n24 Initiatives \r\n\r\n(CNRI, see \r\n\r\n44 https://www.cnri.reston.va.us/) in Reston, \r\n\r\n47 Virginia where he released several versions of \r\n\r\n13 the software.\r\n\r\n---------------------\r\n\r\nTraceback (most recent call last):\r\n\r\n  File \"C:\\Program Files\\JetBrains\\PyCharm Community Edition 2022.3.3\\plugins\\python-ce\\helpers\\pydev\\pydevconsole.py\", line 364, in runcode\r\n\r\n    coro = func()\r\n\r\n  File \"<input>\", line 41, in <module>\r\n\r\n  File \"C:\\ProgramData\\anaconda3\\envs\\adda\\textwrapre.py\", line 73, in wrapre\r\n\r\n    raise ValueError(\r\n\r\nValueError: Some blocks are bigger than the limit! Try again with another separator or a bigger limit!\r\n\r\n```\r\n\r\n\r\n\r\n## Parameters\r\n\r\n\r\n\r\n```python\r\n\r\ndef wrapre(\r\n\r\n    text: Union[str, bytes], \r\n\r\n    blocksize: int, \r\n\r\n    regexsep: str = r\"[\\r\\n]\", \r\n\r\n    raisewhenlonger: bool = True, \r\n\r\n    removenewlines_from_result: bool = False, \r\n\r\n    *args, \r\n\r\n    **kwargs\r\n\r\n) -> List[Union[str, bytes]]:\r\n\r\n    \"\"\"\r\n\r\n    Split a text into blocks of a given size using a regex expression.\r\n\r\n\r\n\r\n    :param text: the text to be splitted\r\n\r\n    :param blocksize: the maximum size of each block\r\n\r\n    :param regexsep: the regex expression used as separator (default: r\"[\\r\\n]\")\r\n\r\n    :param raisewhenlonger: whether or not to raise an exception when a block is bigger than the limit (default: True)\r\n\r\n    :param removenewlines_from_result: whether or not to remove new lines from the result (default: False)\r\n\r\n    :param *args: additional arguments passed to the regex.compile() function\r\n\r\n    :param **kwargs: additional keyword arguments passed to the regex.compile() function\r\n\r\n    :return: a list of blocks\r\n\r\n    \"\"\"\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Splits large texts into smaller ones that can't exceed a certain limit, but need to be split where a certain regular expression matches",
    "version": "0.10",
    "split_keywords": [
        "textwrap",
        "text",
        "wrap",
        "regex"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6bf035eed9a7174c59d8d94630b2d30a96bf1ed019e2e3847eb23b5dcd978b13",
                "md5": "702f7c3a3ae1f4f5332ce81650288681",
                "sha256": "852e5af25d8fd1ead28f396e4c62cf848afa62a17ca24f60c1694ec81db08e18"
            },
            "downloads": -1,
            "filename": "textwrapre-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "702f7c3a3ae1f4f5332ce81650288681",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11609,
            "upload_time": "2023-04-03T03:02:01",
            "upload_time_iso_8601": "2023-04-03T03:02:01.759795Z",
            "url": "https://files.pythonhosted.org/packages/6b/f0/35eed9a7174c59d8d94630b2d30a96bf1ed019e2e3847eb23b5dcd978b13/textwrapre-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "209fb139d5de9374218fa8345f1d732a5e30b8f93239ae8d19d2f1c775640d40",
                "md5": "cb435cabc64f4a6f4acd83a15f500da2",
                "sha256": "cbbdf1f89a37c333c2f087430f3cfe18880ffaa5935ec703f59dcb3168c037b9"
            },
            "downloads": -1,
            "filename": "textwrapre-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "cb435cabc64f4a6f4acd83a15f500da2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9852,
            "upload_time": "2023-04-03T03:02:05",
            "upload_time_iso_8601": "2023-04-03T03:02:05.534389Z",
            "url": "https://files.pythonhosted.org/packages/20/9f/b139d5de9374218fa8345f1d732a5e30b8f93239ae8d19d2f1c775640d40/textwrapre-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-03 03:02:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "hansalemaos",
    "github_project": "textwrapre",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "textwrapre"
}
        
Elapsed time: 0.14367s