mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-26 18:06: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:
commit
04fb100ca9
@ -10,7 +10,11 @@ from urllib.parse import urlparse
|
|||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
from urllib.error import URLError
|
from urllib.error import URLError
|
||||||
|
|
||||||
import urllib3.exceptions
|
try:
|
||||||
|
from urllib3.exceptions import URLSchemeUnknown
|
||||||
|
except ImportError:
|
||||||
|
class URLSchemeUnknown(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
from .core import streamfile
|
from .core import streamfile
|
||||||
|
|
||||||
@ -39,7 +43,8 @@ class OscMirrorGroup:
|
|||||||
try:
|
try:
|
||||||
self._grabber.urlgrab(mirror, filename, text)
|
self._grabber.urlgrab(mirror, filename, text)
|
||||||
return True
|
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
|
# try next mirror
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
32
tests/test_grabber.py
Normal file
32
tests/test_grabber.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user