Opened 9 years ago

Closed 9 years ago

#6223 closed (fixed)

Do not call isatty if it doesn't exist

Reported by: mamadou <tobutaz+django@…> Owned by: Gary Wilson
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In source:django/trunk/django/core/management/color.py

    if (sys.platform == 'win32' or sys.platform == 'Pocket PC'
        or sys.platform.startswith('java') or not sys.stdout.isatty()):

Should be replaced by:

    if not (hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()):

Because according to the python docs, isatty isn't mandatory to implement.

In practice, isatty isn't implemented when importing django classes from a twistd daemon, hence a crash.

Attachments (3)

6223.diff (693 bytes) - added by Gary Wilson 9 years ago.
6223.2.diff (583 bytes) - added by Gary Wilson 9 years ago.
6223.3.diff (612 bytes) - added by Gary Wilson 9 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 9 years ago by Gary Wilson

Triage Stage: UnreviewedAccepted

It seems the java check can be removed because it was added due to Jython not having the isatty method (#5319). It appears that the Windows check was added for the same reason (#1762), but I've got a Windows XP machine here with Python 2.4 that does have an isatty method which returns True. Does Windows support terminal colors? If not, then the win32 check needs to stay.

Changed 9 years ago by Gary Wilson

Attachment: 6223.diff added

comment:2 Changed 9 years ago by Gary Wilson

Has patch: set

comment:3 Changed 9 years ago by mamadou <tobutaz+django@…>

Owner: changed from nobody to Gary Wilson

Patch is good, I'm using it on django trunk, don't let it bitrot.

Changed 9 years ago by Gary Wilson

Attachment: 6223.2.diff added

Changed 9 years ago by Gary Wilson

Attachment: 6223.3.diff added

comment:4 Changed 9 years ago by Gary Wilson

Resolution: fixed
Status: newclosed

(In [7202]) Fixed #6223 -- When determining if terminal supports color, don't call isatty if it doesn't exist, thanks mamadou.

Note: See TracTickets for help on using tickets.
Back to Top