Skip to content

Commit

Permalink
Fix python2 server compatibility
Browse files Browse the repository at this point in the history
Fixes  sshuttle#469. We replace python3 exclusive code with a check for python3 and a compatibility fix. Note that the switch from os.set_nonblocking to fcntl.fcntl in 98d052d (fixing sshuttle#503) also fixes python2 compatibility.
  • Loading branch information
drjbarker committed Aug 28, 2020
1 parent e8f3b53 commit c12d2ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
7 changes: 5 additions & 2 deletions sshuttle/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
while 1:
name = sys.stdin.readline().strip()
if name:
name = name.decode("ASCII")

# python2 compat: in python2 sys.stdin.readline().strip() -> str
# in python3 sys.stdin.readline().strip() -> bytes
# (see #481)
if sys.version_info >= (3, 0):
name = name.decode("ASCII")
nbytes = int(sys.stdin.readline())
if verbosity >= 2:
sys.stderr.write('server: assembling %r (%d bytes)\n'
Expand Down
19 changes: 18 additions & 1 deletion sshuttle/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,24 @@
import sys
import os
import platform
from shutil import which

if sys.version_info >= (3, 0):
from shutil import which
else:
# python2 compat: shutil.which is not available so we provide our own which command
def which(file, mode=os.F_OK | os.X_OK, path=None):
if path is not None:
search_paths = [path]
elif "PATH" in os.environ:
search_paths = os.environ["PATH"].split(os.pathsep)
else:
search_paths = os.defpath.split(os.pathsep)

for path in search_paths:
filepath = os.path.join(path, file)
if os.path.exists(filepath) and os.access(filepath, mode):
return filepath
return None

import sshuttle.ssnet as ssnet
import sshuttle.helpers as helpers
Expand Down

0 comments on commit c12d2ba

Please sign in to comment.