← Back to team overview

sts-sponsors team mailing list archive

Re: [Merge] ~alexsander-souza/maas:colorama_strikes_back into maas:master

 

I wonder if we can make this much simpler? Suggestion below

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

return sys.__stdout__ ?

> +    # 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
> +    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