[tor-commits] [stem/master] Fix a bug where getconf parses didn't set the default correctly for multiple keys

atagar at torproject.org atagar at torproject.org
Wed Jul 4 21:34:20 UTC 2012


commit 0b83af2922b5c377161626c7aef2af14a0152463
Author: Ravi Chandra Padmala <neenaoffline at gmail.com>
Date:   Sun Jun 17 22:27:55 2012 +0530

    Fix a bug where getconf parses didn't set the default correctly for multiple keys
    
    and write a test to check for this
---
 stem/control.py                  |    8 +++++++-
 test/integ/control/controller.py |   11 +++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index d14d723..5ce6780 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -576,5 +576,11 @@ class Controller(BaseController):
         except KeyError: raise stem.socket.InvalidRequest("Received empty string")
     except stem.socket.ControllerError, exc:
       if default is UNDEFINED: raise exc
-      else: return default
+      elif is_multiple:
+        if default != UNDEFINED:
+          return dict([(p, default) for p in param])
+        else:
+          return dict([(p, None) for p in param])
+      else:
+        return default
 
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 9d1028b..38f6f10 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -166,13 +166,20 @@ class TestController(unittest.TestCase):
       self.assertEqual(getconf_params, set(controller.get_conf(["ControlPort",
         "DirPort", "DataDirectory"])))
       
-      # non-existant option
+      # non-existant option(s)
       
       self.assertRaises(stem.socket.InvalidRequest, controller.get_conf, "blarg")
       self.assertEqual("la-di-dah", controller.get_conf("blarg", "la-di-dah"))
+      self.assertRaises(stem.socket.InvalidRequest, controller.get_conf, "blarg")
+      self.assertEqual("la-di-dah", controller.get_conf("blarg", "la-di-dah"))
+      
+      self.assertRaises(stem.socket.InvalidRequest, controller.get_conf,
+          ["blarg", "huadf"], multiple = True)
+      self.assertEqual({"erfusdj": "la-di-dah", "afiafj": "la-di-dah"},
+          controller.get_conf(["erfusdj", "afiafj"], "la-di-dah", multiple = True))
       
       # multivalue configuration keys
-
+      
       nodefamilies = [node_family[11:].strip() for node_family in
           runner.get_torrc_contents().split("\n") if node_family.startswith("NodeFamily ")]
       self.assertEqual(nodefamilies, controller.get_conf("NodeFamily", multiple = True))





More information about the tor-commits mailing list