Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
required If True, user input must not be empty.
retry If True and invalid value, prompt again.
confirm If True, user is asked to confirm input value.
"""
if default is not None and (default or not required):
prompt = "%s (default is '%s'): " % (msg, default)
else:
prompt = "%s: " % msg
while True:
value = raw_input(prompt).strip() or default or ''
try:
if required and not value:
raise InputError("Required value can't be empty.")
if match and not re.match(match, value):
raise InputError("Input value must match '%s'." % match)
except InputError as exc:
if retry:
print >> sys.stderr, "WARNING: %s" % exc
continue
raise
if confirm:
if not prompt_boolean(
"Input value is '%s'. Please confirm." % value,
default=True, retry=True
):
continue
break
return value
default Default value to display.
match If provided, user input must match this regex string.
required If True, user input must not be empty.
retry If True and invalid value, prompt again.
confirm If True, user is asked to confirm input value.
"""
if default is not None and (default or not required):
prompt = "%s (default is '%s'): " % (msg, default)
else:
prompt = "%s: " % msg
while True:
value = raw_input(prompt).strip() or default or ''
try:
if required and not value:
raise InputError("Required value can't be empty.")
if match and not re.match(match, value):
raise InputError("Input value must match '%s'." % match)
except InputError as exc:
if retry:
print >> sys.stderr, "WARNING: %s" % exc
continue
raise
if confirm:
if not prompt_boolean(
"Input value is '%s'. Please confirm." % value,
default=True, retry=True
):
continue
break
return value
required If True, user input must not be empty.
retry If True and invalid value, prompt again.
confirm If True, user is asked to confirm input value.
"""
if default is not None and (default or not required):
prompt = "%s (default is '%s'): " % (msg, default)
else:
prompt = "%s: " % msg
while True:
value = raw_input(prompt).strip() or default or ''
try:
if required and not value:
raise InputError("Required value can't be empty.")
if match and not re.match(match, value):
raise InputError("Input value must match '%s'." % match)
except InputError as exc:
if retry:
print >> sys.stderr, "WARNING: %s" % exc
continue
raise
if confirm:
if not prompt_boolean(
"Input value is '%s'. Please confirm." % value,
default=True, retry=True
):
continue
break
return value
default Default value to display.
match If provided, user input must match this regex string.
required If True, user input must not be empty.
retry If True and invalid value, prompt again.
confirm If True, user is asked to confirm input value.
"""
if default is not None and (default or not required):
prompt = "%s (default is '%s'): " % (msg, default)
else:
prompt = "%s: " % msg
while True:
value = raw_input(prompt).strip() or default or ''
try:
if required and not value:
raise InputError("Required value can't be empty.")
if match and not re.match(match, value):
raise InputError("Input value must match '%s'." % match)
except InputError as exc:
if retry:
print >> sys.stderr, "WARNING: %s" % exc
continue
raise
if confirm:
if not prompt_boolean(
"Input value is '%s'. Please confirm." % value,
default=True, retry=True
):
continue
break
return value
retry If True and invalid value, prompt again.
confirm If True, user is asked to confirm input value.
"""
if default is not None and (default or not required):
prompt = "%s (default is '%s'): " % (msg, default)
else:
prompt = "%s: " % msg
while True:
value = raw_input(prompt).strip() or default or ''
try:
if required and not value:
raise InputError("Required value can't be empty.")
if match and not re.match(match, value):
raise InputError("Input value must match '%s'." % match)
except InputError as exc:
if retry:
print >> sys.stderr, "WARNING: %s" % exc
continue
raise
if confirm:
if not prompt_boolean(
"Input value is '%s'. Please confirm." % value,
default=True, retry=True
):
continue
break
return value