##// END OF EJS Templates
Add full docstring to strip_email_quotes
Fernando Perez -
Show More
@@ -560,6 +560,35 b' def long_substr(data):'
560
560
561 def strip_email_quotes(text):
561 def strip_email_quotes(text):
562 """Strip leading email quotation characters ('>').
562 """Strip leading email quotation characters ('>').
563
564 Removes any combination of leading '>' interspersed with whitespace that
565 appears *identically* in all lines of the input text.
566
567 Parameters
568 ----------
569 text : str
570
571 Examples
572 --------
573
574 Simple uses::
575
576 In [2]: strip_email_quotes('> > text')
577 Out[2]: 'text'
578
579 In [3]: strip_email_quotes('> > text\n> > more')
580 Out[3]: 'text\nmore'
581
582 Note how only the common prefix that appears in all lines is stripped::
583
584 In [4]: strip_email_quotes('> > text\n> > more\n> more...')
585 Out[4]: '> text\n> more\nmore...'
586
587 So if any line has no quote marks ('>') , then none are stripped from any
588 of them ::
589
590 In [5]: strip_email_quotes('> > text\n> > more\nlast different')
591 Out[5]: '> > text\n> > more\nlast different'
563 """
592 """
564 lines = text.splitlines()
593 lines = text.splitlines()
565 matches = set()
594 matches = set()
@@ -601,6 +630,7 b' class EvalFormatter(Formatter):'
601 v = eval(name, kwargs)
630 v = eval(name, kwargs)
602 return v, name
631 return v, name
603
632
633
604 @skip_doctest_py3
634 @skip_doctest_py3
605 class FullEvalFormatter(Formatter):
635 class FullEvalFormatter(Formatter):
606 """A String Formatter that allows evaluation of simple expressions.
636 """A String Formatter that allows evaluation of simple expressions.
@@ -658,6 +688,7 b' class FullEvalFormatter(Formatter):'
658
688
659 return u''.join(py3compat.cast_unicode(s) for s in result)
689 return u''.join(py3compat.cast_unicode(s) for s in result)
660
690
691
661 @skip_doctest_py3
692 @skip_doctest_py3
662 class DollarFormatter(FullEvalFormatter):
693 class DollarFormatter(FullEvalFormatter):
663 """Formatter allowing Itpl style $foo replacement, for names and attribute
694 """Formatter allowing Itpl style $foo replacement, for names and attribute
@@ -700,11 +731,13 b' class DollarFormatter(FullEvalFormatter):'
700 #-----------------------------------------------------------------------------
731 #-----------------------------------------------------------------------------
701 # Utils to columnize a list of string
732 # Utils to columnize a list of string
702 #-----------------------------------------------------------------------------
733 #-----------------------------------------------------------------------------
734
703 def _chunks(l, n):
735 def _chunks(l, n):
704 """Yield successive n-sized chunks from l."""
736 """Yield successive n-sized chunks from l."""
705 for i in xrange(0, len(l), n):
737 for i in xrange(0, len(l), n):
706 yield l[i:i+n]
738 yield l[i:i+n]
707
739
740
708 def _find_optimal(rlist , separator_size=2 , displaywidth=80):
741 def _find_optimal(rlist , separator_size=2 , displaywidth=80):
709 """Calculate optimal info to columnize a list of string"""
742 """Calculate optimal info to columnize a list of string"""
710 for nrow in range(1, len(rlist)+1) :
743 for nrow in range(1, len(rlist)+1) :
@@ -719,6 +752,7 b' def _find_optimal(rlist , separator_size=2 , displaywidth=80):'
719 'columns_width' : chk
752 'columns_width' : chk
720 }
753 }
721
754
755
722 def _get_or_default(mylist, i, default=None):
756 def _get_or_default(mylist, i, default=None):
723 """return list item number, or default if don't exist"""
757 """return list item number, or default if don't exist"""
724 if i >= len(mylist):
758 if i >= len(mylist):
@@ -726,6 +760,7 b' def _get_or_default(mylist, i, default=None):'
726 else :
760 else :
727 return mylist[i]
761 return mylist[i]
728
762
763
729 @skip_doctest
764 @skip_doctest
730 def compute_item_matrix(items, empty=None, *args, **kwargs) :
765 def compute_item_matrix(items, empty=None, *args, **kwargs) :
731 """Returns a nested list, and info to columnize items
766 """Returns a nested list, and info to columnize items
@@ -783,6 +818,7 b' def compute_item_matrix(items, empty=None, *args, **kwargs) :'
783 nrow, ncol = info['rows_numbers'], info['columns_numbers']
818 nrow, ncol = info['rows_numbers'], info['columns_numbers']
784 return ([[ _get_or_default(items, c*nrow+i, default=empty) for c in range(ncol) ] for i in range(nrow) ], info)
819 return ([[ _get_or_default(items, c*nrow+i, default=empty) for c in range(ncol) ] for i in range(nrow) ], info)
785
820
821
786 def columnize(items, separator=' ', displaywidth=80):
822 def columnize(items, separator=' ', displaywidth=80):
787 """ Transform a list of strings into a single string with columns.
823 """ Transform a list of strings into a single string with columns.
788
824
General Comments 0
You need to be logged in to leave comments. Login now