[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Interpreter didn't print output of python commands
commit 502abce52a979b640bb71e580b1baa02c8705bd0
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat May 27 12:36:32 2017 -0700
Interpreter didn't print output of python commands
Wtf? When did we break this? Running any python command would result in no
output. Trouble was that we returned the 'output' before printing it.
---
stem/interpreter/__init__.py | 2 +-
stem/interpreter/commands.py | 10 +++++-----
test/unit/interpreter/commands.py | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/stem/interpreter/__init__.py b/stem/interpreter/__init__.py
index b5d9c49..f4ed151 100644
--- a/stem/interpreter/__init__.py
+++ b/stem/interpreter/__init__.py
@@ -171,7 +171,7 @@ def main():
interpreter.run_command(user_input, print_response = True)
except stem.SocketClosed as exc:
if showed_close_confirmation:
- print(format("Unable to run tor commands. The control connection has been closed.", *ERROR_OUTPUT))
+ print(format('Unable to run tor commands. The control connection has been closed.', *ERROR_OUTPUT))
else:
prompt = format("Tor's control port has closed. Do you want to continue this interpreter? (y/n) ", *HEADER_BOLD_OUTPUT)
user_input = input(prompt) if stem.prereq.is_python_3() else raw_input(prompt)
diff --git a/stem/interpreter/commands.py b/stem/interpreter/commands.py
index 22558aa..45f2e2c 100644
--- a/stem/interpreter/commands.py
+++ b/stem/interpreter/commands.py
@@ -359,8 +359,7 @@ class ControlInterpreter(code.InteractiveConsole):
with redirect(console_output, console_output):
self.is_multiline_context = code.InteractiveConsole.push(self, command)
- output = console_output.getvalue()
- return output if output else None
+ output = console_output.getvalue().strip()
else:
try:
output = format(self._controller.msg(command).raw_content().strip(), *STANDARD_OUTPUT)
@@ -370,9 +369,10 @@ class ControlInterpreter(code.InteractiveConsole):
else:
output = format(str(exc), *ERROR_OUTPUT)
- output += '\n' # give ourselves an extra line before the next prompt
+ if output:
+ output += '\n' # give ourselves an extra line before the next prompt
- if print_response and output is not None:
- print(output)
+ if print_response:
+ print(output)
return output
diff --git a/test/unit/interpreter/commands.py b/test/unit/interpreter/commands.py
index 717614e..59ceadf 100644
--- a/test/unit/interpreter/commands.py
+++ b/test/unit/interpreter/commands.py
@@ -118,7 +118,7 @@ class TestInterpreterCommands(unittest.TestCase):
# no received events
- self.assertEqual('\n', interpreter.run_command('/events'))
+ self.assertEqual('', interpreter.run_command('/events'))
# with enqueued events
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits