def text_normalize(text):
 if isinstance(text, bytes):
  text = codecs.decode(text)
 lines = [line.strip() for line in text.splitlines() if line.strip()]
 return '\n'.join(lines)

def text_normalize ( text ) : if isinstance ( text , bytes ) : text = codecs . decode ( text ) lines = [ line . strip ( ) for line in text . splitlines ( ) if line . strip ( ) ] return '\n' . join ( lines )
whitespace normalization: - strip empty lines - strip leading whitespace in a line - strip trailing whitespace in a line - normalize line endings .