MCPcopy
hub / github.com/StevenBlack/hosts / query_yes_no

Function query_yes_no

updateHostsFile.py:1757–1799  ·  view source on GitHub ↗

Ask a yes/no question via input() and get answer from the user. Inspired by the following implementation: https://code.activestate.com/recipes/577058/ Parameters ---------- question : str The question presented to the user. default : str, default "yes"

(question, default="yes")

Source from the content-addressed store, hash-verified

1755
1756
1757def query_yes_no(question, default="yes"):
1758 """
1759 Ask a yes/no question via input() and get answer from the user.
1760
1761 Inspired by the following implementation:
1762
1763 https://code.activestate.com/recipes/577058/
1764
1765 Parameters
1766 ----------
1767 question : str
1768 The question presented to the user.
1769 default : str, default "yes"
1770 The presumed answer if the user just hits <Enter>. It must be "yes",
1771 "no", or None (means an answer is required of the user).
1772
1773 Returns
1774 -------
1775 yes : Whether or not the user replied yes to the question.
1776 """
1777
1778 valid = {"yes": "yes", "y": "yes", "ye": "yes", "no": "no", "n": "no"}
1779 prompt = {None: " [y/n] ", "yes": " [Y/n] ", "no": " [y/N] "}.get(default, None)
1780
1781 if not prompt:
1782 raise ValueError("invalid default answer: '%s'" % default)
1783
1784 reply = None
1785
1786 while not reply:
1787 sys.stdout.write(colorize(question, Colors.PROMPT) + prompt)
1788
1789 choice = input().lower()
1790 reply = None
1791
1792 if default and not choice:
1793 reply = default
1794 elif choice in valid:
1795 reply = valid[choice]
1796 else:
1797 print_failure("Please respond with 'yes' or 'no' (or 'y' or 'n').\n")
1798
1799 return reply == "yes"
1800
1801
1802def is_valid_user_provided_domain_format(domain):

Callers 11

test_valid_defaultMethod · 0.90
test_valid_noMethod · 0.90
test_valid_yesMethod · 0.90
prompt_for_updateFunction · 0.85
prompt_for_exclusionsFunction · 0.85
prompt_for_moveFunction · 0.85
gather_custom_exclusionsFunction · 0.85

Calls 2

colorizeFunction · 0.85
print_failureFunction · 0.70

Tested by 5

test_valid_defaultMethod · 0.72
test_valid_noMethod · 0.72
test_valid_yesMethod · 0.72