1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-08-05 07:03:38 +02:00

Fix grabber to work with old urllib3 versions that do not contain URLSchemeUnknown exception

This commit is contained in:
2023-05-14 21:35:15 +02:00
parent d089e878ca
commit 309f10633d
2 changed files with 39 additions and 2 deletions

View File

@@ -10,7 +10,11 @@ from urllib.parse import urlparse
from urllib.parse import unquote
from urllib.error import URLError
import urllib3.exceptions
try:
from urllib3.exceptions import URLSchemeUnknown
except ImportError:
class URLSchemeUnknown(Exception):
pass
from .core import streamfile
@@ -39,7 +43,8 @@ class OscMirrorGroup:
try:
self._grabber.urlgrab(mirror, filename, text)
return True
except (HTTPError, URLError, urllib3.exceptions.URLSchemeUnknown) as e:
except (HTTPError, URLError, URLSchemeUnknown, KeyError) as e:
# urllib3 1.25.10 throws a KeyError: pool_key_constructor = self.key_fn_by_scheme[scheme]
# try next mirror
pass

32
tests/test_grabber.py Normal file
View File

@@ -0,0 +1,32 @@
import importlib
import os
import tempfile
import unittest
import osc.conf
import osc.grabber as osc_grabber
class TestMirrorGroup(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp(prefix='osc_test')
# reset the global `config` in preparation for running the tests
importlib.reload(osc.conf)
osc.conf.get_config()
def tearDown(self):
# reset the global `config` to avoid impacting tests from other classes
importlib.reload(osc.conf)
try:
shutil.rmtree(self.tmpdir)
except:
pass
def test_invalid_scheme(self):
gr = osc_grabber.OscFileGrabber()
mg = osc_grabber.OscMirrorGroup(gr, ["container://example.com"])
mg.urlgrab(None, os.path.join(self.tmpdir, "file"))
if __name__ == "__main__":
unittest.main()