commit c2b92450016ccfbe46edec151136c8a8a9f694cb Author: Damian Johnson atagar@torproject.org Date: Sun Jan 27 18:18:45 2013 -0800
Disabling newline translation in our socket
In python 3 the socket file object tries to be helpful by translating newline characters. By default '\n', '\r', and '\r\n' are all translated to '\n'. Tor uses '\r\n' newlines and we check for this so disabling universal newline translation.
====================================================================== ERROR: test_get_pid_by_port_netstat ---------------------------------------------------------------------- Traceback: File "/home/atagar/Desktop/stem/test/data/python3/stem/connection.py", line 321, in authenticate protocolinfo_response = get_protocolinfo(controller) File "/home/atagar/Desktop/stem/test/data/python3/stem/connection.py", line 800, in get_protocolinfo protocolinfo_response = _msg(controller, "PROTOCOLINFO 1") File "/home/atagar/Desktop/stem/test/data/python3/stem/connection.py", line 837, in _msg return controller.recv() File "/home/atagar/Desktop/stem/test/data/python3/stem/socket.py", line 114, in recv return recv_message(socket_file) File "/home/atagar/Desktop/stem/test/data/python3/stem/socket.py", line 511, in recv_message raise stem.ProtocolError("All lines should end with CRLF") stem.ProtocolError: All lines should end with CRLF
During handling of the above exception, another exception occurred:
Traceback: File "/home/atagar/Desktop/stem/test/data/python3/test/integ/util/system.py", line 245, in test_get_pid_by_port_netstat elif not runner.is_ptraceable(): File "/home/atagar/Desktop/stem/test/data/python3/test/runner.py", line 413, in is_ptraceable tor_version = self.get_tor_version() File "/home/atagar/Desktop/stem/test/data/python3/test/runner.py", line 567, in get_tor_version control_socket = self.get_tor_socket() File "/home/atagar/Desktop/stem/test/data/python3/test/runner.py", line 534, in get_tor_socket stem.connection.authenticate(control_socket, CONTROL_PASSWORD, self.get_chroot()) File "/home/atagar/Desktop/stem/test/data/python3/stem/connection.py", line 323, in authenticate raise IncorrectSocketType("unable to use the control socket") stem.connection.IncorrectSocketType: unable to use the control socket --- stem/socket.py | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/stem/socket.py b/stem/socket.py index cad4572..f0786ab 100644 --- a/stem/socket.py +++ b/stem/socket.py @@ -35,6 +35,7 @@ import re import socket import threading
+import stem.prereq import stem.response
from stem.util import log @@ -181,7 +182,12 @@ class ControlSocket(object):
with self._recv_lock: self._socket = self._make_socket() - self._socket_file = self._socket.makefile(mode = "rw") + + if stem.prereq.is_python_3(): + self._socket_file = self._socket.makefile(mode = "rw", newline = "") + else: + self._socket_file = self._socket.makefile(mode = "rw") + self._is_alive = True
# It's possible for this to have a transient failure...