Ticket #13476: 13476-concept.patch

File 13476-concept.patch, 1.1 KB (added by Yuri Baburov, 15 years ago)

I attached a patch to prove it's working. Though, accurate patch should not attempt to mangle sys.stdout and sys.stderr but add everywhere a variable pointing to the right console handle instead.

  • django/core/management/color.py

    diff --git a/django/core/management/color.py b/django/core/management/color.py
    index 8c7a87f..ec63b11 100644
    a b import sys  
    77
    88from django.utils import termcolors
    99
     10console_handle = sys.stdout
     11
     12def patch_console():
     13    try:
     14        global console_handle
     15        from pyreadline import console as _console
     16        console_handle = _console.Console()
     17        console_handle.closed = False
     18        sys.stdout = console_handle
     19        sys.stderr = console_handle
     20        return True
     21    except ImportError:
     22        return False
     23
    1024def supports_color():
    1125    """
    1226    Returns True if the running system's terminal supports color, and False
    1327    otherwise.
    1428    """
    1529    unsupported_platform = (sys.platform in ('win32', 'Pocket PC'))
     30    if type(sys.stdout) is file:
     31        if patch_console():
     32            unsupported_platform = False
     33    else:
     34        unsupported_platform = False
    1635    # isatty is not always implemented, #6223.
    1736    is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
    1837    if unsupported_platform or not is_a_tty:
Back to Top