From d43863ee9fc39908999e6a66732bd0d58770de14 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 30 Dec 2022 11:32:14 -0800 Subject: [PATCH] delete the tempfile after use --- jc/parsers/plist.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jc/parsers/plist.py b/jc/parsers/plist.py index a7858ccb..a4048cdc 100644 --- a/jc/parsers/plist.py +++ b/jc/parsers/plist.py @@ -166,12 +166,20 @@ def parse( # Try parsing as an old-style NeXTSTEP Plist format # pbPlist library only works on file paths, not strings :( import tempfile + import os + + # use delete=False for windows compatibility with tempfile.NamedTemporaryFile(mode='w+b', delete=False) as plist_file: + plist_file_name = plist_file.name plist_file.write(data) plist_file.seek(0) - parsed_plist = PBPlist(plist_file.name) + parsed_plist = PBPlist(plist_file_name) 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) return raw_output if raw else _process(raw_output)