(response: Response, download: typing.BinaryIO)
| 249 | |
| 250 | |
| 251 | def download_response(response: Response, download: typing.BinaryIO) -> None: |
| 252 | console = rich.console.Console() |
| 253 | console.print() |
| 254 | content_length = response.headers.get(class="st">"Content-Length") |
| 255 | with rich.progress.Progress( |
| 256 | class="st">"[progress.description]{task.description}", |
| 257 | class="st">"[progress.percentage]{task.percentage:>3.0f}%", |
| 258 | rich.progress.BarColumn(bar_width=None), |
| 259 | rich.progress.DownloadColumn(), |
| 260 | rich.progress.TransferSpeedColumn(), |
| 261 | ) as progress: |
| 262 | description = fclass="st">"Downloading [bold]{rich.markup.escape(download.name)}" |
| 263 | download_task = progress.add_task( |
| 264 | description, |
| 265 | total=int(content_length or 0), |
| 266 | start=content_length is not None, |
| 267 | ) |
| 268 | for chunk in response.iter_bytes(): |
| 269 | download.write(chunk) |
| 270 | progress.update(download_task, completed=response.num_bytes_downloaded) |
| 271 | |
| 272 | |
| 273 | def validate_json( |
no test coverage detected