#NEWLINE# def handle_mutual_auth( self , response ) : #NEWLINE# #INDENT# '\n        Performs mutual auth checking if possible and requested. This handling\n        is applied to *all* responses, not just 401s.\n        ' #NEWLINE# log . debug ( ( 'handle_mutual_auth(): Handling: %d' % response . status_code ) ) #NEWLINE# if ( self . mutual_authentication in ( REQUIRED , OPTIONAL ) ) : #NEWLINE# #INDENT# is_http_error = ( response . status_code >= 400 ) #NEWLINE# if ( _negotiate_value ( response ) is not None ) : #NEWLINE# #INDENT# log . debug ( 'handle_mutual_auth(): Authenticating the server' ) #NEWLINE# if ( not self . authenticate_server ( response ) ) : #NEWLINE# #INDENT# log . error ( 'handle_mutual_auth(): Mutual authentication failed' ) #NEWLINE# raise MutualAuthenticationError ( 'Unable to authenticate {0}' . format ( response ) ) #NEWLINE# #UNINDENT# log . debug ( 'handle_mutual_auth(): returning {0}' . format ( response ) ) #NEWLINE# return response #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( is_http_error or ( self . mutual_authentication == OPTIONAL ) ) : #NEWLINE# #INDENT# if ( not response . ok ) : #NEWLINE# #INDENT# log . error ( 'handle_mutual_auth(): Mutual authentication unavailable on {0} response' . format ( self . status_code ) ) #NEWLINE# #UNINDENT# if ( self . mutual_authentication == REQUIRED ) : #NEWLINE# #INDENT# return SanitizedResponse ( response ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return response #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# log . error ( 'handle_mutual_auth(): Mutual authentication failed' ) #NEWLINE# raise MutualAuthenticationError ( 'Unable to authenticate {0}' . format ( response ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# log . debug ( 'handle_mutual_auth(): returning {0}' . format ( response ) ) #NEWLINE# return response