mirror of
https://github.com/aykhans/AzSuicideDataVisualization.git
synced 2025-07-02 14:27:31 +00:00
first commit
This commit is contained in:
41
.venv/Lib/site-packages/nbconvert/utils/text.py
Normal file
41
.venv/Lib/site-packages/nbconvert/utils/text.py
Normal file
@ -0,0 +1,41 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
def indent(instr, nspaces=4, ntabs=0, flatten=False):
|
||||
"""Indent a string a given number of spaces or tabstops.
|
||||
|
||||
indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
instr : basestring
|
||||
The string to be indented.
|
||||
nspaces : int (default: 4)
|
||||
The number of spaces to be indented.
|
||||
ntabs : int (default: 0)
|
||||
The number of tabs to be indented.
|
||||
flatten : bool (default: False)
|
||||
Whether to scrub existing indentation. If True, all lines will be
|
||||
aligned to the same indentation. If False, existing indentation will
|
||||
be strictly increased.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
||||
str|unicode : string indented by ntabs and nspaces.
|
||||
|
||||
"""
|
||||
if instr is None:
|
||||
return
|
||||
ind = "\t" * ntabs + " " * nspaces
|
||||
if flatten:
|
||||
pat = re.compile(r"^\s*", re.MULTILINE)
|
||||
else:
|
||||
pat = re.compile(r"^", re.MULTILINE)
|
||||
outstr = re.sub(pat, ind, instr)
|
||||
if outstr.endswith(os.linesep + ind):
|
||||
return outstr[: -len(ind)]
|
||||
else:
|
||||
return outstr
|
Reference in New Issue
Block a user