def CutCommonSpacePrefix(text):
 text_lines = text.splitlines()
 while (text_lines and (not text_lines[(-1)])):
  text_lines = text_lines[:(-1)]
 if text_lines:
  if (text_lines[0] and text_lines[0][0].isspace()):
   text_first_line = []
  else:
   text_first_line = [text_lines.pop(0)]
  common_prefix = os.path.commonprefix([line for line in text_lines if line])
  space_prefix_len = (len(common_prefix) - len(common_prefix.lstrip()))
  if space_prefix_len:
   for index in xrange(len(text_lines)):
    if text_lines[index]:
     text_lines[index] = text_lines[index][space_prefix_len:]
  return '\n'.join((text_first_line + text_lines))
 return ''

def CutCommonSpacePrefix ( text ) : text_lines = text . splitlines ( ) while ( text_lines and ( not text_lines [ ( - 1 ) ] ) ) : text_lines = text_lines [ : ( - 1 ) ] if text_lines : if ( text_lines [ 0 ] and text_lines [ 0 ] [ 0 ] . isspace ( ) ) : text_first_line = [ ] else : text_first_line = [ text_lines . pop ( 0 ) ] common_prefix = os . path . commonprefix ( [ line for line in text_lines if line ] ) space_prefix_len = ( len ( common_prefix ) - len ( common_prefix . lstrip ( ) ) ) if space_prefix_len : for index in xrange ( len ( text_lines ) ) : if text_lines [ index ] : text_lines [ index ] = text_lines [ index ] [ space_prefix_len : ] return '\n' . join ( ( text_first_line + text_lines ) ) return ''
removes a common space prefix from the lines of a multiline text .