MCPcopy Index your code
hub / github.com/ipython/ipython / strip_email_quotes

Function strip_email_quotes

IPython/utils/text.py:379–426  ·  view source on GitHub ↗

Strip leading email quotation characters ('>'). Removes any combination of leading '>' interspersed with whitespace that appears *identically* in all lines of the input text. Parameters ---------- text : str Examples -------- Simple uses:: In [2]: strip_e

(text: str)

Source from the content-addressed store, hash-verified

377
378
379def strip_email_quotes(text: str) -> str:
380 """Strip leading email quotation characters ('>').
381
382 Removes any combination of leading '>' interspersed with whitespace that
383 appears *identically* in all lines of the input text.
384
385 Parameters
386 ----------
387 text : str
388
389 Examples
390 --------
391
392 Simple uses::
393
394 In [2]: strip_email_quotes('> > text')
395 Out[2]: 'text'
396
397 In [3]: strip_email_quotes('> > text\\n> > more')
398 Out[3]: 'text\\nmore'
399
400 Note how only the common prefix that appears in all lines is stripped::
401
402 In [4]: strip_email_quotes('> > text\\n> > more\\n> more...')
403 Out[4]: '> text\\n> more\\nmore...'
404
405 So if any line has no quote marks ('>'), then none are stripped from any
406 of them ::
407
408 In [5]: strip_email_quotes('> > text\\n> > more\\nlast different')
409 Out[5]: '> > text\\n> > more\\nlast different'
410 """
411 lines = text.splitlines()
412 strip_len = 0
413
414 for characters in zip(*lines):
415 # Check if all characters in this position are the same
416 if len(set(characters)) > 1:
417 break
418 prefix_char = characters[0]
419
420 if prefix_char in string.whitespace or prefix_char == ">":
421 strip_len += 1
422 else:
423 break
424
425 text = "\n".join([ln[strip_len:] for ln in lines])
426 return text
427
428
429class EvalFormatter(Formatter):

Callers 1

preclean_inputMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…