commit be06640765510b42912f074ebad6acb7cf4d0bac Author: Damian Johnson atagar@torproject.org Date: Mon May 28 15:52:18 2012 -0700
Renaming getinfo 'values' attribute to 'entries'
The name 'values' has bugged me for a while because it's a dictionary, so users might end up typing things like "my_getinfo_response.values.values()". Renaming it to something that's still generic but without these issues. --- stem/control.py | 6 +++--- stem/response/getinfo.py | 10 +++++----- test/unit/response/getinfo.py | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/stem/control.py b/stem/control.py index b188ea4..1f3b767 100644 --- a/stem/control.py +++ b/stem/control.py @@ -480,7 +480,7 @@ class Controller(BaseController):
# error if we got back different parameters than we requested requested_params = set(param) - reply_params = set(response.values.keys()) + reply_params = set(response.entries.keys())
if requested_params != reply_params: requested_label = ", ".join(requested_params) @@ -489,9 +489,9 @@ class Controller(BaseController): raise stem.socket.ProtocolError("GETINFO reply doesn't match the parameters that we requested. Queried '%s' but got '%s'." % (requested_label, reply_label))
if is_multiple: - return response.values + return response.entries else: - return response.values[param[0]] + return response.entries[param[0]] except stem.socket.ControllerError, exc: if default == UNDEFINED: raise exc else: return default diff --git a/stem/response/getinfo.py b/stem/response/getinfo.py index 7cde9f1..dabbe12 100644 --- a/stem/response/getinfo.py +++ b/stem/response/getinfo.py @@ -5,7 +5,7 @@ class GetInfoResponse(stem.socket.ControlMessage): Reply for a GETINFO query.
Attributes: - values (dict) - mapping between the queried options and their values + entries (dict) - mapping between the queried options and their values """
def _parse_message(self): @@ -21,7 +21,7 @@ class GetInfoResponse(stem.socket.ControlMessage): # . # 250 OK
- self.values = {} + self.entries = {}
lines = list(self)
@@ -30,7 +30,7 @@ class GetInfoResponse(stem.socket.ControlMessage):
for line in lines: if not "=" in line: - raise stem.socket.ProtocolError("GETINFO replies should only contain parameter=value mappings: %s" % line) + raise stem.socket.ProtocolError("GETINFO replies should only contain parameter=value mappings:\n%s" % self)
key, value = line.split("=", 1)
@@ -41,7 +41,7 @@ class GetInfoResponse(stem.socket.ControlMessage): if value.startswith("\n"): value = value[1:] else: - raise stem.socket.ProtocolError("GETINFO response contained a multiline value that didn't start with a newline: %s" % line) + raise stem.socket.ProtocolError("GETINFO response contained a multiline value that didn't start with a newline:\n%s" % self)
- self.values[key] = value + self.entries[key] = value
diff --git a/test/unit/response/getinfo.py b/test/unit/response/getinfo.py index 5f5862a..6787cff 100644 --- a/test/unit/response/getinfo.py +++ b/test/unit/response/getinfo.py @@ -56,7 +56,7 @@ class TestGetInfoResponse(unittest.TestCase): self.assertTrue(isinstance(control_message, stem.socket.ControlMessage)) self.assertTrue(isinstance(control_message, stem.response.getinfo.GetInfoResponse))
- self.assertEqual({}, control_message.values) + self.assertEqual({}, control_message.entries)
def test_single_response(self): """ @@ -65,7 +65,7 @@ class TestGetInfoResponse(unittest.TestCase):
control_message = mocking.get_message(SINGLE_RESPONSE) stem.response.convert("GETINFO", control_message) - self.assertEqual({"version": "0.2.3.11-alpha-dev"}, control_message.values) + self.assertEqual({"version": "0.2.3.11-alpha-dev"}, control_message.entries)
def test_batch_response(self): """ @@ -81,7 +81,7 @@ class TestGetInfoResponse(unittest.TestCase): "fingerprint": "5FDE0422045DF0E1879A3738D09099EB4A0C5BA0", }
- self.assertEqual(expected, control_message.values) + self.assertEqual(expected, control_message.entries)
def test_multiline_response(self): """ @@ -97,7 +97,7 @@ class TestGetInfoResponse(unittest.TestCase): "config-text": "\n".join(MULTILINE_RESPONSE.splitlines()[2:8]), }
- self.assertEqual(expected, control_message.values) + self.assertEqual(expected, control_message.entries)
def test_invalid_non_mapping_content(self): """
tor-commits@lists.torproject.org