14
14
15
15
if 0 : # noqa
16
16
from typing import Dict # noqa
17
+ from typing import List # noqa
18
+ from typing import Tuple # noqa
19
+
20
+ Filters = List [Tuple [str , str ]]
17
21
18
22
CONF = config .CONF
19
23
LOG = logging .getLogger (__name__ )
@@ -91,13 +95,17 @@ def _handle_error(operation, exc):
91
95
92
96
93
97
def get (url , params = None , stream = False ):
94
- # type: (str, dict , bool) -> requests.Response
98
+ # type: (str, Filters , bool) -> requests.Response
95
99
"""Make GET request and handle errors."""
96
100
LOG .debug ('GET %s' , url )
97
101
98
102
try :
99
- rsp = requests .get (url , auth = _get_auth (), headers = _get_headers (),
100
- params = params , stream = stream )
103
+ # TODO(stephenfin): We only use a subset of the types possible for
104
+ # 'params' (namely a list of tuples) but it doesn't seem possible to
105
+ # indicate this
106
+ rsp = requests .get ( # type: ignore
107
+ url , auth = _get_auth (), headers = _get_headers (), params = params ,
108
+ stream = stream )
101
109
rsp .raise_for_status ()
102
110
except requests .exceptions .RequestException as exc :
103
111
_handle_error ('fetch' , exc )
@@ -107,7 +115,8 @@ def get(url, params=None, stream=False):
107
115
return rsp
108
116
109
117
110
- def put (url , data ): # type: (str, dict) -> requests.Response
118
+ def put (url , data ):
119
+ # type: (str, dict) -> requests.Response
111
120
"""Make PUT request and handle errors."""
112
121
LOG .debug ('PUT %s, data=%r' , url , data )
113
122
@@ -123,15 +132,15 @@ def put(url, data): # type: (str, dict) -> requests.Response
123
132
return rsp
124
133
125
134
126
- def download (url , params = None ): # type: (str, dict) -> None
135
+ def download (url , params = None ):
136
+ # type: (str, Filters) -> str
127
137
"""Retrieve a specific API resource and save it to a file.
128
138
129
139
GET /{resource}/{resourceID}/
130
140
131
141
Arguments:
132
- resource_type (str): The resource endpoint name.
133
- resource_id (int/str): The ID for the specific resource.
134
- params (dict/list): Additional parameters.
142
+ url: The resource URL.
143
+ params: Additional parameters.
135
144
136
145
Returns:
137
146
A path to an output file containing the content.
@@ -148,7 +157,8 @@ def download(url, params=None): # type: (str, dict) -> None
148
157
return output_path
149
158
150
159
151
- def index (resource_type , params = None ): # type: (str, dict) -> dict
160
+ def index (resource_type , params = None ):
161
+ # type: (str, Filters) -> dict
152
162
"""List API resources.
153
163
154
164
GET /{resource}/
@@ -157,8 +167,8 @@ def index(resource_type, params=None): # type: (str, dict) -> dict
157
167
fashion.
158
168
159
169
Arguments:
160
- resource_type (str) : The resource endpoint name.
161
- params (dict/list) : Additional parameters, filters.
170
+ resource_type: The resource endpoint name.
171
+ params: Additional parameters, filters.
162
172
163
173
Returns:
164
174
A list of dictionaries, representing the summary view of each resource.
@@ -175,15 +185,15 @@ def index(resource_type, params=None): # type: (str, dict) -> dict
175
185
176
186
177
187
def detail (resource_type , resource_id , params = None ):
178
- # type: (str, int, dict ) -> dict
188
+ # type: (str, int, Filters ) -> Dict
179
189
"""Retrieve a specific API resource.
180
190
181
191
GET /{resource}/{resourceID}/
182
192
183
193
Arguments:
184
- resource_type (str) : The resource endpoint name.
185
- resource_id (int/str) : The ID for the specific resource.
186
- params (dict/list) : Additional parameters.
194
+ resource_type: The resource endpoint name.
195
+ resource_id: The ID for the specific resource.
196
+ params: Additional parameters.
187
197
188
198
Returns:
189
199
A dictionary representing the detailed view of a given resource.
@@ -202,9 +212,9 @@ def update(resource_type, resource_id, data):
202
212
PUT /{resource}/{resourceID}/
203
213
204
214
Arguments:
205
- resource_type (str) : The resource endpoint name.
206
- resource_id (int/str) : The ID for the specific resource.
207
- params (dict/list) : Fields to update.
215
+ resource_type: The resource endpoint name.
216
+ resource_id: The ID for the specific resource.
217
+ params: Fields to update.
208
218
209
219
Returns:
210
220
A dictionary representing the detailed view of a given resource.
0 commit comments