forked from bugy/script-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_utils.py
More file actions
66 lines (46 loc) · 1.31 KB
/
Copy pathstring_utils.py
File metadata and controls
66 lines (46 loc) · 1.31 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def replace(old_text, new_text, start, end):
start_text = old_text[:start]
if end < (len(old_text) - 1):
end_text = old_text[end + 1:]
else:
end_text = ''
return start_text + new_text + end_text
def is_integer(text):
try:
int(text)
return True
except ValueError:
return False
def unwrap_quotes(string):
if string.startswith('"') and string.endswith('"'):
return unwrap_quotes(string[1:-1])
elif string.startswith("'") and string.endswith("'"):
return unwrap_quotes(string[1:-1])
return string
def strip(value):
if value is None:
return value
if isinstance(value, list):
return [strip(x) for x in value]
if isinstance(value, dict):
result = {}
for k, v in value.items():
result[strip(k)] = strip(v)
return result
if isinstance(value, str):
return value.strip()
return value
def is_blank(value):
if not value:
return True
if not value.strip():
return True
return False
def values_to_string(value):
if not value:
return value
if isinstance(value, dict):
return {k: str(v) for k, v in value.items()}
if isinstance(value, list):
return [str(element) for element in value]
return value