Skip to content

Commit

Permalink
Prevent user from wrapping already wrapped streams
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchy committed Oct 23, 2018
1 parent c11da6f commit ad2a750
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions colorama/initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ def init(autoreset=False, convert=None, strip=None, wrap=True):
global wrapped_stdout, wrapped_stderr
global orig_stdout, orig_stderr

orig_stdout = sys.stdout
orig_stderr = sys.stderr

if sys.stdout is None:
wrapped_stdout = None
else:
sys.stdout = wrapped_stdout = \
wrap_stream(orig_stdout, convert, strip, autoreset, wrap)
if sys.stderr is None:
wrapped_stderr = None
else:
sys.stderr = wrapped_stderr = \
wrap_stream(orig_stderr, convert, strip, autoreset, wrap)
if orig_stdout is None:
orig_stdout = sys.stdout

if sys.stdout is None:
wrapped_stdout = None
else:
sys.stdout = wrapped_stdout = \
wrap_stream(orig_stdout, convert, strip, autoreset, wrap)

if orig_stderr is None:
orig_stderr = sys.stderr

if sys.stderr is None:
wrapped_stderr = None
else:
sys.stderr = wrapped_stderr = \
wrap_stream(orig_stderr, convert, strip, autoreset, wrap)

global atexit_done
if not atexit_done:
Expand Down

0 comments on commit ad2a750

Please sign in to comment.