Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #6223 -- When determining if terminal supports color, don't cal…

…l `isatty` if it doesn't exist, thanks mamadou.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7202 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7fbebae8c8797fa7452466055b53c42d6b123811 1 parent a75e58b
Gary Wilson Jr. authored March 08, 2008

Showing 1 changed file with 14 additions and 2 deletions. Show diff stats Hide diff stats

  1. 16  django/core/management/color.py
16  django/core/management/color.py
@@ -6,10 +6,22 @@
6 6
 
7 7
 from django.utils import termcolors
8 8
 
  9
+def 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
+
9 22
 def color_style():
10 23
     """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():
13 25
         return no_style()
14 26
     class dummy: pass
15 27
     style = dummy()

0 notes on commit 7fbebae

Please sign in to comment.
Something went wrong with that request. Please try again.