#NEWLINE# @ defunct_on_error #NEWLINE# def _handle_startup_response( self , startup_response , did_authenticate = False ) : #NEWLINE# #INDENT# if self . is_defunct : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if isinstance ( startup_response , ReadyMessage ) : #NEWLINE# #INDENT# log . debug ( 'Got ReadyMessage on new connection (%s) from %s' , id ( self ) , self . host ) #NEWLINE# if self . _compressor : #NEWLINE# #INDENT# self . compressor = self . _compressor #NEWLINE# #UNINDENT# self . connected_event . set ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( startup_response , AuthenticateMessage ) : #NEWLINE# #INDENT# log . debug ( 'Got AuthenticateMessage on new connection (%s) from %s: %s' , id ( self ) , self . host , startup_response . authenticator ) #NEWLINE# if ( self . authenticator is None ) : #NEWLINE# #INDENT# raise AuthenticationFailed ( 'Remote end requires authentication.' ) #NEWLINE# #UNINDENT# if isinstance ( self . authenticator , dict ) : #NEWLINE# #INDENT# log . debug ( 'Sending credentials-based auth response on %s' , self ) #NEWLINE# cm = CredentialsMessage ( creds = self . authenticator ) #NEWLINE# callback = partial ( self . _handle_startup_response , did_authenticate = True ) #NEWLINE# self . send_msg ( cm , self . get_request_id ( ) , cb = callback ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# log . debug ( 'Sending SASL-based auth response on %s' , self ) #NEWLINE# self . authenticator . server_authenticator_class = startup_response . authenticator #NEWLINE# initial_response = self . authenticator . initial_response ( ) #NEWLINE# initial_response = ( '' if ( initial_response is None ) else initial_response ) #NEWLINE# self . send_msg ( AuthResponseMessage ( initial_response ) , self . get_request_id ( ) , self . _handle_auth_response ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( startup_response , ErrorMessage ) : #NEWLINE# #INDENT# log . debug ( 'Received ErrorMessage on new connection (%s) from %s: %s' , id ( self ) , self . host , startup_response . summary_msg ( ) ) #NEWLINE# if did_authenticate : #NEWLINE# #INDENT# raise AuthenticationFailed ( ( 'Failed to authenticate to %s: %s' % ( self . host , startup_response . summary_msg ( ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ConnectionException ( ( 'Failed to initialize new connection to %s: %s' % ( self . host , startup_response . summary_msg ( ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( startup_response , ConnectionShutdown ) : #NEWLINE# #INDENT# log . debug ( 'Connection to %s was closed during the startup handshake' , self . host ) #NEWLINE# raise startup_response #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg = 'Unexpected response during Connection setup: %r' #NEWLINE# log . error ( msg , startup_response ) #NEWLINE# raise ProtocolError ( ( msg % ( startup_response , ) ) )