File tree Expand file tree Collapse file tree 1 file changed +0
-37
lines changed
Expand file tree Collapse file tree 1 file changed +0
-37
lines changed Original file line number Diff line number Diff line change 1212User = get_user_model ()
1313log = logging .getLogger (__name__ )
1414
15- USERNAME_SEPARATOR = "-"
16- # Characters that should be replaced by the specified separator character
17- USERNAME_SEPARATOR_REPLACE_CHARS = "\\ s_"
18- # Characters that should be removed entirely from the full name to create the username
19- USERNAME_INVALID_CHAR_PATTERN = (
20- rf"[^\w{ USERNAME_SEPARATOR_REPLACE_CHARS } { USERNAME_SEPARATOR } ]|[\d]"
21- )
22-
23- USERNAME_TURKISH_I_CHARS = r"[ıİ]"
24- USERNAME_TURKISH_I_CHARS_REPLACEMENT = "i"
25-
26- # Pattern for chars to replace with a single separator. The separator character itself
27- # is also included in this pattern so repeated separators are squashed down.
28- USERNAME_SEPARATOR_REPLACE_PATTERN = (
29- rf"[{ USERNAME_SEPARATOR_REPLACE_CHARS } { USERNAME_SEPARATOR } ]+"
30- )
31-
32-
33- def _reformat_for_username (string ):
34- """
35- Removes/substitutes characters in a string to make it suitable as a username value
36-
37- Args:
38- string (str): A string
39- Returns:
40- str: A version of the string with username-appropriate characters
41- """
42- cleaned_string = re .sub (USERNAME_INVALID_CHAR_PATTERN , "" , string )
43- cleaned_string = re .sub (
44- USERNAME_TURKISH_I_CHARS , USERNAME_TURKISH_I_CHARS_REPLACEMENT , cleaned_string
45- )
46- return (
47- re .sub (USERNAME_SEPARATOR_REPLACE_PATTERN , USERNAME_SEPARATOR , cleaned_string )
48- .lower ()
49- .strip (USERNAME_SEPARATOR )
50- )
51-
5215
5316def is_duplicate_username_error (exc ):
5417 """
You can’t perform that action at this time.
0 commit comments