[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Add attributes to InvalidRequest and InvalidArguments
commit a80a784b29a91fb3ee9a6ec8a30b829b68648e41
Author: Ravi Chandra Padmala <neenaoffline@xxxxxxxxx>
Date: Thu Jun 14 12:16:44 2012 +0530
Add attributes to InvalidRequest and InvalidArguments
Adds attributes to store the error code and error message
to InvalidRequest and InvalidArguments
---
stem/response/__init__.py | 3 ++-
stem/response/getconf.py | 4 ++--
stem/response/getinfo.py | 2 +-
stem/socket.py | 38 +++++++++++++++++++++++++++++++++-----
4 files changed, 38 insertions(+), 9 deletions(-)
diff --git a/stem/response/__init__.py b/stem/response/__init__.py
index 273bead..13c65b3 100644
--- a/stem/response/__init__.py
+++ b/stem/response/__init__.py
@@ -60,7 +60,8 @@ def convert(response_type, message):
:raises:
* :class:`stem.socket.ProtocolError` the message isn't a proper response of that type
- * :class:`stem.socket.InvalidArguments` Raised if the request's arguments when converting GETCONF or GETINFO responses are invalid
+ * :class:`stem.socket.InvalidArguments` raised if the arguments given as
+ input are invalid. Raised whenj converting GETINFO or GETCONF requests
* 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 41f1857..fd2256c 100644
--- a/stem/response/getconf.py
+++ b/stem/response/getconf.py
@@ -33,11 +33,11 @@ class GetConfResponse(stem.response.ControlMessage):
if not self.is_ok():
unrecognized_keywords = []
for code, _, line in self.content():
- if code == '552' and line.startswith("Unrecognized configuration key \"") and line.endswith("\""):
+ if code == "552" and line.startswith("Unrecognized configuration key \"") and line.endswith("\""):
unrecognized_keywords.append(line[32:-1])
if unrecognized_keywords:
- raise stem.socket.InvalidArguments("GETCONF request contained unrecognized keywords: %s\n" \
+ raise stem.socket.InvalidArguments("552", "GETCONF request contained unrecognized keywords: %s\n" \
% ', '.join(unrecognized_keywords), unrecognized_keywords)
else:
raise stem.socket.ProtocolError("GETCONF response contained a non-OK status code:\n%s" % self)
diff --git a/stem/response/getinfo.py b/stem/response/getinfo.py
index 3fac253..f467769 100644
--- a/stem/response/getinfo.py
+++ b/stem/response/getinfo.py
@@ -31,7 +31,7 @@ class GetInfoResponse(stem.response.ControlMessage):
unrecognized_keywords.append(line[18:-1])
if unrecognized_keywords:
- raise stem.socket.InvalidArguments("GETCONF request contained unrecognized keywords: %s\n" \
+ raise stem.socket.InvalidArguments("552", "GETINFO request contained unrecognized keywords: %s\n" \
% ', '.join(unrecognized_keywords), unrecognized_keywords)
else:
raise stem.socket.ProtocolError("GETINFO response didn't have an OK status:\n%s" % self)
diff --git a/stem/socket.py b/stem/socket.py
index b933f50..9e1f5b7 100644
--- a/stem/socket.py
+++ b/stem/socket.py
@@ -551,24 +551,52 @@ class ProtocolError(ControllerError):
"Malformed content from the control socket."
class InvalidRequest(ControllerError):
- "Base Exception class for invalid requests"
+ """
+ Base Exception class for invalid requests
+
+ :var str code: The error code returned by Tor (if applicable)
+ :var str message: The error message returned by Tor (if applicable) or a human
+ readable error message
+ """
+
+ def __init__(self, code = None, message = None):
+ """
+ Initializes an InvalidRequest object.
+
+ :param str code: The error code returned by Tor (if applicable)
+ :param str message: The error message returned by Tor (if applicable) or a
+ human readable error message
+
+ :returns: object of InvalidRequest class
+ """
+
+ self.code = code
+ self.message = message
class InvalidArguments(InvalidRequest):
"""
Exception class for invalid requests which contain invalid arguments.
- :var list arguments: a list of parameters which were invalid
+ :var str code: The error code returned by Tor (if applicable)
+ :var str message: The error message returned by Tor (if applicable) or a human
+ readable error message
+ :var list arguments: a list of arguments which were invalid
"""
- def __init__(self, message, arguments):
+ def __init__(self, code = None, message = None, arguments = None):
"""
Initializes an InvalidArguments object.
- :param str message: error message
- :param list arguments: a list of parameters which were invalid
+ :param str code: The error code returned by Tor (if applicable)
+ :param str message: The error message returned by Tor (if applicable) or a
+ human readable error message
+ :param list arguments: a list of arguments which were invalid
:returns: object of InvalidArguments class
"""
+
+ self.code = code
+ self.message = message
self.arguments = arguments
class SocketError(ControllerError):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits