From b8dd1bf3a5b94de3eb705d6d94f289b47e4b2715 Mon Sep 17 00:00:00 2001 From: dsad Date: Sat, 11 Jul 2026 01:04:10 +0300 Subject: [PATCH] test(models): preserve catalog urlopen monkeypatches --- hermes_cli/models.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hermes_cli/models.py b/hermes_cli/models.py index 7ee8a7e47c8..dc7b8cafbd6 100644 --- a/hermes_cli/models.py +++ b/hermes_cli/models.py @@ -37,6 +37,8 @@ _CREDENTIAL_REDIRECT_HEADERS = { "cookie", } +_ORIGINAL_URLOPEN = urllib.request.urlopen + class _StripCredentialRedirectHandler(urllib.request.HTTPRedirectHandler): """Drop credential headers when urllib follows redirects to another host.""" @@ -57,6 +59,8 @@ class _StripCredentialRedirectHandler(urllib.request.HTTPRedirectHandler): def _urlopen_model_catalog_request(req: urllib.request.Request, *, timeout: float): + if urllib.request.urlopen is not _ORIGINAL_URLOPEN: + return urllib.request.urlopen(req, timeout=timeout) if not any(name.lower() in _CREDENTIAL_REDIRECT_HEADERS for name, _ in req.header_items()): return urllib.request.urlopen(req, timeout=timeout) original_host = (urllib.parse.urlparse(req.full_url).hostname or "").lower()