mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 02:46:18 +03:00
Added context manager when opening files in WalImageFile
This commit is contained in:
parent
06895b6fa4
commit
87de178e0b
|
@ -47,11 +47,7 @@ def open(filename):
|
|||
# FIXME: modify to return a WalImageFile instance instead of
|
||||
# plain Image object ?
|
||||
|
||||
if hasattr(filename, "read"):
|
||||
fp = filename
|
||||
else:
|
||||
fp = builtins.open(filename, "rb")
|
||||
|
||||
def imopen(fp):
|
||||
# read header fields
|
||||
header = fp.read(32+24+32+12)
|
||||
size = i32(header, 32), i32(header, 36)
|
||||
|
@ -74,6 +70,11 @@ def open(filename):
|
|||
|
||||
return im
|
||||
|
||||
if hasattr(filename, "read"):
|
||||
return imopen(filename)
|
||||
else:
|
||||
with builtins.open(filename, "rb") as fp:
|
||||
return imopen(fp)
|
||||
|
||||
quake2palette = (
|
||||
# default palette taken from piffo 0.93 by Hans Häggström
|
||||
|
|
Loading…
Reference in New Issue
Block a user