mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-10-12 16:32:01 -05:00
Added try/except block for user_input in ipautil
Added error handling for function user_input in order to handle EOFError in ipautil.py https://fedorahosted.org/freeipa/ticket/3406 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
1 parent
0abaf195dc
commit
7c48621bb8
1 file changed
+29
-17
+29
-17
@@ -747,30 +747,40 @@ def ipa_generate_password(characters=None,pwd_len=None):
|
|||||||
def user_input(prompt, default = None, allow_empty = True):
|
def user_input(prompt, default = None, allow_empty = True):
|
||||||
if default == None:
|
if default == None:
|
||||||
while True:
|
while True:
|
||||||
ret = raw_input("%s: " % prompt)
|
try:
|
||||||
if allow_empty or ret.strip():
|
ret = raw_input("%s: " % prompt)
|
||||||
return ret
|
if allow_empty or ret.strip():
|
||||||
|
return ret
|
||||||
|
except EOFError:
|
||||||
|
if allow_empty:
|
||||||
|
return ''
|
||||||
|
raise RuntimeError("Failed to get user input")
|
||||||
|
|
||||||
if isinstance(default, basestring):
|
if isinstance(default, basestring):
|
||||||
while True:
|
while True:
|
||||||
ret = raw_input("%s [%s]: " % (prompt, default))
|
try:
|
||||||
if not ret and (allow_empty or default):
|
ret = raw_input("%s [%s]: " % (prompt, default))
|
||||||
|
if not ret and (allow_empty or default):
|
||||||
|
return default
|
||||||
|
elif ret.strip():
|
||||||
|
return ret
|
||||||
|
except EOFError:
|
||||||
return default
|
return default
|
||||||
elif ret.strip():
|
|
||||||
return ret
|
|
||||||
if isinstance(default, bool):
|
if isinstance(default, bool):
|
||||||
if default:
|
choice = "yes" if default else "no"
|
||||||
choice = "yes"
|
|
||||||
else:
|
|
||||||
choice = "no"
|
|
||||||
while True:
|
while True:
|
||||||
ret = raw_input("%s [%s]: " % (prompt, choice))
|
try:
|
||||||
if not ret:
|
ret = raw_input("%s [%s]: " % (prompt, choice))
|
||||||
|
if not ret:
|
||||||
|
return default
|
||||||
|
elif ret.lower()[0] == "y":
|
||||||
|
return True
|
||||||
|
elif ret.lower()[0] == "n":
|
||||||
|
return False
|
||||||
|
except EOFError:
|
||||||
return default
|
return default
|
||||||
elif ret.lower()[0] == "y":
|
|
||||||
return True
|
|
||||||
elif ret.lower()[0] == "n":
|
|
||||||
return False
|
|
||||||
if isinstance(default, int):
|
if isinstance(default, int):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@@ -780,6 +790,8 @@ def user_input(prompt, default = None, allow_empty = True):
|
|||||||
ret = int(ret)
|
ret = int(ret)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
except EOFError:
|
||||||
|
return default
|
||||||
else:
|
else:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user