From: Will McGugan Date: Fri, 4 Feb 2022 12:33:32 +0000 (+0000) Subject: Fix console markup escaping issue (#1866) X-Git-Tag: 0.23.0~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2814fd379c4738d402e57f9560194b42adee8ebf;p=thirdparty%2Fhttpx.git Fix console markup escaping issue (#1866) * fix for markup escaping in progress * whitespace * restore new line * Update _main.py Co-authored-by: Tom Christie Co-authored-by: Marcelo Trylesinski --- diff --git a/httpx/_main.py b/httpx/_main.py index 237875a0..24ca30dd 100644 --- a/httpx/_main.py +++ b/httpx/_main.py @@ -8,8 +8,10 @@ import httpcore 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 @@ -173,7 +175,7 @@ def print_response(response: Response) -> None: 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 @@ -233,11 +235,8 @@ def trace(name: str, info: dict, verbose: bool = False) -> None: 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}%", @@ -245,8 +244,12 @@ def download_response(response: Response, download: typing.BinaryIO) -> None: 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)