rewrite some tail call loops as normal loops
parent
2e54939345
commit
5e7168c848
|
@ -2368,33 +2368,43 @@ def paren_prompt(text, positive=True, choices=[], function=input, default=None):
|
|||
return ""
|
||||
|
||||
|
||||
def sane_value(network, key, prompt, positive=True, return_empty=False):
|
||||
response = paren_prompt(prompt, positive)
|
||||
if return_empty and response == "":
|
||||
return response
|
||||
try: network.validate(key, response)
|
||||
except AssertionError as e:
|
||||
return sane_value(network, key, e.description, False)
|
||||
return response
|
||||
def sane_value(network, key, prompt, positive=True, allow_empty=False):
|
||||
while 1:
|
||||
response = paren_prompt(prompt, positive)
|
||||
if allow_empty and response == "":
|
||||
return response
|
||||
try:
|
||||
network.validate(key, response)
|
||||
except AssertionError as e:
|
||||
prompt = e.description
|
||||
positive = False
|
||||
else:
|
||||
return response
|
||||
|
||||
|
||||
def password_loop(prompt, positive=True):
|
||||
response1 = paren_prompt(prompt, positive, function=getpass)
|
||||
if response1 == "":
|
||||
confprompt = "Confirm empty password"
|
||||
else:
|
||||
confprompt = "Confirm it"
|
||||
response2 = paren_prompt(confprompt, function=getpass)
|
||||
if response1 != response2:
|
||||
return password_loop("Those didnt match. Try again", False)
|
||||
return response1
|
||||
while 1:
|
||||
response1 = paren_prompt(prompt, positive, function=getpass)
|
||||
if response1 == "":
|
||||
confprompt = "Confirm empty password"
|
||||
else:
|
||||
confprompt = "Confirm it"
|
||||
response2 = paren_prompt(confprompt, function=getpass)
|
||||
if response1 != response2:
|
||||
prompt = "Those didnt match. Try again"
|
||||
positive = False
|
||||
else:
|
||||
return response1
|
||||
|
||||
|
||||
def nameloop(network, prompt, positive):
|
||||
name = sane_value(network, "user_name", prompt, positive)
|
||||
if network.user_is_registered(name):
|
||||
return nameloop(network, "%s is already registered" % name, False)
|
||||
return name
|
||||
while 1:
|
||||
name = sane_value(network, "user_name", prompt, positive)
|
||||
if network.user_is_registered(name):
|
||||
prompt = "%s is already registered" % name
|
||||
positive = False
|
||||
else:
|
||||
return name
|
||||
|
||||
|
||||
def log_in(network, name="", password=""):
|
||||
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue