8000 MNT: Be more defensive about pre-reading into BytesIO · matplotlib/matplotlib@55ba612 · GitHub
[go: up one dir, main page]

Skip to content

Commit 55ba612

Browse files
tacaswelltimhoffm
andauthored
MNT: Be more defensive about pre-readin 8000 g into BytesIO
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
1 parent 66ff15a commit 55ba612

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/matplotlib/image.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,11 @@ def imread(fname, format=None):
14731473
parsed = urllib.parse.urlparse(fname)
14741474
if len(parsed.scheme) > 1: # Pillow doesn't handle URLs directly.
14751475
with urllib.request.urlopen(fname) as response:
1476-
return imread(BytesIO(response.read()), format=ext)
1476+
try:
1477+
response.seek(0)
1478+
except (AttributeError, io.UnsupportedOperation):
1479+
response = BytesIO(response.read())
1480+
return imread(response, format=ext)
14771481
with img_open(fname) as image:
14781482
return (_pil_png_to_float_array(image)
14791483
if isinstance(image, PIL.PngImagePlugin.PngImageFile) else

0 commit comments

Comments
 (0)
0