-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
44 lines (33 loc) · 1.07 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import re
from typing import List
def has_more_cyrillic_than_latin(string):
if string == None:
return
pattern = '[а-яА-Я]'
cyrillic = re.findall(pattern, string)
latin = [x for x in string if (x.isalpha() and x not in cyrillic)]
return len(cyrillic) > len(latin)
def is_empty_string(text):
return text.strip() == ''
class SafeList(list):
def __getitem__(self, i):
try:
return super().__getitem__(i)
except IndexError:
return None
class SafeString(str):
def __getitem__(self, i):
try:
return super().__getitem__(i)
except IndexError:
return None
def strip(self):
return SafeString(super().strip())
def rstrip(self):
return SafeString(super().rstrip())
def lstrip(self):
return SafeString(super().lstrip())
def split(self, *args, **kwargs) -> List[str]:
return SafeList(super().split(*args, **kwargs))
def rsplit(self, *args, **kwargs) -> List[str]:
return SafeList(super().rsplit(*args, **kwargs))