Skip to content

Commit

Permalink
Merge pull request #198 from Delgan/fix_196
Browse files Browse the repository at this point in the history
Prevent exponential number of calls while accessing "closed" / "isatty" (#196)
  • Loading branch information
wiggin15 authored Nov 3, 2018
2 parents c11da6f + 510bb8b commit 90f2fac
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions colorama/ansitowin32.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@ def isatty(self):
if 'PYCHARM_HOSTED' in os.environ:
if stream is not None and (stream is sys.__stdout__ or stream is sys.__stderr__):
return True
return (hasattr(stream, 'isatty') and stream.isatty())
try:
stream_isatty = stream.isatty
except AttributeError:
return False
else:
return stream_isatty()

@property
def closed(self):
stream = self.__wrapped
return not hasattr(stream, 'closed') or stream.closed
try:
return stream.closed
except AttributeError:
return True


class AnsiToWin32(object):
Expand Down

0 comments on commit 90f2fac

Please sign in to comment.