MCPcopy Create free account
hub / github.com/EasyIME/PIME / filter_whitespace

Function filter_whitespace

python/python3/tornado/template.py:227–249  ·  view source on GitHub ↗

Transform whitespace in ``text`` according to ``mode``. Available modes are: * ``all``: Return all whitespace unmodified. * ``single``: Collapse consecutive whitespace with a single whitespace character, preserving newlines. * ``oneline``: Collapse all runs of whitespace into

(mode: str, text: str)

Source from the content-addressed store, hash-verified

225
226
227def filter_whitespace(mode: str, text: str) -> str:
228 """Transform whitespace in ``text`` according to ``mode``.
229
230 Available modes are:
231
232 * ``all``: Return all whitespace unmodified.
233 * ``single``: Collapse consecutive whitespace with a single whitespace
234 character, preserving newlines.
235 * ``oneline``: Collapse all runs of whitespace into a single space
236 character, removing all newlines in the process.
237
238 .. versionadded:: 4.3
239 """
240 if mode == "all":
241 return text
242 elif mode == "single":
243 text = re.sub(r"([\t ]+)", " ", text)
244 text = re.sub(r"(\s*\n\s*)", "\n", text)
245 return text
246 elif mode == "oneline":
247 return re.sub(r"(\s+)", " ", text)
248 else:
249 raise Exception("invalid whitespace mode %s" % mode)
250
251
252class Template(object):

Callers 3

__init__Method · 0.85
generateMethod · 0.85
_parseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected