diff --git a/django/core/management/color.py b/django/core/management/color.py
index 8c7a87f..b8bc652 100644
a
|
b
|
import sys
|
7 | 7 | |
8 | 8 | from django.utils import termcolors |
9 | 9 | |
| 10 | console_stdout = sys.stdout |
| 11 | console_stderr = sys.stderr |
| 12 | |
| 13 | def pyreadline_console_patch(): |
| 14 | try: |
| 15 | import pyreadline |
| 16 | global console_stdout |
| 17 | global console_stderr |
| 18 | # isatty is not always implemented, #6223. |
| 19 | if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty(): |
| 20 | console_stdout = sys.stdout |
| 21 | sys.stdout = pyreadline.console.Console() |
| 22 | sys.stdout.closed = False |
| 23 | if hasattr(sys.stderr, 'isatty') and sys.stderr.isatty(): |
| 24 | console_stderr = sys.stderr |
| 25 | sys.stderr = pyreadline.console.Console() |
| 26 | sys.stderr.closed = False |
| 27 | return True |
| 28 | except ImportError: |
| 29 | return False |
| 30 | |
10 | 31 | def supports_color(): |
11 | 32 | """ |
12 | 33 | Returns True if the running system's terminal supports color, and False |
13 | 34 | otherwise. |
14 | 35 | """ |
15 | 36 | unsupported_platform = (sys.platform in ('win32', 'Pocket PC')) |
| 37 | |
| 38 | if unsupported_platform: |
| 39 | if type(sys.stdout) is file: # if console is not patched yet |
| 40 | if pyreadline_console_patch(): |
| 41 | unsupported_platform = False |
| 42 | else: |
| 43 | unsupported_platform = False |
16 | 44 | # isatty is not always implemented, #6223. |
17 | 45 | is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() |
18 | 46 | if unsupported_platform or not is_a_tty: |