def collapse_spaces(text):
if not isinstance(text, six.string_types):<EOL><INDENT>return text<EOL><DEDENT>return COLLAPSE_RE.sub(WS, text).strip(WS)<EOL>
Remove newlines, tabs and multiple spaces with single spaces.