def _check_write_command_response(results):
 errors = [res for res in results if (('writeErrors' in res[1]) or ('writeConcernError' in res[1]))]
 if errors:
  (offset, result) = errors[(-1)]
  write_errors = result.get('writeErrors')
  if write_errors:
   error = write_errors[(-1)]
   error['index'] += offset
   if (error.get('code') == 11000):
    raise DuplicateKeyError(error.get('errmsg'), 11000, error)
   raise WriteError(error.get('errmsg'), error.get('code'), error)
  else:
   error = result['writeConcernError']
   if (('errInfo' in error) and error['errInfo'].get('wtimeout')):
    raise WTimeoutError(error.get('errmsg'), error.get('code'), error)
   raise WriteConcernError(error.get('errmsg'), error.get('code'), error)

def _check_write_command_response ( results ) : errors = [ res for res in results if ( ( 'writeErrors' in res [ 1 ] ) or ( 'writeConcernError' in res [ 1 ] ) ) ] if errors : ( offset , result ) = errors [ ( - 1 ) ] write_errors = result . get ( 'writeErrors' ) if write_errors : error = write_errors [ ( - 1 ) ] error [ 'index' ] += offset if ( error . get ( 'code' ) == 11000 ) : raise DuplicateKeyError ( error . get ( 'errmsg' ) , 11000 , error ) raise WriteError ( error . get ( 'errmsg' ) , error . get ( 'code' ) , error ) else : error = result [ 'writeConcernError' ] if ( ( 'errInfo' in error ) and error [ 'errInfo' ] . get ( 'wtimeout' ) ) : raise WTimeoutError ( error . get ( 'errmsg' ) , error . get ( 'code' ) , error ) raise WriteConcernError ( error . get ( 'errmsg' ) , error . get ( 'code' ) , error )
backward compatibility helper for write command error handling .