commit:     a4ed205d28d1f61805598c31a235b21978a54217
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 12 21:39:35 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Dec 16 05:12:16 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=a4ed205d

tests: test_socks5: modernise by dropping py2isms

Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/tests/util/test_socks5.py | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/lib/portage/tests/util/test_socks5.py 
b/lib/portage/tests/util/test_socks5.py
index cf386ca5c4..fa35e2633a 100644
--- a/lib/portage/tests/util/test_socks5.py
+++ b/lib/portage/tests/util/test_socks5.py
@@ -88,17 +88,12 @@ class AsyncHTTPServer:
 class AsyncHTTPServerTestCase(TestCase):
     @staticmethod
     def _fetch_directly(host, port, path):
-        # NOTE: python2.7 does not have context manager support here
-        try:
-            f = urlopen(
-                "http://{host}:{port}{path}".format(  # nosec
-                    host=host, port=port, path=path
-                )
+        with urlopen(
+            "http://{host}:{port}{path}".format(  # nosec
+                host=host, port=port, path=path
             )
+        ) as f:
             return f.read()
-        finally:
-            if f is not None:
-                f.close()
 
     async def _test_http_server(self):
         asyncio.run(self._test_http_server())
@@ -109,9 +104,9 @@ class AsyncHTTPServerTestCase(TestCase):
         path = "/index.html"
 
         loop = asyncio.get_running_loop()
-        for i in range(2):
+        for _ in range(2):
             with AsyncHTTPServer(host, {path: content}, loop) as server:
-                for j in range(2):
+                for _ in range(2):
                     result = await loop.run_in_executor(
                         None, self._fetch_directly, host, server.server_port, 
path
                     )
@@ -153,7 +148,7 @@ class 
_socket_file_wrapper(portage.proxy.objectproxy.ObjectProxy):
 
 def socks5_http_get_ipv4(proxy, host, port, path):
     """
-    Open http GET request via socks5 proxy listening on a unix socket,
+    Open HTTP GET request via SOCKS5 proxy listening on a UNIX socket,
     and return a file to read the response body from.
     """
     s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

Reply via email to