sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #04007
Re: [Merge] ~alexsander-souza/maas:colorama_strikes_back into maas:master
Review: Approve
+1
Small nit inline
Diff comments:
> diff --git a/src/maascli/utils.py b/src/maascli/utils.py
> index f35e929..f38aa5b 100644
> --- a/src/maascli/utils.py
> +++ b/src/maascli/utils.py
> @@ -150,6 +150,22 @@ def print_response_headers(headers, file=None):
> print(form % (cap(header), headers[header]), file=file)
>
>
> +def get_orig_stdout(file):
> + # Get the underlying buffer if we're writing to stdout. This allows us to
> + # write bytes directly, without attempting to convert the bytes to unicode.
> + # Unicode output may not be desired; the HTTP response could be raw bytes.
> + try:
> + import colorama
> +
> + if isinstance(file, colorama.ansitowin32.StreamWrapper):
> + file = colorama.initialise.orig_stdout
> + except (ImportError, OSError):
> + pass
you can use contextlib.suppress here:
with suppress(ImportError, OSError):
import colorama
if isinstance(file, colorama.ansitowin32.StreamWrapper):
file = colorama.initialise.orig_stdout
> + if isinstance(file, io.TextIOWrapper):
> + file = file.buffer
> + return file
> +
> +
> def print_response_content(response, content, file=None):
> """Write the response's content to stdout.
>
--
https://code.launchpad.net/~alexsander-souza/maas/+git/maas/+merge/434386
Your team MAAS Committers is subscribed to branch maas:master.
References