Ticket #13476: 13476-better.patch

File 13476-better.patch, 1.6 KB (added by buriy, 5 years ago)

Better patch

  • django/core/management/color.py

    diff --git a/django/core/management/color.py b/django/core/management/color.py
    index 8c7a87f..b8bc652 100644
    a b import sys 
    77
    88from django.utils import termcolors
    99
     10console_stdout = sys.stdout
     11console_stderr = sys.stderr
     12
     13def 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
    1031def supports_color():
    1132    """
    1233    Returns True if the running system's terminal supports color, and False
    1334    otherwise.
    1435    """
    1536    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
    1644    # isatty is not always implemented, #6223.
    1745    is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
    1846    if unsupported_platform or not is_a_tty:
Back to Top