#NEWLINE# def simple_response( self , status , msg = '' ) : #NEWLINE# #INDENT# 'Write a simple response back to the client.' #NEWLINE# status = str ( status ) #NEWLINE# buf = [ ( ( ( bytes ( self . server . protocol , 'ascii' ) + SPACE ) + bytes ( status , 'ISO-8859-1' ) ) + CRLF ) , bytes ( ( 'Content-Length: %s\r\n' % len ( status ) ) , 'ISO-8859-1' ) , b'Content-Type: text/plain\r\n' ] #NEWLINE# if ( status [ : 3 ] in ( '413' , '414' ) ) : #NEWLINE# #INDENT# self . close_connection = True #NEWLINE# if ( self . response_protocol == 'HTTP/1.1' ) : #NEWLINE# #INDENT# buf . append ( b'Connection: close\r\n' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# status = '400 Bad Request' #NEWLINE# #UNINDENT# #UNINDENT# buf . append ( CRLF ) #NEWLINE# if msg : #NEWLINE# #INDENT# if isinstance ( msg , unicodestr ) : #NEWLINE# #INDENT# msg = msg . encode ( 'ISO-8859-1' ) #NEWLINE# #UNINDENT# buf . append ( msg ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . conn . wfile . write ( b'' . join ( buf ) ) #NEWLINE# #UNINDENT# except socket . error : #NEWLINE# #INDENT# x = sys . exc_info ( ) [ 1 ] #NEWLINE# if ( x . args [ 0 ] not in socket_errors_to_ignore ) : #NEWLINE# #INDENT# raise