import pygments.lexers
import pygments.util
import rich.console
+import rich.markup
import rich.progress
import rich.syntax
+import rich.table
from ._client import Client
from ._exceptions import RequestError
syntax = rich.syntax.Syntax(text, lexer_name, theme="ansi_dark", word_wrap=True)
console.print(syntax)
else: # pragma: nocover
- console.print(response.text)
+ console.print(rich.markup.escape(response.text))
def format_certificate(cert: dict) -> str: # pragma: nocover
def download_response(response: Response, download: typing.BinaryIO) -> None:
console = rich.console.Console()
- syntax = rich.syntax.Syntax("", "http", theme="ansi_dark", word_wrap=True)
- console.print(syntax)
-
+ console.print()
content_length = response.headers.get("Content-Length")
- kwargs = {"total": int(content_length)} if content_length else {}
with rich.progress.Progress(
"[progress.description]{task.description}",
"[progress.percentage]{task.percentage:>3.0f}%",
rich.progress.DownloadColumn(),
rich.progress.TransferSpeedColumn(),
) as progress:
- description = f"Downloading [bold]{download.name}"
- download_task = progress.add_task(description, **kwargs) # type: ignore
+ description = f"Downloading [bold]{rich.markup.escape(download.name)}"
+ download_task = progress.add_task(
+ description,
+ total=int(content_length or 0),
+ start=content_length is not None,
+ )
for chunk in response.iter_bytes():
download.write(chunk)
progress.update(download_task, completed=response.num_bytes_downloaded)