forked from tableau/document-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
33 lines (30 loc) · 874 Bytes
/
base.py
File metadata and controls
33 lines (30 loc) · 874 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
class BaseObject:
def _to_dict(
self, base_attrs=[], to_dict_attrs=[],
to_dict_list_attrs=[], to_dict_of_dict_attrs=[]
):
base = {
k.replace('_', ''): getattr(self, k) for k in base_attrs
if getattr(self, k)
}
base.update(
{
k: getattr(self, k).to_dict() for k in to_dict_attrs
if getattr(self, k)
}
)
base.update(
{
k: [i.to_dict() for i in getattr(self, k)]
for k in to_dict_list_attrs
if getattr(self, k)
}
)
base.update(
{
i: {k:v.to_dict() for k, v in getattr(self, i).items()}
for i in to_dict_of_dict_attrs
if getattr(self, i)
}
)
return base