Django

Code

Changeset 7202

Show
Ignore:
Timestamp:
03/07/08 21:12:27 (9 months ago)
Author:
gwilson
Message:

Fixed #6223 -- When determining if terminal supports color, don't call isatty if it doesn't exist, thanks mamadou.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management/color.py

    r6478 r7202  
    77from django.utils import termcolors 
    88 
     9def supports_color(): 
     10    """ 
     11    Returns True if the running system's terminal supports color, and False 
     12    otherwise. 
     13    """ 
     14    unsupported_platform = (sys.platform in ('win32', 'Pocket PC') 
     15                            or sys.platform.startswith('java')) 
     16    # isatty is not always implemented, #6223. 
     17    is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() 
     18    if unsupported_platform or not is_a_tty: 
     19        return False 
     20    return True 
     21 
    922def color_style(): 
    1023    """Returns a Style object with the Django color scheme.""" 
    11     if (sys.platform == 'win32' or sys.platform == 'Pocket PC' 
    12         or sys.platform.startswith('java') or not sys.stdout.isatty()): 
     24    if not supports_color(): 
    1325        return no_style() 
    1426    class dummy: pass