From f6341deca6d9d275edcf15854948d3be0bfeffc4 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 14 Sep 2021 20:41:30 +0100 Subject: [PATCH 1/4] fix for markup escaping in progress --- httpx/_main.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/httpx/_main.py b/httpx/_main.py index 6c299ba050..39fc746ef3 100644 --- a/httpx/_main.py +++ b/httpx/_main.py @@ -7,8 +7,11 @@ 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 @@ -172,12 +175,7 @@ def print_response(response: Response) -> 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) - 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}%", @@ -185,8 +183,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) From 6de69bc435309c34dc08ae3e088639bf6f1277ed Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 14 Sep 2021 20:42:52 +0100 Subject: [PATCH 2/4] whitespace --- httpx/_main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/httpx/_main.py b/httpx/_main.py index 39fc746ef3..4a986694d7 100644 --- a/httpx/_main.py +++ b/httpx/_main.py @@ -12,7 +12,6 @@ import rich.syntax import rich.table - from ._client import Client from ._exceptions import RequestError from ._models import Request, Response From 24d9bc94e8ee30de126473dd5c8805f37bd84b74 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 14 Sep 2021 20:57:00 +0100 Subject: [PATCH 3/4] restore new line --- httpx/_main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/httpx/_main.py b/httpx/_main.py index 4a986694d7..b04e505950 100644 --- a/httpx/_main.py +++ b/httpx/_main.py @@ -174,6 +174,8 @@ def print_response(response: Response) -> None: def download_response(response: Response, download: typing.BinaryIO) -> None: + console = rich.console.Console() + console.print() content_length = response.headers.get("Content-Length") with rich.progress.Progress( "[progress.description]{task.description}", From 973d1ed4e06577d928061092affe8f94def03331 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 4 Feb 2022 12:14:57 +0000 Subject: [PATCH 4/4] Update _main.py --- httpx/_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpx/_main.py b/httpx/_main.py index fe0281ab8b..24ca30ddfc 100644 --- a/httpx/_main.py +++ b/httpx/_main.py @@ -175,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