diff --git a/IPython/utils/text.py b/IPython/utils/text.py index 2646745..5d18b6c 100644 --- a/IPython/utils/text.py +++ b/IPython/utils/text.py @@ -560,6 +560,35 @@ def long_substr(data): def strip_email_quotes(text): """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_email_quotes('> > text') + Out[2]: 'text' + + In [3]: strip_email_quotes('> > text\n> > more') + Out[3]: 'text\nmore' + + Note how only the common prefix that appears in all lines is stripped:: + + In [4]: strip_email_quotes('> > text\n> > more\n> more...') + Out[4]: '> text\n> more\nmore...' + + So if any line has no quote marks ('>') , then none are stripped from any + of them :: + + In [5]: strip_email_quotes('> > text\n> > more\nlast different') + Out[5]: '> > text\n> > more\nlast different' """ lines = text.splitlines() matches = set() @@ -601,6 +630,7 @@ class EvalFormatter(Formatter): v = eval(name, kwargs) return v, name + @skip_doctest_py3 class FullEvalFormatter(Formatter): """A String Formatter that allows evaluation of simple expressions. @@ -658,6 +688,7 @@ class FullEvalFormatter(Formatter): return u''.join(py3compat.cast_unicode(s) for s in result) + @skip_doctest_py3 class DollarFormatter(FullEvalFormatter): """Formatter allowing Itpl style $foo replacement, for names and attribute @@ -700,11 +731,13 @@ class DollarFormatter(FullEvalFormatter): #----------------------------------------------------------------------------- # Utils to columnize a list of string #----------------------------------------------------------------------------- + def _chunks(l, n): """Yield successive n-sized chunks from l.""" for i in xrange(0, len(l), n): yield l[i:i+n] + def _find_optimal(rlist , separator_size=2 , displaywidth=80): """Calculate optimal info to columnize a list of string""" for nrow in range(1, len(rlist)+1) : @@ -719,6 +752,7 @@ def _find_optimal(rlist , separator_size=2 , displaywidth=80): 'columns_width' : chk } + def _get_or_default(mylist, i, default=None): """return list item number, or default if don't exist""" if i >= len(mylist): @@ -726,6 +760,7 @@ def _get_or_default(mylist, i, default=None): else : return mylist[i] + @skip_doctest def compute_item_matrix(items, empty=None, *args, **kwargs) : """Returns a nested list, and info to columnize items @@ -783,6 +818,7 @@ def compute_item_matrix(items, empty=None, *args, **kwargs) : nrow, ncol = info['rows_numbers'], info['columns_numbers'] return ([[ _get_or_default(items, c*nrow+i, default=empty) for c in range(ncol) ] for i in range(nrow) ], info) + def columnize(items, separator=' ', displaywidth=80): """ Transform a list of strings into a single string with columns.