Opened 16 years ago

Closed 16 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: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 16 years ago.
6223.2.diff (583 bytes ) - added by Gary Wilson 16 years ago.
6223.3.diff (612 bytes ) - added by Gary Wilson 16 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by Gary Wilson, 16 years ago

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.

by Gary Wilson, 16 years ago

Attachment: 6223.diff added

comment:2 by Gary Wilson, 16 years ago

Has patch: set

comment:3 by mamadou <tobutaz+django@…>, 16 years ago

Owner: changed from nobody to Gary Wilson

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

by Gary Wilson, 16 years ago

Attachment: 6223.2.diff added

by Gary Wilson, 16 years ago

Attachment: 6223.3.diff added

comment:4 by Gary Wilson, 16 years ago

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