/opt/imh-python/lib/python3.9/site-packages/traitlets/utils
NameSizeModeActions
__pycache__/-0755rm
bunch.py7840644editdlrm
decorators.py30840644editdlrm
descriptions.py55710644editdlrm
getargspec.py16430644editdlrm
importstring.py12100644editdlrm
nested_update.py11140644editdlrm
sentinel.py6420644editdlrm
text.py11390644editdlrm
warnings.py19640644editdlrm
__init__.py31440644editdlrm
Edit: /opt/imh-python/lib/python3.9/site-packages/traitlets/utils/text.py (1139B)
""" Utilities imported from ipython_genutils """ from __future__ import annotations import re import textwrap from textwrap import dedent from textwrap import indent as _indent from typing import List def indent(val: str) -> str: return _indent(val, " ") def wrap_paragraphs(text: str, ncols: int = 80) -> List[str]: """Wrap multiple paragraphs to fit a specified width. This is equivalent to textwrap.wrap, but with support for multiple paragraphs, as separated by empty lines. Returns ------- list of complete paragraphs, wrapped to fill `ncols` columns. """ paragraph_re = re.compile(r"\n(\s*\n)+", re.MULTILINE) text = dedent(text).strip() paragraphs = paragraph_re.split(text)[::2] # every other entry is space out_ps = [] indent_re = re.compile(r"\n\s+", re.MULTILINE) for p in paragraphs: # presume indentation that survives dedent is meaningful formatting, # so don't fill unless text is flush. if indent_re.search(p) is None: # wrap paragraph p = textwrap.fill(p, ncols) out_ps.append(p) return out_ps