From efb37739ab1b3a7c9d87af7a2d8ed57a1d0d5abe Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Thu, 9 Feb 2012 09:09:03 -0500 Subject: Add common helper for interactive prompts This patch adds a common method, textui.prompt_helper, that handles encoding, decoding and error handling for interactive prompts. On EOFError (Ctrl+D) or KeyboardInterrupt (Ctrl+C), it raises a new InvocationError, PromptFailed. The helper is used in prompt, prompt_yesno, and prompt_password, each of which originally only handled one of Ctrl+C and Ctrl+D. This fixes https://fedorahosted.org/freeipa/ticket/2345 And it means prompt_yesno will no longer return None on error. A minor fix restores errors.py's ability print out the list of errors when run as a script. --- ipalib/errors.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'ipalib/errors.py') diff --git a/ipalib/errors.py b/ipalib/errors.py index 115802fa6..bdc4a5e73 100644 --- a/ipalib/errors.py +++ b/ipalib/errors.py @@ -816,6 +816,15 @@ class NotConfiguredError(InvocationError): format = _('Client is not configured. Run ipa-client-install.') +class PromptFailed(InvocationError): + """ + **3014** Raise when an interactive prompt failed. + """ + + errno = 3014 + format = _('Could not get %(name)s interactively') + + ############################################################################## # 4000 - 4999: Execution errors @@ -1587,5 +1596,5 @@ public_errors = tuple( if __name__ == '__main__': for klass in public_errors: - print '%d\t%s' % (klass.code, klass.__name__) + print '%d\t%s' % (klass.errno, klass.__name__) print '(%d public errors)' % len(public_errors) -- cgit