File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed
Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -1468,10 +1468,16 @@ def imread(fname, format=None):
14681468 img_open = (
14691469 PIL .PngImagePlugin .PngImageFile if ext == 'png' else PIL .Image .open )
14701470 if isinstance (fname , str ):
1471+ import io
1472+ from urllib import request
1473+
14711474 parsed = urllib .parse .urlparse (fname )
14721475 if len (parsed .scheme ) > 1 : # Pillow doesn't handle URLs directly.
1473- from urllib import request
1474- with urllib .request .urlopen (fname ) as response :
1476+ with request .urlopen (fname ) as response :
1477+ try :
1478+ response .seek (0 )
1479+ except (AttributeError , io .UnsupportedOperation ):
1480+ response = io .BytesIO (response .read ())
14751481 return imread (response , format = ext )
14761482 with img_open (fname ) as image :
14771483 return (_pil_png_to_float_array (image )
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ def pytest_configure(config):
1616 ("markers" , "style: Set alternate Matplotlib style temporarily." ),
1717 ("markers" , "baseline_images: Compare output against references." ),
1818 ("markers" , "pytz: Tests that require pytz to be installed." ),
19+ ("markers" , "network: Tests that reachout to the network." ),
1920 ("filterwarnings" , "error" ),
2021 ]:
2122 config .addinivalue_line (key , value )
Original file line number Diff line number Diff line change @@ -1118,3 +1118,9 @@ def test_exact_vmin():
11181118
11191119 # check than the RBGA values are the same
11201120 assert np .all (from_image == direct_computation )
1121+
1122+
1123+ @pytest .mark .network
1124+ @pytest .mark .flaky
1125+ def test_https_imread_smoketest ():
1126+ v = mimage .imread ('https://matplotlib.org/1.5.0/_static/logo2.png' )
You can’t perform that action at this time.
0 commit comments