import unicodedata
import re


def slugify(s, ok='-_', lower=True, spaces=False, only_ascii=True):
    """
    Courtesy of Mozilla unicode-slugify, BSD licensed.
    https://github.com/mozilla/unicode-slugify
    """
    rv = []
    for c in unicodedata.normalize('NFKC', s):
        cat = unicodedata.category(c)[0]
        if cat in 'LN' or c in ok:
            rv.append(c)
        elif cat == 'Z':  # space
            rv.append(' ')
        else:
            rv.append(ok[0])
    new = ''.join(rv).strip()
    if not spaces:
        new = re.sub('[-\s]+', ok[0], new)
    new = re.sub(re.escape(ok[0]) + '{2,}', ok[0], new).strip(ok[0])
    new = new.lower() if lower else new
    if only_ascii:
        new = new.encode('ascii', 'ignore').decode('ascii')
    return new