1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

delete the tempfile after use

This commit is contained in:
Kelly Brazil
2022-12-30 11:32:14 -08:00
parent 177d10577f
commit d43863ee9f

View File

@ -166,12 +166,20 @@ def parse(
# Try parsing as an old-style NeXTSTEP Plist format # Try parsing as an old-style NeXTSTEP Plist format
# pbPlist library only works on file paths, not strings :( # pbPlist library only works on file paths, not strings :(
import tempfile import tempfile
import os
# use delete=False for windows compatibility
with tempfile.NamedTemporaryFile(mode='w+b', delete=False) as plist_file: with tempfile.NamedTemporaryFile(mode='w+b', delete=False) as plist_file:
plist_file_name = plist_file.name
plist_file.write(data) plist_file.write(data)
plist_file.seek(0) plist_file.seek(0)
parsed_plist = PBPlist(plist_file.name) parsed_plist = PBPlist(plist_file_name)
raw_output = parsed_plist.root.nativeType() raw_output = parsed_plist.root.nativeType()
# try to delete the temp file
if os.path.exists(plist_file_name):
os.remove(plist_file_name)
raw_output = _fix_objects(raw_output) raw_output = _fix_objects(raw_output)
return raw_output if raw else _process(raw_output) return raw_output if raw else _process(raw_output)