Check for existence of isatty on stdout before calling it

The standard library documentation [states that](http://docs.python.org/2/library/stdtypes.html#file.isatty) file-like objects that are not associated with a real file should not implement the isatty method, so its existence has to be verified before trying to call it.

An example of an environment where this is an issue is WSGI, where the standard output gets replaced by WSGI's own logging object, which lacks an isatty method.