[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Interpreter constructed its own connection
commit eb28072d925b548913e17e3f7c7cb548395d6d29
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Thu Jul 21 09:45:27 2016 -0700
Interpreter constructed its own connection
No, just no. >:(
No clue why Sambuddha did this. Constructing a separate connection is bad for
several reasons...
1. The interpreter only works if tor is running on the default port. Anything
else and it's hosed.
2. The stem.connect() prints to stdout and gets passwords from stdin. That
means nyx is completely hosed in several situations since we're in a
curses context and that'll freeze or screw up our interface.
3. This second connection is completely pointless. Nyx has a controller
connection - it's used everywhere. Why did this seem like a good idea?
4. It completely broke our tests if tor isn't presently running on the
expected port.
5. If tor shuts down and is restarted this won't get the new connection when
nyx reattaches.
---
nyx/panel/interpreter.py | 14 +++++---------
test/panel/interpreter.py | 18 ++++++++++++++----
2 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/nyx/panel/interpreter.py b/nyx/panel/interpreter.py
index dfd7480..7775028 100644
--- a/nyx/panel/interpreter.py
+++ b/nyx/panel/interpreter.py
@@ -13,10 +13,9 @@ import sys
from cStringIO import StringIO
from mock import patch
from nyx.curses import BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, BOLD, HIGHLIGHT, NORMAL
-from nyx import panel
+from nyx import tor_controller, panel
import stem
-import stem.connection
import stem.interpreter.autocomplete
import stem.interpreter.commands
@@ -74,13 +73,10 @@ class InterpreterPanel(panel.Panel):
self._x_offset = 0
self._scroller = nyx.curses.Scroller()
self._backlog = []
- self.controller = stem.connection.connect(
- control_port = ('127.0.0.1', 'default'),
- control_socket = '/var/run/tor/control',
- password_prompt = True,
- )
- self.autocompleter = stem.interpreter.autocomplete.Autocompleter(self.controller)
- self.interpreter = stem.interpreter.commands.ControlInterpretor(self.controller)
+
+ controller = tor_controller()
+ self.autocompleter = stem.interpreter.autocomplete.Autocompleter(controller)
+ self.interpreter = stem.interpreter.commands.ControlInterpretor(controller)
self.prompt_line = [[(PROMPT, GREEN, BOLD), (USAGE_INFO, CYAN, BOLD)]]
def key_handlers(self):
diff --git a/test/panel/interpreter.py b/test/panel/interpreter.py
index 5383777..8283c5e 100644
--- a/test/panel/interpreter.py
+++ b/test/panel/interpreter.py
@@ -8,6 +8,8 @@ import nyx.curses
import nyx.panel.interpreter
import test
+from mock import patch
+
EXPECTED_PANEL = """
Control Interpreter:
>>> to use this panel press enter
@@ -57,20 +59,26 @@ class TestInterpreter(unittest.TestCase):
self.assertEqual(('>>> ', 'Green', 'Bold'), output[0])
self.assertEqual(('/help', 'Magenta', 'Bold'), output[1])
- def test_rendering_panel(self):
+ @patch('nyx.panel.interpreter.tor_controller')
+ def test_rendering_panel(self, tor_controller_mock):
+ tor_controller_mock()._handle_event = lambda event: None
panel = nyx.panel.interpreter.InterpreterPanel()
self.assertEqual(EXPECTED_PANEL, test.render(panel._draw).content)
panel._is_input_mode = True
self.assertEqual(EXPECTED_PANEL_INPUT_MODE, test.render(panel._draw).content)
- def test_rendering_multiline_panel(self):
+ @patch('nyx.panel.interpreter.tor_controller')
+ def test_rendering_multiline_panel(self, tor_controller_mock):
+ tor_controller_mock()._handle_event = lambda event: None
panel = nyx.panel.interpreter.InterpreterPanel()
panel.prompt_line = [[('>>> ', 'Green', 'Bold'), ('GETINFO', 'Green', 'Bold'), (' version', 'Cyan')]]
panel.prompt_line.append([('250-version=0.2.4.27 (git-412e3f7dc9c6c01a)', 'Blue')])
self.assertEqual(EXPECTED_MULTILINE_PANEL, test.render(panel._draw).content)
- def test_scrollbar(self):
+ @patch('nyx.panel.interpreter.tor_controller')
+ def test_scrollbar(self, tor_controller_mock):
+ tor_controller_mock()._handle_event = lambda event: None
panel = nyx.panel.interpreter.InterpreterPanel()
self.assertIsInstance(panel._scroller, nyx.curses.Scroller)
@@ -80,7 +88,9 @@ class TestInterpreter(unittest.TestCase):
self.assertEqual(height, len(output_lines))
self.assertEqual(EXPECTED_SCROLLBAR_PANEL, output_lines[1])
- def test_key_handlers(self):
+ @patch('nyx.panel.interpreter.tor_controller')
+ def test_key_handlers(self, tor_controller_mock):
+ tor_controller_mock()._handle_event = lambda event: None
panel = nyx.panel.interpreter.InterpreterPanel()
output = panel.key_handlers()
self.assertEqual(2, len(output))
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits