tartley / colorama

Simple cross-platform colored terminal text in Python
BSD 3-Clause "New" or "Revised" License
3.56k stars 253 forks source link

Adjust exception handling in `isatty()` #304

Open carltongibson opened 3 years ago

carltongibson commented 3 years ago

Hi. Thanks for the great work!

We had an issue reported on Django, where colorama.init() was triggering an error with mod_wsgi.

On the mod_wsgi issue Graham Dumpleton pointed out that the colorama isatty() check is only handling AttributeError where we have an OSError (and feasibly a ValueError could be raised too.)

Opening this just to put on your radar that widening the except clause in isatty() may be valuable.

Thanks again. Kind Regards,

Carlton

carltongibson commented 3 years ago

Just a quick follow-up: I'm struggling to nest the colorama.init() call without it stopping working so ideally it wouldn't raise.

This bit from the readme isn't quite true currently:

On other platforms, calling init() has no effect ... By design, this permits applications to call init() unconditionally on all platforms, after which ANSI output should just work.

We can catch the exception at the top layer, so it's not fatal.