From 32fdf9969917fe31e6c6c3e19b6d422531088b2b Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 2 May 2023 18:40:35 +0200 Subject: [PATCH] Simplify imports since requests >= 2.16.0 no longer uses vendored urllib3. --- docker/transport/npipeconn.py | 10 +++------- docker/transport/sshconn.py | 10 +++------- docker/transport/ssladapter.py | 5 +---- docker/transport/unixconn.py | 10 +++------- docker/types/daemon.py | 5 +---- tests/unit/api_test.py | 2 +- 6 files changed, 12 insertions(+), 30 deletions(-) diff --git a/docker/transport/npipeconn.py b/docker/transport/npipeconn.py index 41555da01..45988b2df 100644 --- a/docker/transport/npipeconn.py +++ b/docker/transport/npipeconn.py @@ -5,17 +5,13 @@ from .. import constants from .npipesocket import NpipeSocket -try: - import requests.packages.urllib3 as urllib3 - import requests.packages.urllib3.connection as urllib3_connection -except ImportError: - import urllib3 - import urllib3.connection as urllib3_connection +import urllib3 +import urllib3.connection RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer -class NpipeHTTPConnection(urllib3_connection.HTTPConnection): +class NpipeHTTPConnection(urllib3.connection.HTTPConnection): def __init__(self, npipe_path, timeout=60): super().__init__( 'localhost', timeout=timeout diff --git a/docker/transport/sshconn.py b/docker/transport/sshconn.py index 8c2622043..a92beb621 100644 --- a/docker/transport/sshconn.py +++ b/docker/transport/sshconn.py @@ -11,12 +11,8 @@ from docker.transport.basehttpadapter import BaseHTTPAdapter from .. import constants -try: - import requests.packages.urllib3 as urllib3 - import requests.packages.urllib3.connection as urllib3_connection -except ImportError: - import urllib3 - import urllib3.connection as urllib3_connection +import urllib3 +import urllib3.connection RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer @@ -99,7 +95,7 @@ def close(self): self.proc.terminate() -class SSHConnection(urllib3_connection.HTTPConnection): +class SSHConnection(urllib3.connection.HTTPConnection): def __init__(self, ssh_transport=None, timeout=60, host=None): super().__init__( 'localhost', timeout=timeout diff --git a/docker/transport/ssladapter.py b/docker/transport/ssladapter.py index 6aa80037d..69274bd1d 100644 --- a/docker/transport/ssladapter.py +++ b/docker/transport/ssladapter.py @@ -7,10 +7,7 @@ from docker.transport.basehttpadapter import BaseHTTPAdapter -try: - import requests.packages.urllib3 as urllib3 -except ImportError: - import urllib3 +import urllib3 PoolManager = urllib3.poolmanager.PoolManager diff --git a/docker/transport/unixconn.py b/docker/transport/unixconn.py index 333d01a17..15c175b96 100644 --- a/docker/transport/unixconn.py +++ b/docker/transport/unixconn.py @@ -5,18 +5,14 @@ from docker.transport.basehttpadapter import BaseHTTPAdapter from .. import constants -try: - import requests.packages.urllib3 as urllib3 - import requests.packages.urllib3.connection as urllib3_connection -except ImportError: - import urllib3 - import urllib3.connection as urllib3_connection +import urllib3 +import urllib3.connection RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer -class UnixHTTPConnection(urllib3_connection.HTTPConnection): +class UnixHTTPConnection(urllib3.connection.HTTPConnection): def __init__(self, base_url, unix_socket, timeout=60): super().__init__( diff --git a/docker/types/daemon.py b/docker/types/daemon.py index 10e810144..096b2cc16 100644 --- a/docker/types/daemon.py +++ b/docker/types/daemon.py @@ -1,9 +1,6 @@ import socket -try: - import requests.packages.urllib3 as urllib3 -except ImportError: - import urllib3 +import urllib3 from ..errors import DockerException diff --git a/tests/unit/api_test.py b/tests/unit/api_test.py index a2348f08b..4b6099c90 100644 --- a/tests/unit/api_test.py +++ b/tests/unit/api_test.py @@ -16,9 +16,9 @@ import docker import pytest import requests +import urllib3 from docker.api import APIClient from docker.constants import DEFAULT_DOCKER_API_VERSION -from requests.packages import urllib3 from unittest import mock from . import fake_api