code: def collapse_spaces(text):
      
      if not isinstance(text, six.string_types):
          return text
      return COLLAPSE_RE.sub(WS, text).strip(WS)
docs: Remove newlines, tabs and multiple spaces with single spaces.