Ticket #6385: colorize.diff

File colorize.diff, 2.1 KB (added by Rob Hudson <treborhudson@…>, 17 years ago)

Add HTTP colors to runserver output

  • django/core/servers/basehttp.py

     
    66This is a simple server for use in testing or debugging Django apps. It hasn't
    77been reviewed for security issues. Don't use it for production use.
    88"""
    9 
     9from django.core.management.color import color_style
    1010from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
    1111import mimetypes
    1212import os
     
    443443
    444444    def close(self):
    445445        try:
    446             self.request_handler.log_request(self.status.split(' ',1)[0], self.bytes_sent)
     446            style = color_style()
     447            status_code = self.status.split(' ',1)[0]
     448            if status_code.startswith('2'):
     449                status_code = style.SUCCESS(status_code)
     450            elif status_code.startswith('3'):
     451                status_code = style.REDIRECT(status_code)
     452            elif status_code.startswith('4'):
     453                status_code = style.CLIENT_ERROR(status_code)
     454            elif status_code.startswith('5'):
     455                status_code = style.SERVER_ERROR(status_code)
     456            self.request_handler.log_request(status_code, self.bytes_sent)
    447457        finally:
    448458            try:
    449459                if hasattr(self.result,'close'):
  • django/core/management/color.py

     
    2020    style.SQL_COLTYPE = termcolors.make_style(fg='green')
    2121    style.SQL_KEYWORD = termcolors.make_style(fg='yellow')
    2222    style.SQL_TABLE = termcolors.make_style(opts=('bold',))
     23    # HTTP STATUS CODES
     24    style.SUCCESS = termcolors.make_style(fg='green', opts=('bold',)) # 2xx
     25    style.REDIRECT = termcolors.make_style(fg='blue', opts=('bold',)) # 3xx
     26    style.CLIENT_ERROR = termcolors.make_style(fg='yellow', opts=('bold',)) # 4xx
     27    style.SERVER_ERROR = termcolors.make_style(fg='red', opts=('bold',)) # 5xx
    2328    return style
    2429
    2530def no_style():
Back to Top