MCPcopy Create free account
hub / github.com/FastLED/FastLED / _download_to_temp

Function _download_to_temp

ci/autoresearch/decode.py:61–88  ·  view source on GitHub ↗

Download a URL to a temporary file, preserving the extension. Returns (temp_path, extension).

(url: str)

Source from the content-addressed store, hash-verified

59
60
61def _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
91def _build_jsonrpc_payload(file_bytes: bytes, extension: str) -> str:

Callers 1

_resolve_fileFunction · 0.85

Calls 5

_get_extensionFunction · 0.85
unlinkMethod · 0.80
printFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected