Handle non text in style/secho by converting to text#1146
Handle non text in style/secho by converting to text#1146davidism merged 2 commits intopallets:masterfrom
Conversation
|
Within That said, I did try an implementation for decoding bytes passed to from ._compat import get_best_encoding
# extracted from echo for use in secho as well
def _get_echo_file(file, err):
if file is not None:
return file
if err:
return _default_text_stderr()
else:
return _default_text_stdout()
def secho(message, file=None, err=False, ...):
file = _get_echo_file(file, err)
if message is not None:
if is_bytes(message):
file = _get_echo_file(file, err)
encoding = get_best_encoding(file)
message = message.decode(encoding)
elif not isinstance(message, str):
message = str(message)
message = style(message, **styles)
return echo(message, file=file, err=err, ...)This isn't completely correct, it doesn't pull out the |
|
I don't think this addresses #944, that seems to be about allowing |
ea0b98f to
35bcb72
Compare
35bcb72 to
1516dc6
Compare
|
I guess we could also do |
4e18052 to
353dd89
Compare
Call
str()on any non-string type.echo()also supports printingbytes, but this PR doesn't support that, ending up printing its repr (b'bytes'). I'm not sure how to handle it, since makingstyle()support bytes might be rather ugly.