Skip to content
Myr

pass bytes unstyled from secho to echo

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

authored by David Lord · committed by David Lord · parent 1516dc6 · Browse files · 2 files+20 added−7 removed
This commit

State

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

Diff stats

2 files+20 added−7 removed

  • tests:+10 added−5 removed
  • other:+10 added−2 removed

2 files+20 added−7 removed

modified:src/click/termui.py+10 added-2 removed
5 unmodified lines
6import sys78from ._compat import DEFAULT_COLUMNS9from ._compat import get_winterm_size10from ._compat import is_bytes11from ._compat import isatty12from ._compat import strip_ansi13from ._compat import WIN14from .exceptions import Abort
542 unmodified lines
557558 All keyword arguments are forwarded to the underlying functions559 depending on which one they go with.560561 Non-string types will be converted to :class:`str`. However,562 :class:`bytes` are passed directly to :meth:`echo` without applying563 style. If you want to style bytes that represent text, call564 :meth:`bytes.decode` first.565566 .. versionchanged:: 8.0561 A non-string ``message`` is converted to a string.567 A non-string ``message`` is converted to a string. Bytes are568 passed through without style applied.569570 .. versionadded:: 2.0571 """565 if message is not None:572 if message is not None and not is_bytes(message):573 message = style(message, **styles)574575 return echo(message, file=file, nl=nl, err=err, color=color)576577578def edit(
130 unmodified lines
modified:tests/test_termui.py+10 added-5 removed
1import platform2import time34import pytest5
251 unmodified lines
257 bytes = outstreams[0].getvalue()258 assert bytes == b""259260260def test_secho_non_text(runner):261 with runner.isolation() as outstreams:262 click.secho(Exception("spam"), nl=False)263 bytes = outstreams[0].getvalue()264 assert bytes == b"spam"261@pytest.mark.skipif(platform.system() == "Windows", reason="No style on Windows.")262@pytest.mark.parametrize(263 ("value", "expect"), [(123, b"\x1b[45m123\x1b[0m"), (b"test", b"test")]264)265def test_secho_non_text(runner, value, expect):266 with runner.isolation() as (out, _):267 click.secho(value, nl=False, color=True, bg="magenta")268 result = out.getvalue()269 assert result == expect270271272def test_progressbar_yields_all_items(runner):273 with click.progressbar(range(3)) as progress:
108 unmodified lines