Commit 04688c31 authored by Michal's avatar Michal Committed by Jehan

Use the "with" keyword when dealing with file objects

According to: https://docs.python.org/3.6/tutorial/inputoutput.html
parent 263b4722
......@@ -86,9 +86,8 @@ def thumbnail_ora(filename, thumb_size):
# create temp file
tmp = os.path.join(tempdir, 'tmp.png')
f = open(tmp, 'wb')
f.write(orafile.read('Thumbnails/thumbnail.png'))
f.close()
with open(tmp, 'wb') as fid:
fid.write(orafile.read('Thumbnails/thumbnail.png'))
img = pdb['file-png-load'](tmp)
# TODO: scaling
......@@ -287,15 +286,14 @@ def load_ora(filename, raw_filename):
# create temp file. Needed because gimp cannot load files from inside a zip file
tmp = os.path.join(tempdir, 'tmp.png')
f = open(tmp, 'wb')
try:
data = orafile.read(path)
except KeyError:
# support for bad zip files (saved by old versions of this plugin)
data = orafile.read(path.encode('utf-8'))
print 'WARNING: bad OpenRaster ZIP file. There is an utf-8 encoded filename that does not have the utf-8 flag set:', repr(path)
f.write(data)
f.close()
with open(tmp, 'wb') as fid:
try:
data = orafile.read(path)
except KeyError:
# support for bad zip files (saved by old versions of this plugin)
data = orafile.read(path.encode('utf-8'))
print 'WARNING: bad OpenRaster ZIP file. There is an utf-8 encoded filename that does not have the utf-8 flag set:', repr(path)
fid.write(data)
# import layer, set attributes and add to image
gimp_layer = pdb['gimp-file-load-layer'](img, tmp)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment