~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to django/core/servers/basehttp.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
import sys
16
16
import urllib
17
17
 
 
18
from django.core.management.color import color_style
18
19
from django.utils.http import http_date
19
20
from django.utils._os import safe_join
20
21
 
529
530
        try:
530
531
            HTTPServer.server_bind(self)
531
532
        except Exception, e:
532
 
            raise WSGIServerException, e
 
533
            raise WSGIServerException(e)
533
534
        self.setup_environ()
534
535
 
535
536
    def setup_environ(self):
557
558
        # We set self.path to avoid crashes in log_message() on unsupported
558
559
        # requests (like "OPTIONS").
559
560
        self.path = ''
 
561
        self.style = color_style()
560
562
        BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
561
563
 
562
564
    def get_environ(self):
608
610
        # Don't bother logging requests for admin images or the favicon.
609
611
        if self.path.startswith(self.admin_media_prefix) or self.path == '/favicon.ico':
610
612
            return
611
 
        sys.stderr.write("[%s] %s\n" % (self.log_date_time_string(), format % args))
 
613
 
 
614
        msg = "[%s] %s\n" % (self.log_date_time_string(), format % args)
 
615
 
 
616
        # Utilize terminal colors, if available
 
617
        if args[1][0] == '2':
 
618
            # Put 2XX first, since it should be the common case
 
619
            msg = self.style.HTTP_SUCCESS(msg)
 
620
        elif args[1][0] == '1':
 
621
            msg = self.style.HTTP_INFO(msg)
 
622
        elif args[1] == '304':
 
623
            msg = self.style.HTTP_NOT_MODIFIED(msg)
 
624
        elif args[1][0] == '3':
 
625
            msg = self.style.HTTP_REDIRECT(msg)
 
626
        elif args[1] == '404':
 
627
            msg = self.style.HTTP_NOT_FOUND(msg)
 
628
        elif args[1][0] == '4':
 
629
            msg = self.style.HTTP_BAD_REQUEST(msg)
 
630
        else:
 
631
            # Any 5XX, or any other response
 
632
            msg = self.style.HTTP_SERVER_ERROR(msg)
 
633
 
 
634
        sys.stderr.write(msg)
612
635
 
613
636
class AdminMediaHandler(object):
614
637
    """