namer = _RandomNameSequence()
dirlist = _candidate_tempdir_list()
- flags = _text_openflags
for dir in dirlist:
if dir != _os.curdir:
name = next(namer)
filename = _os.path.join(dir, name)
try:
- fd = _os.open(filename, flags, 0o600)
+ fd = _os.open(filename, _bin_openflags, 0o600)
fp = _io.open(fd, 'wb')
fp.write(b'blat')
fp.close()
if dir is None:
dir = gettempdir()
- if 'b' in mode:
- flags = _bin_openflags
- else:
- flags = _text_openflags
+ flags = _bin_openflags
# Setting O_TEMPORARY in the flags causes the OS to delete
# the file when it is closed. This is only supported by Windows.
if dir is None:
dir = gettempdir()
- if 'b' in mode:
- flags = _bin_openflags
- else:
- flags = _text_openflags
+ flags = _bin_openflags
(fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
try:
if not has_textmode:
return # ugh, can't use SkipTest.
- self.do_create(bin=0).write(b"blat\n")
- # XXX should test that the file really is a text file
+ # A text file is truncated at the first Ctrl+Z byte
+ f = self.do_create(bin=0)
+ f.write(b"blat\x1a")
+ f.write(b"extra\n")
+ os.lseek(f.fd, 0, os.SEEK_SET)
+ self.assertEquals(os.read(f.fd, 20), b"blat")
test_classes.append(test__mkstemp_inner)
f.write("xyzzy\n")
f.seek(0)
self.assertEqual(f.read(), "abc\ndef\nxyzzy\n")
+ # Check that Ctrl+Z doesn't truncate the file
+ f.write("foo\x1abar\n")
+ f.seek(0)
+ self.assertEqual(f.read(), "abc\ndef\nxyzzy\nfoo\x1abar\n")
def test_text_newline_and_encoding(self):
f = tempfile.SpooledTemporaryFile(mode='w+', max_size=10,
Core and Builtins
-----------------
+- Issue #6077: On Windows, files opened with tempfile.TemporaryFile in "wt+"
+ mode would appear truncated on the first '0x1a' byte (aka. Ctrl+Z).
+
- Issue #7085: Fix crash when importing some extensions in a thread
on MacOSX 10.6.