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

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



commit 0b83af2922b5c377161626c7aef2af14a0152463
Author: Ravi Chandra Padmala <neenaoffline@xxxxxxxxx>
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))



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