diff options
-rw-r--r-- | netlib/tcp.py | 8 | ||||
-rw-r--r-- | test/test_socks.py | 2 | ||||
-rw-r--r-- | test/test_tcp.py | 20 |
3 files changed, 16 insertions, 14 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py index 6dcc8c72..f6f7d06f 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -7,6 +7,8 @@ import threading import time import traceback +from six.moves import range + import certifi import six import OpenSSL @@ -227,7 +229,7 @@ class Reader(_FileLike): return result def readline(self, size=None): - result = '' + result = b'' bytes_read = 0 while True: if size is not None and bytes_read >= size: @@ -399,7 +401,7 @@ def close_socket(sock): sock.settimeout(sock.gettimeout() or 20) # limit at a megabyte so that we don't read infinitely - for _ in xrange(1024 ** 3 // 4096): + for _ in range(1024 ** 3 // 4096): # may raise a timeout/disconnect exception. if not sock.recv(4096): break @@ -649,7 +651,7 @@ class TCPClient(_Connection): if OpenSSL._util.lib.Cryptography_HAS_ALPN and self.ssl_established: return self.connection.get_alpn_proto_negotiated() else: - return "" + return b"" class BaseHandler(_Connection): diff --git a/test/test_socks.py b/test/test_socks.py index dd8e2807..d95dee41 100644 --- a/test/test_socks.py +++ b/test/test_socks.py @@ -121,7 +121,7 @@ def test_message_ipv4(): def test_message_ipv6(): # Test ATYP=0x04 (IPV6) - ipv6_addr = "2001:db8:85a3:8d3:1319:8a2e:370:7344" + ipv6_addr = u"2001:db8:85a3:8d3:1319:8a2e:370:7344" raw = tutils.treader( b"\x05\x01\x00\x04" + diff --git a/test/test_tcp.py b/test/test_tcp.py index dc0efeb0..725aa8b0 100644 --- a/test/test_tcp.py +++ b/test/test_tcp.py @@ -49,9 +49,9 @@ class ALPNHandler(tcp.BaseHandler): def handle(self): alp = self.get_alpn_proto_negotiated() if alp: - self.wfile.write("%s" % alp) + self.wfile.write(("%s" % alp).encode("ascii")) else: - self.wfile.write("NONE") + self.wfile.write(b"NONE") self.wfile.flush() @@ -503,24 +503,24 @@ class TestALPNClient(tservers.ServerTestBase): def test_alpn(self): c = tcp.TCPClient(("127.0.0.1", self.port)) c.connect() - c.convert_to_ssl(alpn_protos=["foo", "bar", "fasel"]) - assert c.get_alpn_proto_negotiated() == "bar" - assert c.rfile.readline().strip() == "bar" + c.convert_to_ssl(alpn_protos=[b"foo", b"bar", b"fasel"]) + assert c.get_alpn_proto_negotiated() == b"bar" + assert c.rfile.readline().strip() == b"bar" def test_no_alpn(self): c = tcp.TCPClient(("127.0.0.1", self.port)) c.connect() c.convert_to_ssl() - assert c.get_alpn_proto_negotiated() == "" - assert c.rfile.readline().strip() == "NONE" + assert c.get_alpn_proto_negotiated() == b"" + assert c.rfile.readline().strip() == b"NONE" else: def test_none_alpn(self): c = tcp.TCPClient(("127.0.0.1", self.port)) c.connect() - c.convert_to_ssl(alpn_protos=["foo", "bar", "fasel"]) - assert c.get_alpn_proto_negotiated() == "" - assert c.rfile.readline() == "NONE" + c.convert_to_ssl(alpn_protos=[b"foo", b"bar", b"fasel"]) + assert c.get_alpn_proto_negotiated() == b"" + assert c.rfile.readline() == b"NONE" class TestNoSSLNoALPNClient(tservers.ServerTestBase): |