forked from core-api/python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
40 lines (24 loc) · 965 Bytes
/
Copy pathbase.py
File metadata and controls
40 lines (24 loc) · 965 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
from coreapi.compat import string_types
import itypes
# Helper functions to get an expected type from a dictionary.
def _get_string(item, key):
value = item.get(key)
return value if isinstance(value, string_types) else ''
def _get_dict(item, key):
value = item.get(key)
return value if isinstance(value, dict) else {}
def _get_list(item, key):
value = item.get(key)
return value if isinstance(value, list) else []
def _get_bool(item, key, default=False):
value = item.get(key)
return value if isinstance(value, bool) else default
# Helper functions to get an expected type from a list.
def get_dicts(item):
return [value for value in item if isinstance(value, dict)]
class BaseCodec(itypes.Object):
media_type = None
def load(self, bytes, base_url=None):
raise NotImplementedError() # pragma: nocover
def dump(self, document, **kwargs):
raise NotImplementedError() # pragma: nocover