mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 01:04:29 +03:00
Raise ValueError for io.StringIO in Image.open
This commit is contained in:
parent
bbaebe0d20
commit
fedb0407b4
|
@ -1,3 +1,4 @@
|
|||
import io
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
@ -91,6 +92,9 @@ class TestImage(PillowTestCase):
|
|||
def test_bad_mode(self):
|
||||
self.assertRaises(ValueError, Image.open, "filename", "bad mode")
|
||||
|
||||
def test_stringio(self):
|
||||
self.assertRaises(ValueError, Image.open, io.StringIO())
|
||||
|
||||
def test_pathlib(self):
|
||||
from PIL.Image import Path
|
||||
|
||||
|
|
|
@ -2690,10 +2690,16 @@ def open(fp, mode="r"):
|
|||
:exception FileNotFoundError: If the file cannot be found.
|
||||
:exception PIL.UnidentifiedImageError: If the image cannot be opened and
|
||||
identified.
|
||||
:exception ValueError: If the ``mode`` is not "r", or if a StringIO
|
||||
instance is used for ``fp``.
|
||||
"""
|
||||
|
||||
if mode != "r":
|
||||
raise ValueError("bad mode %r" % mode)
|
||||
elif isinstance(fp, io.StringIO):
|
||||
raise ValueError(
|
||||
"StringIO cannot be used to open an image. Binary data must be used instead"
|
||||
)
|
||||
|
||||
exclusive_fp = False
|
||||
filename = ""
|
||||
|
|
Loading…
Reference in New Issue
Block a user