[stem/master] Reintroducing tuple support to get_options

commit e2057f1beb158ce111ddc735c8b1a58fab79f6d1 Author: Damian Johnson <atagar@torproject.org> Date: Sat Jul 7 19:26:56 2012 -0700 Reintroducing tuple support to get_options Damn I hate it when I'm right. The reason that arm supported tuple lists is the fucking HiddenService* options. Adding support for them back in, though I gotta admit that I flirted with the idea of just saying "screw hidden services". These things are such a hack... --- stem/control.py | 11 +++++++++-- test/integ/control/controller.py | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/stem/control.py b/stem/control.py index f377cd3..ccfeb94 100644 --- a/stem/control.py +++ b/stem/control.py @@ -703,7 +703,11 @@ class Controller(BaseController): "Log": None, }) - :param dict params: mapping of configuration options to the values we're setting it to + The params can optionally be a list a key/value tuples, though the only + reason this type of arguement would be useful is for hidden service + configuration (those options are order dependent). + + :param dict,list params: mapping of configuration options to the values we're setting it to :param bool reset: issues a SETCONF if False, and RESETCONF if True :raises: @@ -715,7 +719,10 @@ class Controller(BaseController): # constructs the SETCONF or RESETCONF query query_comp = ["RESETCONF" if reset else "SETCONF"] - for param, value in params.items(): + if isinstance(params, dict): + params = params.items() + + for param, value in params: if isinstance(value, str): query_comp.append("%s=\"%s\"" % (param, value.strip())) elif value: diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py index b7eea7e..3a15634 100644 --- a/test/integ/control/controller.py +++ b/test/integ/control/controller.py @@ -242,23 +242,23 @@ class TestController(unittest.TestCase): except stem.socket.InvalidArguments, exc: self.assertEqual(["bombay"], exc.arguments) - # context-sensitive keys - controller.set_options({ - "HiddenServiceDir": tmpdir, - "HiddenServicePort": "17234 127.0.0.1:17235", - }) + # context-sensitive keys (the only retched things for which order matters) + controller.set_options(( + ("HiddenServiceDir", tmpdir), + ("HiddenServicePort", "17234 127.0.0.1:17235"), + )) self.assertEqual(tmpdir, controller.get_conf("HiddenServiceDir")) self.assertEqual("17234 127.0.0.1:17235", controller.get_conf("HiddenServicePort")) finally: # reverts configuration changes - controller.set_options({ - "ExitPolicy": "reject *:*", - "ConnLimit": None, - "ContactInfo": None, - "HiddenServiceDir": None, - "HiddenServicePort": None, - }, reset = True) + controller.set_options(( + ("ExitPolicy", "reject *:*"), + ("ConnLimit", None), + ("ContactInfo", None), + ("HiddenServiceDir", None), + ("HiddenServicePort", None), + ), reset = True) shutil.rmtree(tmpdir)
participants (1)
-
atagar@torproject.org