[tor-commits] [stem/master] Replacing 'assert' keyword in extend_circuit()
atagar at torproject.org
atagar at torproject.org
Sun Jan 6 00:06:33 UTC 2013
commit 9cd9b4004995015c0a0a04a32bb9c68a1addf728
Author: Damian Johnson <atagar at torproject.org>
Date: Sat Jan 5 16:04:50 2013 -0800
Replacing 'assert' keyword in extend_circuit()
Issue spotted by Sean in "Stem code review 2013-01-03". The check itself is
fine but I'm trying to avoid using the 'assert' keyword.
---
stem/control.py | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index c7d52b4..b22adfd 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1616,17 +1616,16 @@ class Controller(BaseController):
response = self.msg("EXTENDCIRCUIT %s" % " ".join(args))
stem.response.convert("SINGLELINE", response)
- if response.is_ok():
- try:
- extended, new_circuit = response.message.split(" ")
- assert extended == "EXTENDED"
- except:
- raise stem.ProtocolError("EXTENDCIRCUIT response invalid:\n%s", str(response))
- elif response.code in ('512', '552'):
+ if response.code in ('512', '552'):
raise stem.InvalidRequest(response.code, response.message)
- else:
+ elif not response.is_ok():
raise stem.ProtocolError("EXTENDCIRCUIT returned unexpected response code: %s" % response.code)
+ if not response.message.startswith("EXTENDED "):
+ raise stem.ProtocolError("EXTENDCIRCUIT response invalid:\n%s", response)
+
+ new_circuit = response.message.split(" ", 1)[1]
+
if await_build:
while True:
circ = circ_queue.get()
More information about the tor-commits
mailing list