rewrite some tail call loops as normal loops

master
magical 2022-08-06 06:20:16 +00:00
parent 2e54939345
commit 5e7168c848
1 changed files with 32 additions and 22 deletions

View File

@ -2368,17 +2368,22 @@ def paren_prompt(text, positive=True, choices=[], function=input, default=None):
return ""
def sane_value(network, key, prompt, positive=True, return_empty=False):
def sane_value(network, key, prompt, positive=True, allow_empty=False):
while 1:
response = paren_prompt(prompt, positive)
if return_empty and response == "":
if allow_empty and response == "":
return response
try: network.validate(key, response)
try:
network.validate(key, response)
except AssertionError as e:
return sane_value(network, key, e.description, False)
prompt = e.description
positive = False
else:
return response
def password_loop(prompt, positive=True):
while 1:
response1 = paren_prompt(prompt, positive, function=getpass)
if response1 == "":
confprompt = "Confirm empty password"
@ -2386,14 +2391,19 @@ def password_loop(prompt, positive=True):
confprompt = "Confirm it"
response2 = paren_prompt(confprompt, function=getpass)
if response1 != response2:
return password_loop("Those didnt match. Try again", False)
prompt = "Those didnt match. Try again"
positive = False
else:
return response1
def nameloop(network, prompt, positive):
while 1:
name = sane_value(network, "user_name", prompt, positive)
if network.user_is_registered(name):
return nameloop(network, "%s is already registered" % name, False)
prompt = "%s is already registered" % name
positive = False
else:
return name
@ -2405,7 +2415,7 @@ def log_in(network, name="", password=""):
curses app.
"""
if not name:
name = sane_value(network, "user_name", "Username", return_empty=True)
name = sane_value(network, "user_name", "Username", allow_empty=True)
if name == "":
motherfucking_rainbows("~~W3 4R3 4n0nYm0u5~~")
else: