Make compatible with requests 2.29.0 and urllib3 2.0 (#613)

* Make compatible with requests 2.29.0.

* This fix should also work with urllib3 2.0 according to urllib3 maintainer.

* Add changelog fragment.

* We still need the constraint for CI until Docker SDK for Python has a new release with a fix.

* Make modifications to response_class as small as possible.

* Revert "We still need the constraint for CI until Docker SDK for Python has a new release with a fix."

This reverts commit 698d544a1e08308e8bf8b4e56ab78c5079f9a17b.

* The pip coming with the ansible-core 2.11 alpine3 image seems to be too old.
This commit is contained in:
Felix Fontein
2023-05-05 22:09:02 +02:00
committed by GitHub
parent 5a26eee6d4
commit 39f2e9b9c4
10 changed files with 36 additions and 38 deletions
@@ -10,24 +10,18 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.module_utils.six import PY3
from ansible.module_utils.six.moves.queue import Empty
from .. import constants
from .._import_helper import HTTPAdapter, urllib3
from .._import_helper import HTTPAdapter, urllib3, urllib3_connection
from .basehttpadapter import BaseHTTPAdapter
from .npipesocket import NpipeSocket
if PY3:
import http.client as httplib
else:
import httplib
RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer
class NpipeHTTPConnection(httplib.HTTPConnection, object):
class NpipeHTTPConnection(urllib3_connection.HTTPConnection, object):
def __init__(self, npipe_path, timeout=60):
super(NpipeHTTPConnection, self).__init__(
'localhost', timeout=timeout
@@ -24,12 +24,7 @@ from ansible.module_utils.six.moves.urllib_parse import urlparse
from .basehttpadapter import BaseHTTPAdapter
from .. import constants
if PY3:
import http.client as httplib
else:
import httplib
from .._import_helper import HTTPAdapter, urllib3
from .._import_helper import HTTPAdapter, urllib3, urllib3_connection
PARAMIKO_IMPORT_ERROR = None
try:
@@ -120,7 +115,7 @@ class SSHSocket(socket.socket):
self.proc.terminate()
class SSHConnection(httplib.HTTPConnection, object):
class SSHConnection(urllib3_connection.HTTPConnection, object):
def __init__(self, ssh_transport=None, timeout=60, host=None):
super(SSHConnection, self).__init__(
'localhost', timeout=timeout
@@ -13,29 +13,17 @@ __metaclass__ = type
import socket
from ansible.module_utils.six import PY2
from ansible.module_utils.six.moves import http_client as httplib
from .basehttpadapter import BaseHTTPAdapter
from .. import constants
from .._import_helper import HTTPAdapter, urllib3
from .._import_helper import HTTPAdapter, urllib3, urllib3_connection
RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer
class UnixHTTPResponse(httplib.HTTPResponse, object):
def __init__(self, sock, *args, **kwargs):
disable_buffering = kwargs.pop('disable_buffering', False)
if PY2:
# FIXME: We may need to disable buffering on Py3 as well,
# but there's no clear way to do it at the moment. See:
# https://github.com/docker/docker-py/issues/1799
kwargs['buffering'] = not disable_buffering
super(UnixHTTPResponse, self).__init__(sock, *args, **kwargs)
class UnixHTTPConnection(httplib.HTTPConnection, object):
class UnixHTTPConnection(urllib3_connection.HTTPConnection, object):
def __init__(self, base_url, unix_socket, timeout=60):
super(UnixHTTPConnection, self).__init__(
@@ -58,10 +46,13 @@ class UnixHTTPConnection(httplib.HTTPConnection, object):
self.disable_buffering = True
def response_class(self, sock, *args, **kwargs):
if self.disable_buffering:
kwargs['disable_buffering'] = True
if PY2:
# FIXME: We may need to disable buffering on Py3 as well,
# but there's no clear way to do it at the moment. See:
# https://github.com/docker/docker-py/issues/1799
kwargs['buffering'] = not self.disable_buffering
return UnixHTTPResponse(sock, *args, **kwargs)
return super(UnixHTTPConnection, self).response_class(sock, *args, **kwargs)
class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):