Skip to content
Myr

Fix console markup escaping issue (#1866)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix for markup escaping in progress * whitespace * restore new line * Update _main.py

authored by Will McGugan · committed by GitHub · parent 2146c75 · Browse files · 1 file+10 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Tom Christie <tom@tomchristie.com>
  • Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

Diff stats

1 file+10 added−7 removed

  • other:+10 added−7 removed

1 file+10 added−7 removed

modified:httpx/_main.py+10 added-7 removed
6 unmodified lines
7import httpcore8import pygments.lexers9import pygments.util10import rich.console11import rich.markup12import rich.progress13import rich.syntax14import rich.table1516from ._client import Client17from ._exceptions import RequestError18from ._models import Response
155 unmodified lines
174 text = response.text175 syntax = rich.syntax.Syntax(text, lexer_name, theme="ansi_dark", word_wrap=True)176 console.print(syntax)177 else: # pragma: nocover176 console.print(response.text)178 console.print(rich.markup.escape(response.text))179180181def format_certificate(cert: dict) -> str: # pragma: nocover182 lines = []
51 unmodified lines
234235236def download_response(response: Response, download: typing.BinaryIO) -> None:237 console = rich.console.Console()236 syntax = rich.syntax.Syntax("", "http", theme="ansi_dark", word_wrap=True)237 console.print(syntax)238 console.print()238239 content_length = response.headers.get("Content-Length")240 kwargs = {"total": int(content_length)} if content_length else {}240 with rich.progress.Progress(241 "[progress.description]{task.description}",242 "[progress.percentage]{task.percentage:>3.0f}%",243 rich.progress.BarColumn(bar_width=None),244 rich.progress.DownloadColumn(),245 rich.progress.TransferSpeedColumn(),246 ) as progress:248 description = f"Downloading [bold]{download.name}"249 download_task = progress.add_task(description, **kwargs) # type: ignore247 description = f"Downloading [bold]{rich.markup.escape(download.name)}"248 download_task = progress.add_task(249 description,250 total=int(content_length or 0),251 start=content_length is not None,252 )253 for chunk in response.iter_bytes():254 download.write(chunk)255 progress.update(download_task, completed=response.num_bytes_downloaded)256
240 unmodified lines