#NEWLINE# def communicate( self ) : #NEWLINE# #INDENT# 'Read each request and respond appropriately.' #NEWLINE# request_seen = False #NEWLINE# try : #NEWLINE# #INDENT# while True : #NEWLINE# #INDENT# req = None #NEWLINE# req = self . RequestHandlerClass ( self . server , self ) #NEWLINE# req . parse_request ( ) #NEWLINE# if self . server . stats [ 'Enabled' ] : #NEWLINE# #INDENT# self . requests_seen += 1 #NEWLINE# #UNINDENT# if ( not req . ready ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# request_seen = True #NEWLINE# req . respond ( ) #NEWLINE# if req . close_connection : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except socket . error : #NEWLINE# #INDENT# e = sys . exc_info ( ) [ 1 ] #NEWLINE# errnum = e . args [ 0 ] #NEWLINE# if ( ( errnum == 'timed out' ) or ( errnum == 'The read operation timed out' ) ) : #NEWLINE# #INDENT# if ( ( not request_seen ) or ( req and req . started_request ) ) : #NEWLINE# #INDENT# if ( req and ( not req . sent_headers ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# req . simple_response ( '408 Request Timeout' ) #NEWLINE# #UNINDENT# except FatalSSLAlert : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( errnum not in socket_errors_to_ignore ) : #NEWLINE# #INDENT# self . server . error_log ( ( 'socket.error %s' % repr ( errnum ) ) , level = logging . WARNING , traceback = True ) #NEWLINE# if ( req and ( not req . sent_headers ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# req . simple_response ( '500 Internal Server Error' ) #NEWLINE# #UNINDENT# except FatalSSLAlert : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return #NEWLINE# #UNINDENT# except ( KeyboardInterrupt , SystemExit ) : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# except FatalSSLAlert : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# except NoSSLError : #NEWLINE# #INDENT# if ( req and ( not req . sent_headers ) ) : #NEWLINE# #INDENT# self . wfile = CP_makefile ( self . socket . _sock , 'wb' , self . wbufsize ) #NEWLINE# req . simple_response ( '400 Bad Request' , 'The client sent a plain HTTP request, but this server only speaks HTTPS on this port.' ) #NEWLINE# self . linger = True #NEWLINE# #UNINDENT# #UNINDENT# except Exception : #NEWLINE# #INDENT# e = sys . exc_info ( ) [ 1 ] #NEWLINE# self . server . error_log ( repr ( e ) , level = logging . ERROR , traceback = True ) #NEWLINE# if ( req and ( not req . sent_headers ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# req . simple_response ( '500 Internal Server Error' ) #NEWLINE# #UNINDENT# except FatalSSLAlert : #NEWLINE# #INDENT# return