HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/faker/utils/text.py
import re
import unicodedata

from typing import Pattern

_re_pattern: Pattern = re.compile(r"[^\w\s-]", flags=re.U)
_re_pattern_allow_dots: Pattern = re.compile(r"[^\.\w\s-]", flags=re.U)
_re_spaces: Pattern = re.compile(r"[-\s]+", flags=re.U)


def slugify(value: str, allow_dots: bool = False, allow_unicode: bool = False) -> str:
    """
    Converts to lowercase, removes non-word characters (alphanumerics and
    underscores) and converts spaces to hyphens. Also strips leading and
    trailing whitespace. Modified to optionally allow dots.

    Adapted from Django 1.9
    """
    pattern: Pattern = _re_pattern_allow_dots if allow_dots else _re_pattern

    value = str(value)
    if allow_unicode:
        value = unicodedata.normalize("NFKC", value)
        value = pattern.sub("", value).strip().lower()
        return _re_spaces.sub("-", value)
    value = unicodedata.normalize("NFKD", value).encode("ascii", "ignore").decode("ascii")
    value = pattern.sub("", value).strip().lower()
    return _re_spaces.sub("-", value)