def get_tmpfile(self, suggested_name): """Return a temporary file in the temporary downloads directory. The files are kept as long as qutebrowser is running and automatically cleaned up at program exit. Args: suggested_name: str of the "suggested"/original filename. Used as a suffix, so any file extenions are preserved. Return: A tempfile.NamedTemporaryFile that should be used to save the file. """ tmpdir = self.get_tmpdir() suggested_name = utils.sanitize_filename(suggested_name) # Make sure that the filename is not too long suggested_name = utils.elide_filename(suggested_name, 50) fobj = tempfile.NamedTemporaryFile(dir=tmpdir.name, delete=False, suffix='_' + suggested_name) self.files.append(fobj) return fobj