Skip to content

Commit 4be30de

Browse files
author
Thomas Basche
committed
Linting
1 parent 31175ec commit 4be30de

2 files changed

Lines changed: 31 additions & 31 deletions

File tree

reposit/data/api.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import requests
77

88
from reposit.data.exceptions import InvalidControllerException
9-
from reposit.data.utils import is_valid_url
9+
from reposit.data.utils import is_valid_url, deepest_key, match_to_schema
1010
from reposit.settings import BASE_URL
11-
from reposit.utilities import dict_iter
1211

1312
logger = logging.getLogger(__name__)
1413

@@ -103,32 +102,3 @@ def _simple_format_for_fields(self, api_response):
103102
target_key = deepest_key(self.schema)
104103
target_data = match_to_schema(data, target_key)
105104
return target_data
106-
107-
108-
def deepest_key(_dict):
109-
"""Return the deepest key in a dict"""
110-
for key, value in dict_iter(_dict):
111-
if isinstance(value, dict) and bool(value):
112-
return deepest_key(_dict[key])
113-
return key
114-
115-
116-
def match_to_schema(_dict, requested_key):
117-
"""
118-
Match the schema supplied with the response to return the
119-
data we requested.
120-
:param _dict:
121-
:param requested_key:
122-
:return:
123-
"""
124-
if _dict.get(requested_key) is not None:
125-
return _dict[requested_key]
126-
127-
for valid_key in _dict:
128-
if valid_key == requested_key:
129-
if not isinstance(_dict.get(valid_key), dict):
130-
return _dict[valid_key]
131-
else:
132-
continue
133-
elif valid_key != requested_key and isinstance(_dict.get(valid_key), dict):
134-
return match_to_schema(_dict[valid_key], requested_key)

reposit/data/utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,33 @@ def is_valid_url(url):
1818
:return:
1919
"""
2020
return bool(re.match(VALID_URL_REGEX, url))
21+
22+
23+
def deepest_key(_dict):
24+
"""Return the deepest key in a dict"""
25+
for key, value in dict_iter(_dict):
26+
if isinstance(value, dict) and bool(value):
27+
return deepest_key(_dict[key])
28+
return key
29+
30+
31+
def match_to_schema(_dict, requested_key):
32+
"""
33+
Match the schema supplied with the response to return the
34+
data we requested.
35+
:param _dict:
36+
:param requested_key:
37+
:return:
38+
"""
39+
if _dict.get(requested_key) is not None:
40+
return _dict[requested_key]
41+
42+
for valid_key in _dict:
43+
if valid_key == requested_key:
44+
if not isinstance(_dict.get(valid_key), dict):
45+
return _dict[valid_key]
46+
else:
47+
continue
48+
elif valid_key != requested_key and isinstance(_dict.get(valid_key), dict):
49+
return match_to_schema(_dict[valid_key], requested_key)
50+
return None

0 commit comments

Comments
 (0)