def dedent(text):
 margin = None
 text = _whitespace_only_re.sub('', text)
 indents = _leading_whitespace_re.findall(text)
 for indent in indents:
  if (margin is None):
   margin = indent
  elif indent.startswith(margin):
   pass
  elif margin.startswith(indent):
   margin = indent
  else:
   margin = ''
   break
 if (0 and margin):
  for line in text.split('\n'):
   assert ((not line) or line.startswith(margin)), ('line = %r, margin = %r' % (line, margin))
 if margin:
  text = re.sub(('(?m)^' + margin), '', text)
 return text

def dedent ( text ) : margin = None text = _whitespace_only_re . sub ( '' , text ) indents = _leading_whitespace_re . findall ( text ) for indent in indents : if ( margin is None ) : margin = indent elif indent . startswith ( margin ) : pass elif margin . startswith ( indent ) : margin = indent else : margin = '' break if ( 0 and margin ) : for line in text . split ( '\n' ) : assert ( ( not line ) or line . startswith ( margin ) ) , ( 'line = %r, margin = %r' % ( line , margin ) ) if margin : text = re . sub ( ( '(?m)^' + margin ) , '' , text ) return text
remove excess indentation from docstring *s* .