Skip to content

Commit 02fa496

Browse files
committed
Fix server side Python3 issues.
Closes: apenwarr#49.
1 parent ce51871 commit 02fa496

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

sshuttle/assembler.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
z = zlib.decompressobj()
66
while 1:
7-
name = sys.stdin.readline().strip()
7+
name = stdin.readline().strip()
88
if name:
9-
nbytes = int(sys.stdin.readline())
9+
name = name.decode("ASCII")
10+
11+
nbytes = int(stdin.readline())
1012
if verbosity >= 2:
1113
sys.stderr.write('server: assembling %r (%d bytes)\n'
1214
% (name, nbytes))
13-
content = z.decompress(sys.stdin.read(nbytes))
15+
content = z.decompress(stdin.read(nbytes))
1416

1517
module = imp.new_module(name)
1618
parent, _, parent_name = name.rpartition(".")

sshuttle/server.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@
1717

1818

1919
def _ipmatch(ipstr):
20-
if ipstr == 'default':
21-
ipstr = '0.0.0.0/0'
22-
m = re.match(r'^(\d+(\.\d+(\.\d+(\.\d+)?)?)?)(?:/(\d+))?$', ipstr)
20+
if ipstr == b'default':
21+
ipstr = b'0.0.0.0/0'
22+
m = re.match(b'^(\d+(\.\d+(\.\d+(\.\d+)?)?)?)(?:/(\d+))?$', ipstr)
2323
if m:
2424
g = m.groups()
2525
ips = g[0]
2626
width = int(g[4] or 32)
2727
if g[1] is None:
28-
ips += '.0.0.0'
28+
ips += b'.0.0.0'
2929
width = min(width, 8)
3030
elif g[2] is None:
31-
ips += '.0.0'
31+
ips += b'.0.0'
3232
width = min(width, 16)
3333
elif g[3] is None:
34-
ips += '.0'
34+
ips += b'.0'
3535
width = min(width, 24)
36+
ips = ips.decode("ASCII")
3637
return (struct.unpack('!I', socket.inet_aton(ips))[0], width)
3738

3839

@@ -61,7 +62,7 @@ def _list_routes():
6162
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE)
6263
routes = []
6364
for line in p.stdout:
64-
cols = re.split(r'\s+', line)
65+
cols = re.split(b'\s+', line)
6566
ipw = _ipmatch(cols[0])
6667
if not ipw:
6768
continue # some lines won't be parseable; never mind
@@ -239,9 +240,9 @@ def main(latency_control):
239240
socket.fromfd(sys.stdout.fileno(),
240241
socket.AF_INET, socket.SOCK_STREAM))
241242
handlers.append(mux)
242-
routepkt = ''
243+
routepkt = b''
243244
for r in routes:
244-
routepkt += '%d,%s,%d\n' % r
245+
routepkt += b'%d,%s,%d\n' % (r[0], r[1].encode("ASCII"), r[2])
245246
mux.send(0, ssnet.CMD_ROUTES, routepkt)
246247

247248
hw = Hostwatch()
@@ -270,7 +271,7 @@ def got_host_req(data):
270271
mux.got_host_req = got_host_req
271272

272273
def new_channel(channel, data):
273-
(family, dstip, dstport) = data.split(',', 2)
274+
(family, dstip, dstport) = data.split(b',', 2)
274275
family = int(family)
275276
dstport = int(dstport)
276277
outwrap = ssnet.connect_dst(family, dstip, dstport)

sshuttle/ssh.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def connect(ssh_cmd, rhostport, python, stderr, options):
9191
pyscript = r"""
9292
import sys;
9393
verbosity=%d;
94-
exec(compile(sys.stdin.read(%d), "assembler.py", "exec"))
94+
stdin=getattr(sys.stdin,"buffer",sys.stdin);
95+
exec(compile(stdin.read(%d), "assembler.py", "exec"))
9596
""" % (helpers.verbose or 0, len(content))
9697
pyscript = re.sub(r'\s+', ' ', pyscript.strip())
9798

0 commit comments

Comments
 (0)