Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/slugify/special.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

18 statements  

1from __future__ import annotations 

2 

3 

4def add_uppercase_char(char_list: list[tuple[str, str]]) -> list[tuple[str, str]]: 

5 """ Given a replacement char list, this adds uppercase chars to the list """ 

6 

7 # Collect additions to avoid modifying input during iteration 

8 # and ensure atomicity on error 

9 insertions = [] 

10 for item in char_list: 

11 char, xlate = item 

12 upper_dict = char.upper(), xlate.capitalize() 

13 if upper_dict not in char_list and char != upper_dict[0]: 

14 insertions.append(upper_dict) 

15 

16 # Apply all insertions to original list (maintains documented in-place modification) 

17 for upper_dict in insertions: 

18 char_list.insert(0, upper_dict) 

19 

20 return char_list 

21 

22 

23# Language specific pre translations 

24# Source awesome-slugify 

25 

26_CYRILLIC = [ # package defaults: 

27 (u'ё', u'e'), # io / yo 

28 (u'я', u'ya'), # ia 

29 (u'х', u'h'), # kh 

30 (u'у', u'y'), # u 

31 (u'щ', u'sch'), # sch 

32 (u'ю', u'u'), # iu / yu 

33] 

34CYRILLIC = add_uppercase_char(_CYRILLIC) 

35 

36_GERMAN = [ # package defaults: 

37 (u'ä', u'ae'), # a 

38 (u'ö', u'oe'), # o 

39 (u'ü', u'ue'), # u 

40] 

41GERMAN = add_uppercase_char(_GERMAN) 

42 

43_GREEK = [ # package defaults: 

44 (u'χ', u'ch'), # kh 

45 (u'Ξ', u'X'), # Ks 

46 (u'ϒ', u'Y'), # U 

47 (u'υ', u'y'), # u 

48 (u'ύ', u'y'), 

49 (u'ϋ', u'y'), 

50 (u'ΰ', u'y'), 

51] 

52GREEK = add_uppercase_char(_GREEK) 

53 

54# Pre translations 

55PRE_TRANSLATIONS = CYRILLIC + GERMAN + GREEK