Skip to content

Commit

Permalink
deps: compatiblity with requests ≥ 2.29.0 and urllib3 2.x (#3116)
Browse files Browse the repository at this point in the history
Requirements are the same, so it's still possible to use `urllib3 < 2`
or `requests == 2.28.2` for example.

Signed-off-by: Felix Fontein <felix@fontein.de>
  • Loading branch information
felixfontein authored May 5, 2023
1 parent a02ba74 commit 3178c8d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 35 deletions.
10 changes: 3 additions & 7 deletions docker/transport/npipeconn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
from .. import constants
from .npipesocket import NpipeSocket

import http.client as httplib

try:
import requests.packages.urllib3 as urllib3
except ImportError:
import urllib3
import urllib3
import urllib3.connection

RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer


class NpipeHTTPConnection(httplib.HTTPConnection):
class NpipeHTTPConnection(urllib3.connection.HTTPConnection):
def __init__(self, npipe_path, timeout=60):
super().__init__(
'localhost', timeout=timeout
Expand Down
10 changes: 3 additions & 7 deletions docker/transport/sshconn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
from docker.transport.basehttpadapter import BaseHTTPAdapter
from .. import constants

import http.client as httplib

try:
import requests.packages.urllib3 as urllib3
except ImportError:
import urllib3
import urllib3
import urllib3.connection

RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer

Expand Down Expand Up @@ -99,7 +95,7 @@ def close(self):
self.proc.terminate()


class SSHConnection(httplib.HTTPConnection):
class SSHConnection(urllib3.connection.HTTPConnection):
def __init__(self, ssh_transport=None, timeout=60, host=None):
super().__init__(
'localhost', timeout=timeout
Expand Down
5 changes: 1 addition & 4 deletions docker/transport/ssladapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 3 additions & 12 deletions docker/transport/unixconn.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import requests.adapters
import socket
import http.client as httplib

from docker.transport.basehttpadapter import BaseHTTPAdapter
from .. import constants

try:
import requests.packages.urllib3 as urllib3
except ImportError:
import urllib3
import urllib3
import urllib3.connection


RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer


class UnixHTTPConnection(httplib.HTTPConnection):
class UnixHTTPConnection(urllib3.connection.HTTPConnection):

def __init__(self, base_url, unix_socket, timeout=60):
super().__init__(
Expand All @@ -30,12 +27,6 @@ def connect(self):
sock.connect(self.unix_socket)
self.sock = sock

def putheader(self, header, *values):
super().putheader(header, *values)

def response_class(self, sock, *args, **kwargs):
return httplib.HTTPResponse(sock, *args, **kwargs)


class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
def __init__(self, base_url, socket_path, timeout=60, maxsize=10):
Expand Down
5 changes: 1 addition & 4 deletions docker/types/daemon.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import socket

try:
import requests.packages.urllib3 as urllib3
except ImportError:
import urllib3
import urllib3

from ..errors import DockerException

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3178c8d

Please sign in to comment.