[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [oonib/master] Fix: old code could raise a KeyError because choices[c] preceded the if c in choices



commit e9e4701794b40ac2e7fdc97a3d71189820634b06
Author: Darius Bacon <darius@xxxxxx>
Date:   Fri Mar 28 11:08:41 2014 -0700

    Fix: old code could raise a KeyError because choices[c] preceded the if c in choices
---
 oonib/bouncer/handlers.py |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/oonib/bouncer/handlers.py b/oonib/bouncer/handlers.py
index 47fee26..0ff103e 100644
--- a/oonib/bouncer/handlers.py
+++ b/oonib/bouncer/handlers.py
@@ -95,14 +95,13 @@ class Bouncer(object):
                 choices = self.getHelperAddresses(helper_name)
                 for item in response.values():
                     c = item['collector']
-                    h = choices[c]
-                    if c in choices.keys():
+                    if c in choices:
                         break
                 # Or default to a random selection
                 else:
-                    c,h = random.choice(choices.items())
+                    c = random.choice(choices)
 
-                response[helper_name] = {'collector': c, 'address': h}
+                response[helper_name] = {'collector': c, 'address': choices[c]}
 
             except e.TestHelperNotFound:
                 response = {'error': 'test-helper-not-found'}



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits