"""
import socket as _socket
+import sys as _sys
try: # Python 3
import urllib.parse as _urllib_parse
except ImportError: # Python 2
if not r:
break
ret.append(r)
- return ''.join(ret)
+ return b''.join(ret)
def request(socket, data=None, **kwargs):
"""Send a request and return the response string."""
- socket.sendall(netstring(header(data=data, **kwargs)))
+ ns = netstring(header(data=data, **kwargs))
+ if _sys.version_info >= (3, 0): # Python 3
+ ns = ns.encode('ascii')
+ socket.sendall(ns)
if data:
socket.sendall(data)
return recvall(socket)
finally:
socket.close()
if response:
- sys.stdout.write(response)
+ if _sys.version_info >= (3, 0): # Python 3
+ sys.stdout.buffer.write(response)
+ else:
+ sys.stdout.write(response)