#NEWLINE# def dedent( content ) : #NEWLINE# #INDENT# "\n    Remove leading indent from a block of text.\n    Used when generating descriptions from docstrings.\n\n    Note that python's `textwrap.dedent` doesn't quite cut it,\n    as it fails to dedent multiline docstrings that include\n    unindented text on the initial line.\n    " #NEWLINE# content = force_text ( content ) #NEWLINE# whitespace_counts = [ ( len ( line ) - len ( line . lstrip ( ' ' ) ) ) for line in content . splitlines ( ) [ 1 : ] if line . lstrip ( ) ] #NEWLINE# if whitespace_counts : #NEWLINE# #INDENT# whitespace_pattern = ( '^' + ( ' ' * min ( whitespace_counts ) ) ) #NEWLINE# content = re . sub ( re . compile ( whitespace_pattern , re . MULTILINE ) , '' , content ) #NEWLINE# #UNINDENT# return content . strip ( )