From: Steven Tobin Date: Mon, 26 Sep 2016 11:09:31 +0000 (+0100) Subject: Merge branch 'style_changes' of https://github.com/jfindlay/XKCD-password-generator... X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=318e1f7d4d527dc415bf66230ef32da92c127415;p=redacted-XKCD-password-generator.git Merge branch 'style_changes' of https://github.com/jfindlay/XKCD-password-generator into jfindlay-style_changes --- 318e1f7d4d527dc415bf66230ef32da92c127415 diff --cc xkcdpass/xkcd_password.py index 155b151,cb8f79e..b975e20 --- a/xkcdpass/xkcd_password.py +++ b/xkcdpass/xkcd_password.py @@@ -186,29 -187,13 +187,30 @@@ def find_acrostic(acrostic, worddict) def choose_words(wordlist, numwords): - s = [] - for i in xrange(numwords): - s.append(rng().choice(wordlist)) - return s + """ + Choose numwords randomly from wordlist + """ + + return [rng().choice(wordlist) for i in xrange(numwords)] +def try_input(prompt, validate): + """ + Suppress stack trace on user cancel and validate input with supplied + validate callable. + """ + + try: + answer = raw_input(prompt) + except (KeyboardInterrupt, EOFError): + # user cancelled + print("") + sys.exit(0) + + # validate input + return validate(answer) + + def generate_xkcdpassword(wordlist, numwords=6, interactive=False,