From 01e91592ac2e08946fa82ff8bc2dac5b9f808664 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 2 May 2023 15:15:14 +0200 Subject: [PATCH] Make compatible with requests 2.29.0. --- README.md | 2 +- meta/ee-requirements.txt | 2 +- plugins/doc_fragments/docker.py | 2 +- plugins/module_utils/_api/_import_helper.py | 7 +++++++ plugins/module_utils/_api/transport/npipeconn.py | 10 ++-------- plugins/module_utils/_api/transport/sshconn.py | 9 ++------- plugins/module_utils/_api/transport/unixconn.py | 4 ++-- tests/utils/constraints.txt | 1 - 8 files changed, 16 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 681c6ebb8..e82e0a8ed 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Some modules and plugins require Docker CLI, or other external, programs. Some r Installing the Docker SDK for Python also installs the requirements for the modules and plugins that use `requests`. If you want to directly install the Python libraries instead of the SDK, you need the following ones: -- [requests](https://pypi.org/project/requests/) (versions before 2.29.0); +- [requests](https://pypi.org/project/requests/); - [pywin32](https://pypi.org/project/pywin32/) when using named pipes on Windows with the Windows 32 API; - [paramiko](https://pypi.org/project/paramiko/) when using SSH to connect to the Docker daemon with `use_ssh_client=false`; - [pyOpenSSL](https://pypi.org/project/pyOpenSSL/) when using TLS to connect to the Docker daemon; diff --git a/meta/ee-requirements.txt b/meta/ee-requirements.txt index 565b1113e..ea3286bb3 100644 --- a/meta/ee-requirements.txt +++ b/meta/ee-requirements.txt @@ -4,7 +4,7 @@ docker urllib3 < 2.0 # TODO see https://github.com/ansible-collections/community.docker/issues/611 -requests < 2.29 # TODO see https://github.com/ansible-collections/community.docker/issues/611 +requests paramiko # We assume that EEs are not based on Windows, and have Python >= 3.5. diff --git a/plugins/doc_fragments/docker.py b/plugins/doc_fragments/docker.py index 71ed5807f..4c537850e 100644 --- a/plugins/doc_fragments/docker.py +++ b/plugins/doc_fragments/docker.py @@ -289,7 +289,7 @@ class ModuleDocFragment(object): communicate with the Docker daemon. It uses code derived from the Docker SDK or Python that is included in this collection. requirements: - - requests < 2.29.0 (see U(https://github.com/ansible-collections/community.docker/issues/611)) + - requests - pywin32 (when using named pipes on Windows 32) - paramiko (when using SSH with I(use_ssh_client=false)) - pyOpenSSL (when using TLS) diff --git a/plugins/module_utils/_api/_import_helper.py b/plugins/module_utils/_api/_import_helper.py index f3ea504c9..3c8b696e5 100644 --- a/plugins/module_utils/_api/_import_helper.py +++ b/plugins/module_utils/_api/_import_helper.py @@ -42,9 +42,11 @@ class InvalidSchema(Exception): try: from requests.packages import urllib3 + from requests.packages.urllib3 import connection as urllib3_connection except ImportError: try: import urllib3 + from urllib3 import connection as urllib3_connection except ImportError: URLLIB3_IMPORT_ERROR = traceback.format_exc() @@ -63,7 +65,12 @@ def __init__(self): self.match_hostname = object() self.HTTPConnectionPool = _HTTPConnectionPool + class FakeURLLIB3Connection(object): + def __init__(self): + self.HTTPConncetion = _HTTPConnectionPool + urllib3 = FakeURLLIB3() + urllib3_connection = FakeURLLIB3Connection() # Monkey-patching match_hostname with a version that supports diff --git a/plugins/module_utils/_api/transport/npipeconn.py b/plugins/module_utils/_api/transport/npipeconn.py index 72a5c5899..912e465fe 100644 --- a/plugins/module_utils/_api/transport/npipeconn.py +++ b/plugins/module_utils/_api/transport/npipeconn.py @@ -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 diff --git a/plugins/module_utils/_api/transport/sshconn.py b/plugins/module_utils/_api/transport/sshconn.py index 063c28826..a621d7557 100644 --- a/plugins/module_utils/_api/transport/sshconn.py +++ b/plugins/module_utils/_api/transport/sshconn.py @@ -24,12 +24,7 @@ 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 @@ def close(self): 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 diff --git a/plugins/module_utils/_api/transport/unixconn.py b/plugins/module_utils/_api/transport/unixconn.py index f46372f9a..1d15c5998 100644 --- a/plugins/module_utils/_api/transport/unixconn.py +++ b/plugins/module_utils/_api/transport/unixconn.py @@ -18,7 +18,7 @@ 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 @@ -35,7 +35,7 @@ def __init__(self, sock, *args, **kwargs): 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__( diff --git a/tests/utils/constraints.txt b/tests/utils/constraints.txt index c8a2c39ed..a577641d8 100644 --- a/tests/utils/constraints.txt +++ b/tests/utils/constraints.txt @@ -16,7 +16,6 @@ paramiko < 2.4.0 ; python_version < '2.7' # paramiko 2.4.0 drops support for pyt paramiko < 3.0.0 ; python_version < '3.7' # paramiko 3.0.0 forces installation of a too new cryptography requests < 2.20.0 ; python_version < '2.7' # requests 2.20.0 drops support for python 2.6 requests < 2.28 ; python_version < '3.7' # requests 2.28.0 drops support for python < 3.7 -requests < 2.29 # TODO see https://github.com/ansible-collections/community.docker/issues/611 virtualenv < 16.0.0 ; python_version < '2.7' # virtualenv 16.0.0 and later require python 2.7 or later pyopenssl < 18.0.0 ; python_version < '2.7' # pyOpenSSL 18.0.0 and later require python 2.7 or later setuptools < 45 ; python_version <= '2.7' # setuptools 45 and later require python 3.5 or later