11import re
2- import unicodedata
32import sys
3+ import typing
4+ import unicodedata
45from html .entities import name2codepoint
56
67try :
1516DECIMAL_PATTERN = re .compile (r'&#(\d+);' )
1617HEX_PATTERN = re .compile (r'&#x([\da-fA-F]+);' )
1718QUOTE_PATTERN = re .compile (r'[\']+' )
18- ALLOWED_CHARS_PATTERN = re .compile (r'[^-a-z0-9]+' )
19- ALLOWED_CHARS_PATTERN_WITH_UPPERCASE = re .compile (r'[^-a-zA-Z0-9]+' )
19+ DISALLOWED_CHARS_PATTERN = re .compile (r'[^-a-zA-Z0-9]+' )
2020DUPLICATE_DASH_PATTERN = re .compile (r'-{2,}' )
2121NUMBERS_PATTERN = re .compile (r'(?<=\d),(?=\d)' )
2222DEFAULT_SEPARATOR = '-'
@@ -66,7 +66,7 @@ def smart_truncate(string, max_length=0, word_boundary=False, separator=' ', sav
6666
6767def slugify (text , entities = True , decimal = True , hexadecimal = True , max_length = 0 , word_boundary = False ,
6868 separator = DEFAULT_SEPARATOR , save_order = False , stopwords = (), regex_pattern = None , lowercase = True ,
69- replacements = ()):
69+ replacements : typing . Iterable [ typing . Iterable [ str ]] = ()):
7070 """
7171 Make a slug from the given text.
7272 :param text (str): initial text
@@ -78,7 +78,7 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
7878 :param save_order (bool): if parameter is True and max_length > 0 return whole words in the initial order
7979 :param separator (str): separator between words
8080 :param stopwords (iterable): words to discount
81- :param regex_pattern (str): regex pattern for allowed characters
81+ :param regex_pattern (str): regex pattern for disallowed characters
8282 :param lowercase (bool): activate case sensitivity by setting it to False
8383 :param replacements (iterable): list of replacement rules e.g. [['|', 'or'], ['%', 'percent']]
8484 :return (str):
@@ -137,10 +137,7 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
137137 text = NUMBERS_PATTERN .sub ('' , text )
138138
139139 # replace all other unwanted characters
140- if lowercase :
141- pattern = regex_pattern or ALLOWED_CHARS_PATTERN
142- else :
143- pattern = regex_pattern or ALLOWED_CHARS_PATTERN_WITH_UPPERCASE
140+ pattern = regex_pattern or DISALLOWED_CHARS_PATTERN
144141 text = re .sub (pattern , DEFAULT_SEPARATOR , text )
145142
146143 # remove redundant
0 commit comments