commit 620efe453c30f47c784f5df287d2aea74f6e8dc4 Author: Nick Mathewson nickm@torproject.org Date: Thu Feb 28 13:09:25 2019 -0500
Python3: Various bytes/unicode fixes --- lib/chutney/Traffic.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/lib/chutney/Traffic.py b/lib/chutney/Traffic.py index 7b3e6d4..766766a 100644 --- a/lib/chutney/Traffic.py +++ b/lib/chutney/Traffic.py @@ -41,15 +41,17 @@ def socks_cmd(addr_port): """ ver = 4 # Only SOCKSv4 for now. cmd = 1 # Stream connection. - user = '\x00' + user = b'\x00' dnsname = '' host, port = addr_port try: addr = socket.inet_aton(host) except socket.error: - addr = '\x00\x00\x00\x01' + addr = b'\x00\x00\x00\x01' dnsname = '%s\x00' % host debug("Socks 4a request to %s:%d" % (host, port)) + if type(dnsname) != type(b""): + dnsname = dnsname.encode("ascii") return struct.pack('!BBH', ver, cmd, port) + addr + user + dnsname
@@ -133,7 +135,7 @@ class Sink(Peer):
def __init__(self, tt, s): super(Sink, self).__init__(Peer.SINK, tt, s) - self.inbuf = '' + self.inbuf = b'' self.repetitions = self.tt.repetitions
def on_readable(self): @@ -193,8 +195,8 @@ class Source(Peer): super(Source, self).__init__(Peer.SOURCE, tt) self.state = self.NOT_CONNECTED self.data = buf - self.outbuf = '' - self.inbuf = '' + self.outbuf = b'' + self.inbuf = b'' self.proxy = proxy self.repetitions = repetitions self._sent_no_bytes = 0 @@ -229,10 +231,10 @@ class Source(Peer): return -1 self.inbuf += inp if len(self.inbuf) == 8: - if ord(self.inbuf[0]) == 0 and ord(self.inbuf[1]) == 0x5a: + if self.inbuf[:2] == b'\x00\x5a': debug("proxy handshake successful (fd=%d)" % self.fd()) self.state = self.CONNECTED - self.inbuf = '' + self.inbuf = b'' debug("successfully connected (fd=%d)" % self.fd()) # if we have no reps or no data, skip sending actual data if self.want_to_write():
tor-commits@lists.torproject.org