1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-25 17:36:13 +01:00

Merge pull request #1326 from dmach/fix-missing-URLSchemeUnknown-in-old-urllib3

Fix grabber to work with old urllib3 versions that do not contain URLSchemeUnknown exception
This commit is contained in:
Daniel Mach 2023-05-16 09:07:26 +02:00 committed by GitHub
commit 04fb100ca9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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()