def category_replace(text, replacements=UNICODE_CATEGORIES):
if text is None:<EOL><INDENT>return None<EOL><DEDENT>characters = []<EOL>for character in decompose_nfkd(text):<EOL><INDENT>cat = category(character)<EOL>replacement = replacements.get(cat, character)<EOL>if replacement is not None:<EOL><INDENT>characters.append(replacement)<EOL><DEDENT><DEDENT>return u'<STR_LIT>'.join(characters)<EOL>
Remove characters from a string based on unicode classes.

    This is a method for removing non-text characters (such as punctuation,
    whitespace, marks and diacritics) from a piece of text by class, rather
    than specifying them individually.