From 74b1c26eeb104ec99b49befc78f8612d125e532e Mon Sep 17 00:00:00 2001
From: Lucio Sauer <watermanpaint@posteo.net>
Date: Wed, 8 May 2024 12:46:33 +0200
Subject: [PATCH 1/3] pyproject: bump snakeoil to restore compat with
 >=python-3.11.9

ArgumentParser added a separator to its option tuple with
>=python-3.11.9, which snakeoil-0.10.7 does not handle correctly.
https://github.com/python/cpython/pull/114180

Signed-off-by: Lucio Sauer <watermanpaint@posteo.net>
---
 pyproject.toml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index fd0eb6163..45fe72132 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -8,7 +8,7 @@ requires = [
 	"pathspec",
 	"tree-sitter>=0.21.0",
 	"tree-sitter-bash>=0.21.0",
-	"snakeoil~=0.10.7",
+	"snakeoil~=0.10.8",
 	"pkgcore~=0.12.25",
 ]
 build-backend = "py_build"
@@ -46,7 +46,7 @@ dependencies = [
 	"pathspec",
 	"tree-sitter>=0.21.0",
 	"tree-sitter-bash>=0.21.0",
-	"snakeoil~=0.10.7",
+	"snakeoil~=0.10.8",
 	"pkgcore~=0.12.25",
 ]
 

From b5cca560732300b4f610fdc056bc8be0e87fe6a3 Mon Sep 17 00:00:00 2001
From: Lucio Sauer <watermanpaint@posteo.net>
Date: Tue, 30 Apr 2024 23:28:51 +0200
Subject: [PATCH 2/3] fix crash when performing --timeout 0 call to ftp:// site

e.g.
pkgcheck scan --net -c HomepageUrlCheck --timeout 0 app-admin/chrootuid
at checkout 127160ac611d39cc6bb2ca21fcf99a086fe2b176

Python's ftplib raises a ValueError with timeout=0. Use timeout=None to
put the underlying socket in blocking mode. See
https://docs.python.org/3/library/socket.html#socket.socket.settimeout
for legal timeout values.

Signed-off-by: Lucio Sauer <watermanpaint@posteo.net>
---
 src/pkgcheck/addons/__init__.py | 12 +++++++++++-
 src/pkgcheck/addons/net.py      |  7 +------
 src/pkgcheck/checks/__init__.py |  2 +-
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/pkgcheck/addons/__init__.py b/src/pkgcheck/addons/__init__.py
index 566786695..c621c53b1 100644
--- a/src/pkgcheck/addons/__init__.py
+++ b/src/pkgcheck/addons/__init__.py
@@ -274,6 +274,16 @@ def use_validate(self, klasses, pkg, seq, attr=None):
 class NetAddon(base.Addon):
     """Addon supporting network functionality."""
 
+    def __init__(self, *args):
+        super().__init__(*args)
+
+        if self.options.timeout == 0:
+            # set timeout to 0 to never timeout
+            self.timeout = None
+        else:
+            # default to timing out connections after 5 seconds
+            self.timeout = self.options.timeout if self.options.timeout is not None else 5
+
     @classmethod
     def mangle_argparser(cls, parser):
         group = parser.add_argument_group("network")
@@ -291,7 +301,7 @@ def session(self):
 
             return Session(
                 concurrent=self.options.tasks,
-                timeout=self.options.timeout,
+                timeout=self.timeout,
                 user_agent=self.options.user_agent,
             )
         except ImportError as e:
diff --git a/src/pkgcheck/addons/net.py b/src/pkgcheck/addons/net.py
index 782d74d1d..91101282f 100644
--- a/src/pkgcheck/addons/net.py
+++ b/src/pkgcheck/addons/net.py
@@ -18,12 +18,7 @@ class Session(requests.Session):
 
     def __init__(self, concurrent=None, timeout=None, user_agent=None):
         super().__init__()
-        if timeout == 0:
-            # set timeout to 0 to never timeout
-            self.timeout = None
-        else:
-            # default to timing out connections after 5 seconds
-            self.timeout = timeout if timeout is not None else 5
+        self.timeout = timeout
 
         # block when urllib3 connection pool is full
         concurrent = concurrent if concurrent is not None else os.cpu_count() * 5
diff --git a/src/pkgcheck/checks/__init__.py b/src/pkgcheck/checks/__init__.py
index b5caa2442..556f720e4 100644
--- a/src/pkgcheck/checks/__init__.py
+++ b/src/pkgcheck/checks/__init__.py
@@ -127,7 +127,7 @@ def __init__(self, *args, net_addon, **kwargs):
         super().__init__(*args, **kwargs)
         if not self.options.net:
             raise SkipCheck(self, "network checks not enabled")
-        self.timeout = self.options.timeout
+        self.timeout = net_addon.timeout
         self.session = net_addon.session
 
 

From 4b9faf7d09d6cbfd59d1fe76d159fc2dd122df74 Mon Sep 17 00:00:00 2001
From: Lucio Sauer <watermanpaint@posteo.net>
Date: Tue, 30 Apr 2024 23:35:04 +0200
Subject: [PATCH 3/3] modify test to check that timeout=0 is never passed to
 _ftp_check

followup to f691ea197c3db922edf33e570708751421db48aa

Signed-off-by: Lucio Sauer <watermanpaint@posteo.net>
---
 tests/addons/test_addons.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/addons/test_addons.py b/tests/addons/test_addons.py
index 47503a6ca..c02214f72 100644
--- a/tests/addons/test_addons.py
+++ b/tests/addons/test_addons.py
@@ -387,10 +387,12 @@ def test_custom_timeout(self, tool):
         addon = addons.NetAddon(options)
         assert isinstance(addon.session, requests.Session)
         assert addon.session.timeout == 10
+        assert addon.timeout == 10
         # a timeout of zero disables timeouts entirely
         options, _ = tool.parse_args(["scan", "--timeout", "0"])
         addon = addons.NetAddon(options)
         assert addon.session.timeout is None
+        assert addon.timeout is None
 
     def test_args(self, tool):
         options, _ = tool.parse_args(
