|
10 | 10 | from vws.response import Response |
11 | 11 |
|
12 | 12 |
|
13 | | -def _httpx_timeout( |
14 | | - request_timeout: float | tuple[float, float], |
15 | | -) -> httpx.Timeout: |
16 | | - """Convert a VWS request timeout to an ``httpx`` timeout.""" |
17 | | - match request_timeout: |
18 | | - case (connect_timeout, read_timeout): |
19 | | - return httpx.Timeout( |
20 | | - connect=connect_timeout, |
21 | | - read=read_timeout, |
22 | | - write=None, |
23 | | - pool=None, |
24 | | - ) |
25 | | - case float() | int() as timeout: |
26 | | - return httpx.Timeout( |
27 | | - connect=timeout, |
28 | | - read=timeout, |
29 | | - write=None, |
30 | | - pool=None, |
31 | | - ) |
32 | | - case _: # pragma: no cover |
33 | | - raise AssertionError |
34 | | - |
35 | | - |
36 | 13 | @runtime_checkable |
37 | 14 | class Transport(Protocol): |
38 | 15 | """Protocol for HTTP transports used by VWS clients. |
@@ -172,12 +149,30 @@ def __call__( |
172 | 149 | Returns: |
173 | 150 | A Response populated from the httpx response. |
174 | 151 | """ |
| 152 | + match request_timeout: |
| 153 | + case (connect_timeout, read_timeout): |
| 154 | + httpx_timeout = httpx.Timeout( |
| 155 | + connect=connect_timeout, |
| 156 | + read=read_timeout, |
| 157 | + write=None, |
| 158 | + pool=None, |
| 159 | + ) |
| 160 | + case float() | int() as timeout: |
| 161 | + httpx_timeout = httpx.Timeout( |
| 162 | + connect=timeout, |
| 163 | + read=timeout, |
| 164 | + write=None, |
| 165 | + pool=None, |
| 166 | + ) |
| 167 | + case _: # pragma: no cover |
| 168 | + raise AssertionError |
| 169 | + |
175 | 170 | httpx_response = self._client.request( |
176 | 171 | method=method, |
177 | 172 | url=url, |
178 | 173 | headers=headers, |
179 | 174 | content=data, |
180 | | - timeout=_httpx_timeout(request_timeout=request_timeout), |
| 175 | + timeout=httpx_timeout, |
181 | 176 | follow_redirects=True, |
182 | 177 | ) |
183 | 178 |
|
@@ -279,12 +274,30 @@ async def __call__( |
279 | 274 | Returns: |
280 | 275 | A Response populated from the httpx response. |
281 | 276 | """ |
| 277 | + match request_timeout: |
| 278 | + case (connect_timeout, read_timeout): |
| 279 | + httpx_timeout = httpx.Timeout( |
| 280 | + connect=connect_timeout, |
| 281 | + read=read_timeout, |
| 282 | + write=None, |
| 283 | + pool=None, |
| 284 | + ) |
| 285 | + case float() | int() as timeout: |
| 286 | + httpx_timeout = httpx.Timeout( |
| 287 | + connect=timeout, |
| 288 | + read=timeout, |
| 289 | + write=None, |
| 290 | + pool=None, |
| 291 | + ) |
| 292 | + case _: # pragma: no cover |
| 293 | + raise AssertionError |
| 294 | + |
282 | 295 | httpx_response = await self._client.request( |
283 | 296 | method=method, |
284 | 297 | url=url, |
285 | 298 | headers=headers, |
286 | 299 | content=data, |
287 | | - timeout=_httpx_timeout(request_timeout=request_timeout), |
| 300 | + timeout=httpx_timeout, |
288 | 301 | follow_redirects=True, |
289 | 302 | ) |
290 | 303 |
|
|
0 commit comments