Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions TorCtl/TorCtl.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import time
import copy

from io import IOBase

from TorUtil import *

if sys.version_info < (2, 5):
Expand Down Expand Up @@ -867,7 +869,7 @@ def _doSend(self, msg):
if len(lines) > 2:
amsg = "\n".join(lines[:2]) + "\n"
self._debugFile.write(str(time.time())+"\t>>> "+amsg)
self._s.write(msg)
self._s.write(msg.encode())

def set_timer(self, in_seconds, type=None):
event = (("650", "TORCTL_TIMER", type),)
Expand Down Expand Up @@ -929,7 +931,7 @@ def authenticate(self, secret=""):
elif self._authType == AUTH_TYPE.PASSWORD:
self.authenticate_password(secret)
else:
authCookie = open(self._cookiePath, "r")
authCookie = open(self._cookiePath, "rb")
self.authenticate_cookie(authCookie)
authCookie.close()
except ErrorReply, exc:
Expand Down Expand Up @@ -973,10 +975,10 @@ def authenticate_cookie(self, cookie):
"""

# read contents if provided a file
if type(cookie) == file: cookie = cookie.read()
if isinstance(cookie, IOBase): cookie = cookie.read()

# unlike passwords the cookie contents isn't enclosed by quotes
self.sendAndRecv("AUTHENTICATE %s\r\n" % binascii.b2a_hex(cookie))
self.sendAndRecv("AUTHENTICATE %s\r\n" % binascii.b2a_hex(cookie).decode())

def get_option(self, name):
"""Get the value of the configuration option named 'name'. To
Expand Down
2 changes: 1 addition & 1 deletion TorCtl/TorUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def readline(self):
return result

while 1:
s = self._s.recv(128)
s = self._s.recv(128).decode('utf-8')
if not s: return None
# XXX: This really does need an exception
# raise ConnectionClosed()
Expand Down