summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2016-12-27 12:21:47 -0800
committerDylan Baker <dylan@pnwbakers.com>2016-12-27 12:52:44 -0800
commitb9d102d084b13d3498beb768707dae9b01eb02a4 (patch)
tree5ee586c5fb86b9a93a966ebf8836ae8723874cca /alot
parentd5ea31204df5c41d798003d16222dec2c6ab0ed5 (diff)
commands/utils: Refactor exception case
This removes the use of range (originally I simply replaced it with xrange, but the realized that the use of range was itself strange), and replaces it with generators and iterators to create the dictionary. This has the advantage of only creating one concrete instance (the choices dict), and being slightly easier to read and understand, as well as not needing to call len() repeatedly.
Diffstat (limited to 'alot')
-rw-r--r--alot/commands/utils.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/alot/commands/utils.py b/alot/commands/utils.py
index 153c5028..7249b9ee 100644
--- a/alot/commands/utils.py
+++ b/alot/commands/utils.py
@@ -33,10 +33,10 @@ def get_keys(ui, encrypt_keyids, block_error=False, signed_only=False):
signed_only=signed_only)
except GPGProblem as e:
if e.code == GPGCode.AMBIGUOUS_NAME:
- possible_keys = crypto.list_keys(hint=keyid)
- tmp_choices = [k.uids[0].uid for k in possible_keys]
- choices = {str(len(tmp_choices) - x): tmp_choices[x]
- for x in range(0, len(tmp_choices))}
+ tmp_choices = (k.uids[0].uid for k in
+ crypto.list_keys(hint=keyid))
+ choices = {str(i): t for i, t in
+ enumerate(reversed(tmp_choices), 1)}
keyid = yield ui.choice("ambiguous keyid! Which " +
"key do you want to use?",
choices, cancel=None)