summaryrefslogtreecommitdiffstats
path: root/sshuttle/helpers.py
diff options
context:
space:
mode:
authorvieira <vieira@yubo.be>2015-12-05 03:40:26 +0000
committerBrian May <brian@linuxpenguins.xyz>2016-04-03 13:14:02 +1000
commit4241381d827ca42fd40b6a4bc5a4e2fdde92577b (patch)
tree1406e21383f796307e98f7b3242d1094972bc253 /sshuttle/helpers.py
parent6e15e690295ee6d17d1ab64b85f0adebb7e3ac7a (diff)
Backward compatibility with Python 2.4 (server)
It is often the case that the user has no administrative control over the server that is being used. As such it is important to support as many versions as possible, at least on the remote server end. These fixes will allow sshuttle to be used with servers that have only python 2.4 or python 2.6 installed while hopefully not breaking the compatibility with 2.7 and 3.5.
Diffstat (limited to 'sshuttle/helpers.py')
-rw-r--r--sshuttle/helpers.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/sshuttle/helpers.py b/sshuttle/helpers.py
index 4e80e33..67a6013 100644
--- a/sshuttle/helpers.py
+++ b/sshuttle/helpers.py
@@ -5,6 +5,16 @@ import errno
logprefix = ''
verbose = 0
+if sys.version_info[0] == 3:
+ binary_type = bytes
+
+ def b(s):
+ return s.encode("ASCII")
+else:
+ binary_type = str
+
+ def b(s):
+ return s
def log(s):
global logprefix
@@ -70,7 +80,8 @@ def islocal(ip, family):
try:
try:
sock.bind((ip, 0))
- except socket.error as e:
+ except socket.error:
+ _, e = sys.exc_info()[:2]
if e.args[0] == errno.EADDRNOTAVAIL:
return False # not a local IP
else: