<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def collapse_spaces(text):
 """Remove newlines, tabs and multiple spaces with single spaces."""

    if not isinstance(text, six.string_types):
        return text
    return COLLAPSE_RE.sub(WS, text).strip(WS)