From c206d4f3354a489110fefbf590f0336dbce1b62c Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Thu, 25 Apr 2024 09:34:27 -0500 Subject: [PATCH] Derive with improvements instead of straight copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) --- lib/ansible/module_utils/urls.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index 4ed41b4e8fa..1e61cfe57bb 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -303,17 +303,15 @@ class UnixHTTPHandler(urllib.request.HTTPHandler): class ProxyHandler(urllib.request.ProxyHandler): - _SPLITPORT_RE = re.compile('(.*):([0-9]*)', re.DOTALL) + _SPLITPORT_RE = re.compile('(.*):([0-9]{1,5})', re.DOTALL) @classmethod def _splitport(cls, host): - # Copied from cpython urllib.parse - match = cls._SPLITPORT_RE.fullmatch(host) - if match: + # Derived from cpython urllib.parse + port = None + if (match := cls._SPLITPORT_RE.fullmatch(host)): host, port = match.groups() - if port: - return host, port - return host, None + return host, port or None @staticmethod def _matches(host, port, bypass_network, bypass_port, scheme):