1010
1111import os
1212import re
13+ import string
1314import sys
1415import textwrap
1516from string import Formatter
@@ -405,22 +406,6 @@ def wrap_paragraphs(text, ncols=80):
405406 return out_ps
406407
407408
408- def long_substr (data ):
409- """Return the longest common substring in a list of strings.
410-
411- Credit: http://stackoverflow.com/questions/2892931/longest-common-substring-from-more-than-two-strings-python
412- """
413- substr = ''
414- if len (data ) > 1 and len (data [0 ]) > 0 :
415- for i in range (len (data [0 ])):
416- for j in range (len (data [0 ])- i + 1 ):
417- if j > len (substr ) and all (data [0 ][i :i + j ] in x for x in data ):
418- substr = data [0 ][i :i + j ]
419- elif len (data ) == 1 :
420- substr = data [0 ]
421- return substr
422-
423-
424409def strip_email_quotes (text ):
425410 """Strip leading email quotation characters ('>').
426411
@@ -447,27 +432,30 @@ def strip_email_quotes(text):
447432 In [4]: strip_email_quotes('> > text\\ n> > more\\ n> more...')
448433 Out[4]: '> text\\ n> more\\ nmore...'
449434
450- So if any line has no quote marks ('>') , then none are stripped from any
435+ So if any line has no quote marks ('>'), then none are stripped from any
451436 of them ::
452-
437+
453438 In [5]: strip_email_quotes('> > text\\ n> > more\\ nlast different')
454439 Out[5]: '> > text\\ n> > more\\ nlast different'
455440 """
456441 lines = text .splitlines ()
457- matches = set ()
458- for line in lines :
459- prefix = re .match (r'^(\s*>[ >]*)' , line )
460- if prefix :
461- matches .add (prefix .group (1 ))
442+ strip_len = 0
443+
444+ for characters in zip (* lines ):
445+ # Check if all characters in this position are the same
446+ if len (set (characters )) > 1 :
447+ break
448+ prefix_char = characters [0 ][0 ]
449+
450+ if prefix_char in string .whitespace or prefix_char == ">" :
451+ strip_len += 1
462452 else :
463453 break
464- else :
465- prefix = long_substr (list (matches ))
466- if prefix :
467- strip = len (prefix )
468- text = '\n ' .join ([ ln [strip :] for ln in lines ])
454+
455+ text = "\n " .join ([ln [strip_len :] for ln in lines ])
469456 return text
470457
458+
471459def strip_ansi (source ):
472460 """
473461 Remove ansi escape codes from text.
0 commit comments