Replaced the unsafe "tfname = tempfile.mktemp()" call with
"with tempfile.NamedTemporaryFile(delete=False) as fid: tfname = fid.name"

Also removed unused "import glob"
This commit is contained in:
Per A. Brodtkorb
2020-03-24 15:40:24 +01:00
parent f1aaa8b6d3
commit 5cf6dc565e

View File

@@ -34,7 +34,6 @@
#
"""
img2py.py -- Convert an image to PNG format and embed it in a Python
module with appropriate code so it can be loaded into
@@ -81,7 +80,6 @@ function. See its docstring for more info.
import base64
import getopt
import glob
import os
import re
import sys
@@ -120,10 +118,8 @@ def convert(fileName, maskClr, outputDir, outputName, outType, outExt):
with open(newname, "wb") as f_out:
with open(fileName, "rb") as f_in:
f_out.write(f_in.read())
return 1, "ok"
else:
return img2img.convert(fileName, maskClr, outputDir, outputName, outType, outExt)
return True, "ok"
return img2img.convert(fileName, maskClr, outputDir, outputName, outType, outExt)
def img2py(image_file, python_file,
@@ -152,7 +148,9 @@ def img2py(image_file, python_file,
app = wx.App(0)
# convert the image file to a temporary file
tfname = tempfile.mktemp()
with tempfile.NamedTemporaryFile(delete=False) as fid:
tfname = fid.name
try:
ok, msg = convert(image_file, maskClr, None, tfname, wx.BITMAP_TYPE_PNG, ".png")
if not ok:
@@ -272,7 +270,6 @@ def img2py(image_file, python_file,
out.close()
def main(args=None):
if not args:
args = sys.argv[1:]
@@ -319,5 +316,6 @@ def main(args=None):
img2py(image_file, python_file,
append, compressed, maskClr, imgName, icon, catalog, compatible)
if __name__ == "__main__":
main(sys.argv[1:])