def cleandoc(doc):
 try:
  lines = string.split(string.expandtabs(doc), '\n')
 except UnicodeError:
  return None
 else:
  margin = sys.maxint
  for line in lines[1:]:
   content = len(string.lstrip(line))
   if content:
    indent = (len(line) - content)
    margin = min(margin, indent)
  if lines:
   lines[0] = lines[0].lstrip()
  if (margin < sys.maxint):
   for i in range(1, len(lines)):
    lines[i] = lines[i][margin:]
  while (lines and (not lines[(-1)])):
   lines.pop()
  while (lines and (not lines[0])):
   lines.pop(0)
  return string.join(lines, '\n')

def cleandoc ( doc ) : try : lines = string . split ( string . expandtabs ( doc ) , '\n' ) except UnicodeError : return None else : margin = sys . maxint for line in lines [ 1 : ] : content = len ( string . lstrip ( line ) ) if content : indent = ( len ( line ) - content ) margin = min ( margin , indent ) if lines : lines [ 0 ] = lines [ 0 ] . lstrip ( ) if ( margin < sys . maxint ) : for i in range ( 1 , len ( lines ) ) : lines [ i ] = lines [ i ] [ margin : ] while ( lines and ( not lines [ ( - 1 ) ] ) ) : lines . pop ( ) while ( lines and ( not lines [ 0 ] ) ) : lines . pop ( 0 ) return string . join ( lines , '\n' )
clean up indentation from docstrings .