|
13 | 13 | # the License. |
14 | 14 | """Functionality for interacting with the data api""" |
15 | 15 | from pathlib import Path |
16 | | -from typing import Any, Callable, Dict, Iterator, List, Optional, Union |
| 16 | +from typing import Any, Callable, Dict, Iterator, List, Optional, TypeVar, Union |
17 | 17 |
|
18 | 18 | from planet.models import GeojsonLike |
19 | 19 |
|
|
27 | 27 | WAIT_DELAY = 5 |
28 | 28 | WAIT_MAX_ATTEMPTS = 200 |
29 | 29 |
|
| 30 | +T = TypeVar("T") |
| 31 | + |
30 | 32 |
|
31 | 33 | class DataAPI: |
32 | 34 | """Data API client""" |
@@ -75,18 +77,13 @@ def search( |
75 | 77 | references |
76 | 78 | """ |
77 | 79 |
|
78 | | - results = self._client.search(item_types, |
79 | | - search_filter, |
80 | | - name, |
81 | | - sort, |
82 | | - limit, |
83 | | - geometry) |
84 | | - |
85 | | - try: |
86 | | - while True: |
87 | | - yield self._client._call_sync(results.__anext__()) |
88 | | - except StopAsyncIteration: |
89 | | - pass |
| 80 | + return self._client._aiter_to_iter( |
| 81 | + self._client.search(item_types, |
| 82 | + search_filter, |
| 83 | + name, |
| 84 | + sort, |
| 85 | + limit, |
| 86 | + geometry)) |
90 | 87 |
|
91 | 88 | def create_search( |
92 | 89 | self, |
@@ -183,13 +180,9 @@ def list_searches(self, |
183 | 180 | planet.exceptions.ClientError: If sort or search_type are not |
184 | 181 | valid. |
185 | 182 | """ |
186 | | - results = self._client.list_searches(sort, search_type, limit) |
187 | 183 |
|
188 | | - try: |
189 | | - while True: |
190 | | - yield self._client._call_sync(results.__anext__()) |
191 | | - except StopAsyncIteration: |
192 | | - pass |
| 184 | + return self._client._aiter_to_iter( |
| 185 | + self._client.list_searches(sort, search_type, limit)) |
193 | 186 |
|
194 | 187 | def delete_search(self, search_id: str): |
195 | 188 | """Delete an existing saved search. |
@@ -242,13 +235,8 @@ def run_search(self, |
242 | 235 | planet.exceptions.ClientError: If search_id or sort is not valid. |
243 | 236 | """ |
244 | 237 |
|
245 | | - results = self._client.run_search(search_id, sort, limit) |
246 | | - |
247 | | - try: |
248 | | - while True: |
249 | | - yield self._client._call_sync(results.__anext__()) |
250 | | - except StopAsyncIteration: |
251 | | - pass |
| 238 | + return self._client._aiter_to_iter( |
| 239 | + self._client.run_search(search_id, sort, limit)) |
252 | 240 |
|
253 | 241 | def get_stats(self, |
254 | 242 | item_types: List[str], |
|
0 commit comments