def slugify(value, allow_unicode=False):
value = str(value)<EOL>if allow_unicode:<EOL><INDENT>value = unicodedata.normalize('<STR_LIT>', value)<EOL><DEDENT>else:<EOL><INDENT>value = unicodedata.normalize('<STR_LIT>', value).encode('<STR_LIT:ascii>', '<STR_LIT:ignore>').decode('<STR_LIT:ascii>')<EOL><DEDENT>value = re.sub(r'<STR_LIT>', '<STR_LIT>', value).strip().lower()<EOL>return re.sub(r'<STR_LIT>', '<STR_LIT:->', value)<EOL>
Convert to ASCII if 'allow_unicode' is False. Convert spaces to hyphens.
Remove characters that aren't alphanumerics, underscores, or hyphens.
Convert to lowercase. Also strip leading and trailing whitespace.