'Clean a query of invalid tokens.'

@staticmethod
def clean_query(query, replace=chr(26)):

    accum = []
    any_invalid = False
    tokens = _quote_re.findall(query)
    for token in tokens:
        if (token.startswith('"') and token.endswith('"')):
            accum.append(token)
            continue
        token_set = set(token)
        invalid_for_token = (token_set & _invalid_ascii)
        if invalid_for_token:
            any_invalid = True
            for c in invalid_for_token:
                token = token.replace(c, replace)
        accum.append(token)
    if any_invalid:
        return '    '.join(accum)
    return query
