def METHOD_NAME(self, alert, action):
    action = action.upper()
    text = " ".join(alert.text.splitlines())
    if action == self.ACCEPT:
        alert.accept()
    elif action == self.DISMISS:
        alert.dismiss()
    elif action != self.LEAVE:
        raise ValueError(f"Invalid alert action '{action}'.")
    return text