<s> import os <EOL> import django <EOL> import sys <EOL> from optparse import make_option <EOL> from django . conf import settings <EOL> from django . core . handlers . wsgi import WSGIHandler <EOL> from django . core . servers . basehttp import run , WSGIServerException <EOL> from django . core . management . base import BaseCommand , CommandError <EOL> from staticfiles . handlers import StaticFilesHandler <EOL> try : <EOL> from django . contrib . staticfiles . management . commands . runserver import Command as RunserverCommand <EOL> class Command ( RunserverCommand ) : <EOL> """<STR_LIT>""" <EOL> def get_handler ( self , * args , ** options ) : <EOL> """<STR_LIT>""" <EOL> handler = WSGIHandler ( ) <EOL> use_static_handler = options . get ( '<STR_LIT>' , True ) <EOL> insecure_serving = options . get ( '<STR_LIT>' , False ) <EOL> if use_static_handler and ( settings . DEBUG or insecure_serving ) : <EOL> handler = StaticFilesHandler ( handler ) <EOL> return handler <EOL> except ImportError : <EOL> class Command ( BaseCommand ) : <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , <EOL> action = '<STR_LIT>' , dest = '<STR_LIT>' , default = True , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , <EOL> action = "<STR_LIT>" , dest = '<STR_LIT>' , default = True , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , <EOL> action = "<STR_LIT:store_true>" , dest = '<STR_LIT>' , default = False , <EOL> help = '<STR_LIT>' ) , <EOL> ) <EOL> help = "<STR_LIT>" <EOL> args = '<STR_LIT>' <EOL> def get_handler ( self , * args , ** options ) : <EOL> """<STR_LIT>""" <EOL> handler = WSGIHandler ( ) <EOL> use_static_handler = options . get ( '<STR_LIT>' , True ) <EOL> insecure_serving = options . get ( '<STR_LIT>' , False ) <EOL> if use_static_handler and ( settings . DEBUG or insecure_serving ) : <EOL> handler = StaticFilesHandler ( handler ) <EOL> return handler <EOL> def handle ( self , addrport = '<STR_LIT>' , * args , ** options ) : <EOL> if args : <EOL> raise CommandError ( '<STR_LIT>' % self . args ) <EOL> if not addrport : <EOL> addr = '<STR_LIT>' <EOL> port = '<STR_LIT>' <EOL> else : <EOL> try : <EOL> addr , port = addrport . split ( '<STR_LIT::>' ) <EOL> except ValueError : <EOL> addr , port = '<STR_LIT>' , addrport <EOL> if not addr : <EOL> addr = '<STR_LIT:127.0.0.1>' <EOL> if not port . isdigit ( ) : <EOL> raise CommandError ( "<STR_LIT>" % port ) <EOL> use_reloader = options . get ( '<STR_LIT>' , True ) <EOL> shutdown_message = options . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> quit_command = ( sys . platform == '<STR_LIT:win32>' ) and '<STR_LIT>' or '<STR_LIT>' <EOL> def inner_run ( ) : <EOL> from django . conf import settings <EOL> from django . utils import translation <EOL> print "<STR_LIT>" <EOL> self . validate ( display_num_errors = True ) <EOL> print "<STR_LIT>" % ( django . get_version ( ) , settings . SETTINGS_MODULE ) <EOL> print "<STR_LIT>" % ( addr , port ) <EOL> print "<STR_LIT>" % quit_command <EOL> translation . activate ( settings . LANGUAGE_CODE ) <EOL> try : <EOL> handler = self . get_handler ( * args , ** options ) <EOL> run ( addr , int ( port ) , handler ) <EOL> except WSGIServerException , e : <EOL> ERRORS = { <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> } <EOL> try : <EOL> error_text = ERRORS [ e . args [ <NUM_LIT:0> ] . args [ <NUM_LIT:0> ] ] <EOL> except ( AttributeError , KeyError ) : <EOL> error_text = str ( e ) <EOL> sys . stderr . write ( self . style . ERROR ( "<STR_LIT>" % error_text ) + '<STR_LIT:\n>' ) <EOL> os . _exit ( <NUM_LIT:1> ) <EOL> except KeyboardInterrupt : <EOL> if shutdown_message : <EOL> print shutdown_message <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if use_reloader : <EOL> from django . utils import autoreload <EOL> autoreload . main ( inner_run ) <EOL> else : <EOL> inner_run ( ) </s>
