def wash_for_utf8(text, correct=True):
if isinstance(text, unicode):<EOL><INDENT>return text.encode('<STR_LIT:utf-8>')<EOL><DEDENT>errors = "<STR_LIT:ignore>" if correct else "<STR_LIT:strict>"<EOL>return text.decode("<STR_LIT:utf-8>", errors).encode("<STR_LIT:utf-8>", errors)<EOL>
Return UTF-8 encoded binary string with incorrect characters washed away.

    :param text: input string to wash (can be either a binary or Unicode string)
    :param correct: whether to correct bad characters or throw exception