Skip to content

Commit 709b097

Browse files
author
Thomas Preud'homme
committed
[LNT] Python 3 support: fix writing report to tmp file
Summary: The import_from_string() method in lnt.util.ImportData writes a copy of the report being imported into a temporary file. That fails under Python 3 because by default tempfile.mkstemp open in binary mode and the data written is text. This commit sets the text parameter of mkstemp to True to ensure the file is opened in text mode. It also write to the file via a file object since os.write expects binary data. Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls, leandron, PrzemekWirkus Reviewed By: cmatthews Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D68802
1 parent 290cda8 commit 709b097

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lnt/util/ImportData.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,10 @@ def import_from_string(config, db_name, db, session, ts_name, data,
337337
# recovery.
338338
prefix = utcnow.strftime("data-%Y-%m-%d_%H-%M-%S")
339339
fd, path = tempfile.mkstemp(prefix=prefix, suffix='.json',
340-
dir=str(tmpdir))
341-
os.write(fd, data)
342-
os.close(fd)
340+
dir=str(tmpdir), text=True)
341+
fp = os.fdopen(fd, "w")
342+
fp.write(data)
343+
fp.close()
343344

344345
# Import the data.
345346
#

0 commit comments

Comments
 (0)