-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
45 lines (30 loc) · 1022 Bytes
/
utils.py
File metadata and controls
45 lines (30 loc) · 1022 Bytes
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
from re import sub
def camelize(s):
s = sub(r"(_|-)+", " ", s).title().replace(" ", "")
return ''.join([s[0].lower(), s[1:]])
def pascalize(s):
s = sub(r"(_|-)+", " ", s).title().replace(" ", "")
return ''.join([s[0].upper(), s[1:]])
def snakify(name):
s1 = sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
def is_list(value):
return isinstance(value, list)
def quote(s):
if str(s)[:5] == 'json(':
return '`'+str(s)+'`'
return '"'+str(s)+'"'
def make_dot_string(value, *args):
lst = value + list(args)
s = ".".join(lst)
return s
def eliminate_zeroes(value):
return '.'.join(value.split(".0."))
def eliminate_zeroes_and_capitalize(value):
return pascalize('_'.join(value.split(".0.")))
def eliminate_dots_and_capitalize(value):
return pascalize('_'.join(value.split(".")))
def get_first(value):
return value.split(".")[0]
def eliminate_first(value):
return '.'.join(value.split(".")[1:])