<s> import re <EOL> import unicodedata <EOL> SLUG_OK = '<STR_LIT>' <EOL> def slugify ( s , ok = SLUG_OK , lower = True , spaces = False ) : <EOL> rv = [ ] <EOL> for c in unicodedata . normalize ( '<STR_LIT>' , unicode ( s ) ) : <EOL> cat = unicodedata . category ( c ) [ <NUM_LIT:0> ] <EOL> if cat in '<STR_LIT>' or c in ok : <EOL> rv . append ( c ) <EOL> if cat == '<STR_LIT>' : <EOL> rv . append ( '<STR_LIT:U+0020>' ) <EOL> new = '<STR_LIT>' . join ( rv ) . strip ( ) <EOL> if not spaces : <EOL> new = re . sub ( '<STR_LIT>' , '<STR_LIT:->' , new ) <EOL> return new . lower ( ) if lower else new </s>
