|
47 | 47 | DEFAULT_BASE_URL = "https://api.pdfrest.com" |
48 | 48 | API_KEY_ENV_VAR = "PDFREST_API_KEY" |
49 | 49 | API_KEY_HEADER_NAME = "Api-Key" |
50 | | -DEFAULT_TIMEOUT_SECONDS = 10.0 |
| 50 | +DEFAULT_GENERAL_TIMEOUT_SECONDS = 10.0 |
| 51 | +DEFAULT_READ_TIMEOUT_SECONDS = 120.0 |
51 | 52 | FILE_UPLOAD_FIELD_NAME = "file" |
52 | 53 | DEFAULT_FILE_INFO_CONCURRENCY = 8 |
53 | 54 |
|
|
76 | 77 | DestinationPath = str | PathLike[str] |
77 | 78 |
|
78 | 79 |
|
| 80 | +def _default_timeout() -> httpx.Timeout: |
| 81 | + return httpx.Timeout( |
| 82 | + timeout=DEFAULT_GENERAL_TIMEOUT_SECONDS, |
| 83 | + read=DEFAULT_READ_TIMEOUT_SECONDS, |
| 84 | + ) |
| 85 | + |
| 86 | + |
79 | 87 | def _extract_uploaded_file_ids(payload: Any) -> list[str]: |
80 | 88 | try: |
81 | 89 | files_payload = payload["files"] |
@@ -230,7 +238,7 @@ class _ClientConfig(BaseModel): |
230 | 238 |
|
231 | 239 | base_url: URL |
232 | 240 | api_key: str | None = None |
233 | | - timeout: TimeoutTypes = DEFAULT_TIMEOUT_SECONDS |
| 241 | + timeout: TimeoutTypes = Field(default_factory=_default_timeout) |
234 | 242 | headers: dict[str, str] = Field(default_factory=dict) |
235 | 243 |
|
236 | 244 | model_config = ConfigDict(arbitrary_types_allowed=True) |
@@ -273,7 +281,7 @@ def _validate_headers(cls, value: Any) -> dict[str, str]: |
273 | 281 | @classmethod |
274 | 282 | def _validate_timeout(cls, value: Any) -> TimeoutTypes: |
275 | 283 | if value is None: |
276 | | - return DEFAULT_TIMEOUT_SECONDS |
| 284 | + return _default_timeout() |
277 | 285 | if isinstance(value, (int, float)): |
278 | 286 | return float(value) |
279 | 287 | if isinstance(value, httpx.Timeout): |
@@ -317,7 +325,7 @@ def __init__( |
317 | 325 | *, |
318 | 326 | api_key: str | None = None, |
319 | 327 | base_url: str | URL | None = None, |
320 | | - timeout: TimeoutTypes = DEFAULT_TIMEOUT_SECONDS, |
| 328 | + timeout: TimeoutTypes | None = None, |
321 | 329 | headers: AnyMapping | None = None, |
322 | 330 | ) -> None: |
323 | 331 | raw_api_key = api_key if api_key is not None else os.getenv(API_KEY_ENV_VAR) |
@@ -357,7 +365,7 @@ def __init__( |
357 | 365 | self._config = _ClientConfig( |
358 | 366 | base_url=resolved_base_url, |
359 | 367 | api_key=resolved_api_key, |
360 | | - timeout=timeout, |
| 368 | + timeout=timeout if timeout is not None else _default_timeout(), |
361 | 369 | headers=default_headers, |
362 | 370 | ) |
363 | 371 | except PdfRestConfigurationError: |
@@ -541,7 +549,7 @@ def __init__( |
541 | 549 | *, |
542 | 550 | api_key: str | None = None, |
543 | 551 | base_url: str | URL | None = None, |
544 | | - timeout: TimeoutTypes = DEFAULT_TIMEOUT_SECONDS, |
| 552 | + timeout: TimeoutTypes | None = None, |
545 | 553 | headers: AnyMapping | None = None, |
546 | 554 | http_client: httpx.Client | None = None, |
547 | 555 | transport: httpx.BaseTransport | None = None, |
@@ -659,7 +667,7 @@ def __init__( |
659 | 667 | *, |
660 | 668 | api_key: str | None = None, |
661 | 669 | base_url: str | URL | None = None, |
662 | | - timeout: TimeoutTypes = DEFAULT_TIMEOUT_SECONDS, |
| 670 | + timeout: TimeoutTypes | None = None, |
663 | 671 | headers: AnyMapping | None = None, |
664 | 672 | http_client: httpx.AsyncClient | None = None, |
665 | 673 | transport: httpx.AsyncBaseTransport | None = None, |
@@ -1309,7 +1317,7 @@ def __init__( |
1309 | 1317 | *, |
1310 | 1318 | api_key: str | None = None, |
1311 | 1319 | base_url: str | URL | None = None, |
1312 | | - timeout: TimeoutTypes = DEFAULT_TIMEOUT_SECONDS, |
| 1320 | + timeout: TimeoutTypes | None = None, |
1313 | 1321 | headers: AnyMapping | None = None, |
1314 | 1322 | http_client: httpx.Client | None = None, |
1315 | 1323 | transport: httpx.BaseTransport | None = None, |
@@ -1617,7 +1625,7 @@ def __init__( |
1617 | 1625 | *, |
1618 | 1626 | api_key: str | None = None, |
1619 | 1627 | base_url: str | URL | None = None, |
1620 | | - timeout: TimeoutTypes = DEFAULT_TIMEOUT_SECONDS, |
| 1628 | + timeout: TimeoutTypes | None = None, |
1621 | 1629 | headers: AnyMapping | None = None, |
1622 | 1630 | http_client: httpx.AsyncClient | None = None, |
1623 | 1631 | transport: httpx.AsyncBaseTransport | None = None, |
|
0 commit comments