def _authenticate_x509(credentials, sock_info):
 query = SON([('authenticate', 1), ('mechanism', 'MONGODB-X509')])
 if (credentials.username is not None):
  query['user'] = credentials.username
 elif (sock_info.max_wire_version < 5):
  raise ConfigurationError('A username is required for MONGODB-X509 authentication when connected to MongoDB versions older than 3.4.')
 sock_info.command('$external', query)

def _authenticate_x509 ( credentials , sock_info ) : query = SON ( [ ( 'authenticate' , 1 ) , ( 'mechanism' , 'MONGODB-X509' ) ] ) if ( credentials . username is not None ) : query [ 'user' ] = credentials . username elif ( sock_info . max_wire_version < 5 ) : raise ConfigurationError ( 'A username is required for MONGODB-X509 authentication when connected to MongoDB versions older than 3.4.' ) sock_info . command ( '$external' , query )
authenticate using mongodb-x509 .