[tor-commits] [stem/master] Minor change to GetConfResponse documentation
atagar at torproject.org
atagar at torproject.org
Wed Jul 4 21:34:20 UTC 2012
commit ece7f85dd675633de3b866c868bba1560fd22060
Author: Ravi Chandra Padmala <neenaoffline at gmail.com>
Date: Tue Jun 12 21:07:13 2012 +0530
Minor change to GetConfResponse documentation
---
stem/control.py | 2 +-
stem/response/__init__.py | 2 +-
stem/response/getconf.py | 28 ++++++++++------------------
3 files changed, 12 insertions(+), 20 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index f0459cb..a616b5c 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -534,7 +534,7 @@ class Controller(BaseController):
def get_conf(self, param, default = None):
"""
Queries the control socket for the values of given configuration options. If
- provided a default then that's returned as the if the GETCONF option is undefined
+ provided a default then that's returned as if the GETCONF option is undefined
or if the call fails for any reason (invalid configuration option, error
response, control port closed, initiated, etc).
diff --git a/stem/response/__init__.py b/stem/response/__init__.py
index 43ecb3b..273bead 100644
--- a/stem/response/__init__.py
+++ b/stem/response/__init__.py
@@ -60,7 +60,7 @@ def convert(response_type, message):
:raises:
* :class:`stem.socket.ProtocolError` the message isn't a proper response of that type
- * :class:`stem.socket.InvalidArguments` the request's arguments are invalid
+ * :class:`stem.socket.InvalidArguments` Raised if the request's arguments when converting GETCONF or GETINFO responses are invalid
* TypeError if argument isn't a :class:`stem.response.ControlMessage` or response_type isn't supported
"""
diff --git a/stem/response/getconf.py b/stem/response/getconf.py
index cffbc61..41f1857 100644
--- a/stem/response/getconf.py
+++ b/stem/response/getconf.py
@@ -1,29 +1,21 @@
import stem.socket
import stem.response
-def _getval(dictionary, key):
- try:
- return dictionary[key]
- except KeyError:
- pass
-
def _split_line(line):
- try:
- if '=' in line:
- if line[line.find("=") + 1] == "\"":
- return line.pop_mapping(True)
- else:
- return line.split("=", 1)
- else:
- return (line, None)
- except IndexError:
- return (line[:-1], None)
+ if line.is_next_mapping(quoted = False):
+ return line.split("=", 1) # TODO: make this part of the ControlLine?
+ elif line.is_next_mapping(quoted = True):
+ return line.pop_mapping(True).items()[0]
+ else:
+ return (line.pop(), None)
class GetConfResponse(stem.response.ControlMessage):
"""
Reply for a GETCONF query.
- :var dict entries: mapping between the queried options and their values
+ :var dict entries:
+ mapping between the queried options (string) and their values (string/list
+ of strings)
"""
def _parse_message(self):
@@ -54,7 +46,7 @@ class GetConfResponse(stem.response.ControlMessage):
line = remaining_lines.pop(0)
key, value = _split_line(line)
- entry = _getval(self.entries, key)
+ entry = self.entries.get(key, None)
if type(entry) == str and entry != value:
self.entries[key] = [entry]
More information about the tor-commits
mailing list