commit 9fc23f64d3534a7e68bb0b66dddbd18b3e8db63c Author: Damian Johnson atagar@torproject.org Date: Sat Dec 8 15:24:50 2012 -0800
Unexpected TypeError when get_conf() called for non-existant value
Calling the Controller's get_conf() method would result in a TypeError if the configuration option didn't exist. For instance...
====================================================================== ERROR: test_reattaching_listeners ---------------------------------------------------------------------- Traceback: File "/home/atagar/Desktop/stem/test/integ/control/controller.py", line 134, in test_reattaching_listeners controller.authenticate() File "/home/atagar/Desktop/stem/stem/control.py", line 954, in authenticate stem.connection.authenticate(self, *args, **kwargs) File "/home/atagar/Desktop/stem/stem/connection.py", line 358, in authenticate authenticate_none(controller, False) File "/home/atagar/Desktop/stem/stem/connection.py", line 435, in authenticate_none auth_response = _msg(controller, "AUTHENTICATE") File "/home/atagar/Desktop/stem/stem/connection.py", line 787, in _msg return controller.msg(message) File "/home/atagar/Desktop/stem/stem/control.py", line 308, in msg self._post_authentication() File "/home/atagar/Desktop/stem/stem/control.py", line 1511, in _post_authentication owning_pid = self.get_conf("__OwningControllerProcess", None) File "/home/atagar/Desktop/stem/stem/control.py", line 1009, in get_conf return _case_insensitive_lookup(entries, param, default) File "/home/atagar/Desktop/stem/stem/control.py", line 1644, in _case_insensitive_lookup for entry in entries: TypeError: 'NoneType' object is not iterable --- stem/control.py | 17 +++++++++-------- 1 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/stem/control.py b/stem/control.py index 74127c0..30c440b 100644 --- a/stem/control.py +++ b/stem/control.py @@ -1636,14 +1636,15 @@ def _case_insensitive_lookup(entries, key, default = UNDEFINED): :raises: **ValueError** if no such value exists """
- if isinstance(entries, dict): - for k, v in entries.items(): - if k.lower() == key.lower(): - return v - else: - for entry in entries: - if entry.lower() == key.lower(): - return entry + if entries is not None: + if isinstance(entries, dict): + for k, v in entries.items(): + if k.lower() == key.lower(): + return v + else: + for entry in entries: + if entry.lower() == key.lower(): + return entry
if default != UNDEFINED: return default else: raise ValueError("key '%s' doesn't exist in dict: %s" % (key, entries))