Merge pull request #863 from p-l-/fix-tmpfiles

Fix get_temp_file() to use NamedTemporaryFile() properly
This commit is contained in:
Guillaume Valadon 2017-10-04 17:55:32 +02:00 committed by GitHub
commit 38b99fa33f
1 changed files with 8 additions and 4 deletions

View File

@ -33,11 +33,15 @@ from scapy.base_classes import BasePacketList
###########
def get_temp_file(keep=False, autoext=""):
with tempfile.NamedTemporaryFile(prefix="scapy") as _f:
f = _f.name
"""Create a temporary file and return its name. When keep is False,
the file is deleted when scapy exits.
"""
fname = tempfile.NamedTemporaryFile(prefix="scapy", suffix=autoext,
delete=False).name
if not keep:
conf.temp_files.append(f+autoext)
return f + autoext
conf.temp_files.append(fname)
return fname
def sane_color(x):
r=""