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):
1468
1468
img_open = (
1469
1469
PIL .PngImagePlugin .PngImageFile if ext == 'png' else PIL .Image .open )
1470
1470
if isinstance (fname , str ):
1471
+ import io
1472
+ from urllib import request
1473
+
1471
1474
parsed = urllib .parse .urlparse (fname )
1472
1475
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 ())
1475
1481
return imread (response , format = ext )
1476
1482
with img_open (fname ) as image :
1477
1483
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):
16
16
("markers" , "style: Set alternate Matplotlib style temporarily." ),
17
17
("markers" , "baseline_images: Compare output against references." ),
18
18
("markers" , "pytz: Tests that require pytz to be installed." ),
19
+ ("markers" , "network: Tests that reachout to the network." ),
19
20
("filterwarnings" , "error" ),
20
21
]:
21
22
config .addinivalue_line (key , value )
Original file line number Diff line number Diff line change @@ -1118,3 +1118,9 @@ def test_exact_vmin():
1118
1118
1119
1119
# check than the RBGA values are the same
1120
1120
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