Download a URL to a temporary file, preserving the extension. Returns (temp_path, extension).
(url: str)
| 59 | |
| 60 | |
| 61 | def _download_to_temp(url: str) -> tuple[str, str]: |
| 62 | """Download a URL to a temporary file, preserving the extension. |
| 63 | |
| 64 | Returns (temp_path, extension). |
| 65 | """ |
| 66 | ext = _get_extension(url) |
| 67 | # Strip any query params from extension |
| 68 | if "?" in ext: |
| 69 | ext = ext[: ext.index("?")] |
| 70 | |
| 71 | fd, temp_path = tempfile.mkstemp(suffix=ext, prefix="fastled_decode_") |
| 72 | os.close(fd) |
| 73 | |
| 74 | print(f" Downloading {url} ...") |
| 75 | try: |
| 76 | urllib.request.urlretrieve(url, temp_path) # noqa: S310 |
| 77 | except KeyboardInterrupt as ki: |
| 78 | os.unlink(temp_path) |
| 79 | from ci.util.global_interrupt_handler import handle_keyboard_interrupt |
| 80 | |
| 81 | handle_keyboard_interrupt(ki) |
| 82 | except Exception as e: |
| 83 | os.unlink(temp_path) |
| 84 | raise RuntimeError(f"Failed to download {url}: {e}") from e |
| 85 | |
| 86 | size = os.path.getsize(temp_path) |
| 87 | print(f" Downloaded {size:,} bytes to {temp_path}") |
| 88 | return temp_path, ext |
| 89 | |
| 90 | |
| 91 | def _build_jsonrpc_payload(file_bytes: bytes, extension: str) -> str: |
no test coverage detected