From d0f0aa9f17ad1786ac88457ca5b56222849ebe1a Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Tue, 2 Jun 2020 19:53:46 -0700 Subject: [PATCH 1/5] remove version_info based branching --- sshuttle/client.py | 7 +------ sshuttle/helpers.py | 11 +++-------- tests/client/test_helpers.py | 7 +------ tests/conftest.py | 5 +---- 4 files changed, 6 insertions(+), 24 deletions(-) diff --git a/sshuttle/client.py b/sshuttle/client.py index efdaae1..9a0f15b 100644 --- a/sshuttle/client.py +++ b/sshuttle/client.py @@ -228,12 +228,7 @@ class FirewallClient: pass self.argv = argv s1.close() - if sys.version_info < (3, 0): - # python 2.7 - self.pfile = s2.makefile('wb+') - else: - # python 3.5 - self.pfile = s2.makefile('rwb') + self.pfile = s2.makefile('rwb') if e: log('Spawning firewall manager: %r\n' % self.argv) raise Fatal(e) diff --git a/sshuttle/helpers.py b/sshuttle/helpers.py index 4a41e4e..6c8ab82 100644 --- a/sshuttle/helpers.py +++ b/sshuttle/helpers.py @@ -5,16 +5,11 @@ import errno logprefix = '' verbose = 0 -if sys.version_info[0] == 3: - binary_type = bytes +binary_type = bytes - def b(s): - return s.encode("ASCII") -else: - binary_type = str - def b(s): - return s +def b(s): + return s.encode("ASCII") def log(s): diff --git a/tests/client/test_helpers.py b/tests/client/test_helpers.py index 3a64142..3ed588f 100644 --- a/tests/client/test_helpers.py +++ b/tests/client/test_helpers.py @@ -1,4 +1,3 @@ -import sys import io import socket from socket import AF_INET, AF_INET6 @@ -193,9 +192,5 @@ def test_family_ip_tuple(): def test_family_to_string(): assert sshuttle.helpers.family_to_string(AF_INET) == "AF_INET" assert sshuttle.helpers.family_to_string(AF_INET6) == "AF_INET6" - if sys.version_info < (3, 0): - expected = "1" - assert sshuttle.helpers.family_to_string(socket.AF_UNIX) == "1" - else: - expected = 'AddressFamily.AF_UNIX' + expected = 'AddressFamily.AF_UNIX' assert sshuttle.helpers.family_to_string(socket.AF_UNIX) == expected diff --git a/tests/conftest.py b/tests/conftest.py index 2a7e6c5..95052f1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,6 @@ import sys -if sys.version_info >= (3, 0): - good_python = sys.version_info >= (3, 5) -else: - good_python = sys.version_info >= (2, 7) +good_python = sys.version_info >= (3, 5) collect_ignore = [] if not good_python: From 9bcca27965a20e45c6f9b806fa982a8e363f44df Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Tue, 2 Jun 2020 19:56:34 -0700 Subject: [PATCH 2/5] reduce --- sshuttle/helpers.py | 2 -- sshuttle/ssnet.py | 4 ++-- tests/conftest.py | 7 ------- 3 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 tests/conftest.py diff --git a/sshuttle/helpers.py b/sshuttle/helpers.py index 6c8ab82..a62bea9 100644 --- a/sshuttle/helpers.py +++ b/sshuttle/helpers.py @@ -5,8 +5,6 @@ import errno logprefix = '' verbose = 0 -binary_type = bytes - def b(s): return s.encode("ASCII") diff --git a/sshuttle/ssnet.py b/sshuttle/ssnet.py index e7f668b..7604093 100644 --- a/sshuttle/ssnet.py +++ b/sshuttle/ssnet.py @@ -5,7 +5,7 @@ import errno import select import os -from sshuttle.helpers import b, binary_type, log, debug1, debug2, debug3, Fatal +from sshuttle.helpers import b, log, debug1, debug2, debug3, Fatal MAX_CHANNEL = 65535 LATENCY_BUFFER_SIZE = 32768 @@ -382,7 +382,7 @@ class Mux(Handler): # log('outbuf: %d %r\n' % (self.amount_queued(), ob)) def send(self, channel, cmd, data): - assert isinstance(data, binary_type) + assert isinstance(data, bytes) assert len(data) <= 65535 p = struct.pack('!ccHHH', b('S'), b('S'), channel, cmd, len(data)) \ + data diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index 95052f1..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,7 +0,0 @@ -import sys - -good_python = sys.version_info >= (3, 5) - -collect_ignore = [] -if not good_python: - collect_ignore.append("client") From bef54e778d87dacc9baefeb7c71318cf1d5e233d Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Tue, 2 Jun 2020 20:01:02 -0700 Subject: [PATCH 3/5] remove ImportError based branching --- sshuttle/ssh.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/sshuttle/ssh.py b/sshuttle/ssh.py index 464e92c..5c968f0 100644 --- a/sshuttle/ssh.py +++ b/sshuttle/ssh.py @@ -6,24 +6,13 @@ import zlib import imp import subprocess as ssubprocess import shlex +from shlex import quote import ipaddress - -# ensure backwards compatiblity with python2.7 -try: - from urllib.parse import urlparse -except ImportError: - from urlparse import urlparse +from urllib.parse import urlparse import sshuttle.helpers as helpers from sshuttle.helpers import debug2 -try: - # Python >= 3.5 - from shlex import quote -except ImportError: - # Python 2.x - from pipes import quote - def readfile(name): tokens = name.split(".") From 1db3281c168e4d87b3640443fd3e9b1afaed6809 Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Tue, 2 Jun 2020 20:01:37 -0700 Subject: [PATCH 4/5] shutil.which is 3.3+ --- sshuttle/server.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sshuttle/server.py b/sshuttle/server.py index 37f942a..3234659 100644 --- a/sshuttle/server.py +++ b/sshuttle/server.py @@ -6,6 +6,7 @@ import time import sys import os import platform +from shutil import which import sshuttle.ssnet as ssnet import sshuttle.helpers as helpers @@ -15,11 +16,6 @@ from sshuttle.ssnet import Handler, Proxy, Mux, MuxWrapper from sshuttle.helpers import b, log, debug1, debug2, debug3, Fatal, \ resolvconf_random_nameserver -try: - from shutil import which -except ImportError: - from distutils.spawn import find_executable as which - def _ipmatch(ipstr): # FIXME: IPv4 only From d058d9bc935d93985427da260a4a1795e189cd80 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 3 Jun 2020 08:34:57 +0000 Subject: [PATCH 5/5] Bump pytest from 5.4.2 to 5.4.3 Bumps [pytest](https://github.com/pytest-dev/pytest) from 5.4.2 to 5.4.3. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/5.4.2...5.4.3) Signed-off-by: dependabot-preview[bot] --- requirements-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index a20bccb..8221a09 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,6 +1,6 @@ -r requirements.txt attrs==19.3.0 -pytest==5.4.2 +pytest==5.4.3 pytest-cov==2.9.0 mock==2.0.0 flake8==3.8.2