From 5e7168c8484b36f3407c7539c5a2934e77af213e Mon Sep 17 00:00:00 2001 From: magical Date: Sat, 6 Aug 2022 06:20:16 +0000 Subject: [PATCH] rewrite some tail call loops as normal loops --- clients/urwid/main.py | 54 +++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/clients/urwid/main.py b/clients/urwid/main.py index e3da6c6..e8a1e9d 100644 --- a/clients/urwid/main.py +++ b/clients/urwid/main.py @@ -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: