-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
32 lines (27 loc) · 862 Bytes
/
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
def verify_string(input, name, max_length):
if len(input) <= max_length:
return input
else:
return (
"Error",
f"'{name}' needs to be shorter than {max_length}."
)
def verify_int(input, name, max_size):
try:
number = int(input)
if number <= max_size:
return number
else:
line_break = '\n' if len(name) > 20 else ''
return (
"Error",
f"'{name}'{line_break}needs to be smaller than {max_size}."
)
except ValueError:
line_break = '\n' if len(name) > 20 else ''
return (
"Error",
f"'{name}'{line_break}needs to be an integer value."
)
def is_error(potential_error):
return isinstance(potential_error, tuple) and potential_error[0] == "Error"