mirror of
https://github.com/borgbackup/borg.git
synced 2026-06-11 01:41:57 -04:00
yes: deal with UnicodeDecodeError in input(), fixes #6984
if retry is True, it will just retry to get a valid answer. if retry is False, it will return the default. the code can be tested by entering "error" (without the quotes).
This commit is contained in:
parent
ec3c7b5770
commit
9d1107ea80
1 changed files with 8 additions and 1 deletions
|
|
@ -8,6 +8,9 @@ FALSISH = ("No", "NO", "no", "N", "n", "0")
|
|||
TRUISH = ("Yes", "YES", "yes", "Y", "y", "1")
|
||||
DEFAULTISH = ("Default", "DEFAULT", "default", "D", "d", "")
|
||||
|
||||
ERROR = "error"
|
||||
assert ERROR not in TRUISH + FALSISH + DEFAULTISH
|
||||
|
||||
|
||||
def yes(
|
||||
msg=None,
|
||||
|
|
@ -88,10 +91,14 @@ def yes(
|
|||
if not prompt:
|
||||
return default
|
||||
try:
|
||||
answer = input()
|
||||
answer = input() # this may raise UnicodeDecodeError, #6984
|
||||
if answer == ERROR: # for testing purposes
|
||||
raise UnicodeDecodeError("?", b"?", 0, 1, "?") # args don't matter
|
||||
except EOFError:
|
||||
# avoid defaultish[0], defaultish could be empty
|
||||
answer = truish[0] if default else falsish[0]
|
||||
except UnicodeDecodeError:
|
||||
answer = ERROR
|
||||
if answer in defaultish:
|
||||
if default_msg:
|
||||
output(default_msg, "accepted_default")
|
||||
|
|
|
|||
Loading…
Reference in a new issue