Asks a single question and validates it against a list of validators. When an answer fails validation, the complaint is printed and the question is asked again. :param question: The question to ask. :param validators: The list of validators that the answer m
(question, *validators)
| 44 | |
| 45 | @staticmethod |
| 46 | def ask_question(question, *validators): |
| 47 | """ |
| 48 | Asks a single question and validates it against a list of validators. |
| 49 | When an answer fails validation, the complaint is printed and the question |
| 50 | is asked again. |
| 51 | |
| 52 | :param question: The question to ask. |
| 53 | :param validators: The list of validators that the answer must pass. |
| 54 | :return: The answer, converted to its final form by the validators. |
| 55 | """ |
| 56 | answer = None |
| 57 | while answer is None: |
| 58 | answer = input(question) |
| 59 | for validator in validators: |
| 60 | answer, complaint = validator(answer) |
| 61 | if answer is None: |
| 62 | print(complaint) |
| 63 | break |
| 64 | return answer |
| 65 | |
| 66 | @staticmethod |
| 67 | def non_empty(answer): |
no outgoing calls
no test coverage detected