MCPcopy Create free account
hub / github.com/daniel2005d/mapXplore / Util

Class Util

utils/utils.py:11–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10
11class Util:
12
13 @staticmethod
14 def check_file(file_name:str)->bool:
15 if not os.path.exists(file_name) or not os.path.isfile(file_name):
16 return False
17
18 return True
19
20 @staticmethod
21 def search_text_array(text:str,list:list[str]):
22 matches = []
23 for index, item in enumerate(list):
24 match = re.findall(text, item, flags=re.IGNORECASE)
25 if len(match)>0:
26 matches.append({"index":index, "value": item})
27
28 return matches
29
30 @staticmethod
31 def format_number(value:object)->str:
32 if isinstance(value, int):
33 return f'{value:,.0f}'
34 else:
35 return format(int(value))
36
37 @staticmethod
38 def is_bool(value:str)->bool:
39 return value.lower() in ('yes','true','false','no') if value is not None else False
40
41 @staticmethod
42 def is_base64(value:str)->bool:
43 isBase64 = False
44 try:
45 b64decode(value)
46 isBase64 = True
47 except:
48 pass
49
50 return isBase64
51
52 @staticmethod
53 def is_readable(content:bytes)->bool:
54 allowed_bytes = set(range(32, 127)) | {10,13} | {241,243,250}
55
56 for byte in content:
57 if byte not in allowed_bytes:
58 return False
59 return True
60
61 def get_readable_content(content:bytes)->str:
62 text = ""
63 allowed_bytes = set(range(32, 127)) | {10,13} | {241,243,250}
64
65 for byte in content:
66 if byte not in allowed_bytes:
67 text+=" "
68 else:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected