From cd11a8c19ab672d8326cb474d7833cf532ae82cc Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Mon, 20 Aug 2018 23:36:37 +0100 Subject: [PATCH] Use `NamedTemporaryFile` opened in text mode --- lib/galaxy/tools/wrappers.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/galaxy/tools/wrappers.py b/lib/galaxy/tools/wrappers.py index fee2a3b73b3..8fd81f5121e 100644 --- a/lib/galaxy/tools/wrappers.py +++ b/lib/galaxy/tools/wrappers.py @@ -1,15 +1,11 @@ import logging -import os import tempfile from six import string_types, text_type from six.moves import shlex_quote from galaxy import exceptions -from galaxy.util import ( - odict, - smart_str, -) +from galaxy.util import odict from galaxy.util.none_like import NoneDataset from galaxy.util.object_wrapper import wrap_with_safe_string @@ -321,10 +317,10 @@ class HasDatasets(object): return DatasetFilenameWrapper(dataset, **wrapper_kwds) def paths_as_file(self, sep="\n"): - handle, filepath = tempfile.mkstemp(prefix="gx_file_list", dir=self.job_working_directory) contents = sep.join(map(str, self)) - os.write(handle, smart_str(contents)) - os.close(handle) + with tempfile.NamedTemporaryFile(mode='w+', prefix="gx_file_list", dir=self.job_working_directory, delete=False) as fh: + fh.write(contents) + filepath = fh.name return filepath