[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Make get_conf_map work properly with HiddenService* options
commit da66a5dfa3818de5376e252b667a649abccf9702
Author: Ravi Chandra Padmala <neenaoffline@xxxxxxxxx>
Date: Fri Jul 6 21:04:53 2012 +0530
Make get_conf_map work properly with HiddenService* options
---
stem/control.py | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index 6499bbc..7eca284 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -652,7 +652,7 @@ class Controller(BaseController):
for key in response.entries:
if not key.lower() in MAPPED_CONFIG_KEYS.values():
- user_expected_key = _case_insensitive_lookup(param, key)
+ user_expected_key = _case_insensitive_lookup(param, key, key)
if key != user_expected_key:
response.entries[user_expected_key] = response.entries[key]
@@ -751,15 +751,16 @@ class Controller(BaseController):
self._set_conf(arg, "RESETCONF")
-def _case_insensitive_lookup(entries, key):
+def _case_insensitive_lookup(entries, key, default = UNDEFINED):
"""
Makes a case insensitive lookup within a list or dictionary, providing the
first matching entry that we come across.
:param list,dict entries: list or dictionary to be searched
:param str key: entry or key value to look up
+ :param object default: value to be returned if the key doesn't exist
- :returns: case insensitive match
+ :returns: case insensitive match or default if one was provided and key wasn't found
:raises: ValueError if no such value exists
"""
@@ -773,5 +774,6 @@ def _case_insensitive_lookup(entries, key):
if entry.lower() == key.lower():
return entry
- raise ValueError("key '%s' doesn't exist in dict: %s" % (key, entries))
+ if default != UNDEFINED: return default
+ else: raise ValueError("key '%s' doesn't exist in dict: %s" % (key, entries))
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits