mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 10:56: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
|
# FIXME: modify to return a WalImageFile instance instead of
|
||||||
# plain Image object ?
|
# plain Image object ?
|
||||||
|
|
||||||
if hasattr(filename, "read"):
|
def imopen(fp):
|
||||||
fp = filename
|
|
||||||
else:
|
|
||||||
fp = builtins.open(filename, "rb")
|
|
||||||
|
|
||||||
# read header fields
|
# read header fields
|
||||||
header = fp.read(32+24+32+12)
|
header = fp.read(32+24+32+12)
|
||||||
size = i32(header, 32), i32(header, 36)
|
size = i32(header, 32), i32(header, 36)
|
||||||
|
@ -74,6 +70,11 @@ def open(filename):
|
||||||
|
|
||||||
return im
|
return im
|
||||||
|
|
||||||
|
if hasattr(filename, "read"):
|
||||||
|
return imopen(filename)
|
||||||
|
else:
|
||||||
|
with builtins.open(filename, "rb") as fp:
|
||||||
|
return imopen(fp)
|
||||||
|
|
||||||
quake2palette = (
|
quake2palette = (
|
||||||
# default palette taken from piffo 0.93 by Hans Häggström
|
# default palette taken from piffo 0.93 by Hans Häggström
|
||||||
|
|
Loading…
Reference in New Issue
Block a user