(url: str, timeout: float)
| 299 | |
| 300 | |
| 301 | def request_remote_image(url: str, timeout: float) -> str | None: |
| 302 | fallback_codes = {403, 405, 501} |
| 303 | try: |
| 304 | return fetch_remote_image(url, timeout=timeout, method="HEAD") |
| 305 | except HTTPError as error: |
| 306 | if error.code not in fallback_codes: |
| 307 | return f"remote image returned HTTP {error.code}" |
| 308 | except (TimeoutError, URLError, OSError, ValueError) as error: |
| 309 | return remote_error_message(error) |
| 310 | |
| 311 | try: |
| 312 | return fetch_remote_image(url, timeout=timeout, method="GET") |
| 313 | except HTTPError as error: |
| 314 | return f"remote image returned HTTP {error.code}" |
| 315 | except (TimeoutError, URLError, OSError, ValueError) as error: |
| 316 | return remote_error_message(error) |
| 317 | |
| 318 | |
| 319 | def fetch_remote_image(url: str, *, timeout: float, method: str) -> str | None: |
no test coverage detected