mirror of
https://github.com/python/cpython.git
synced 2025-10-12 18:02:39 +00:00
Merged revisions 76593 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r76593 | amaury.forgeotdarc | 2009-11-30 01:08:56 +0100 (lun., 30 nov. 2009) | 5 lines #6077: on Windows, fix truncation of a tempfile.TemporaryFile opened in "wt+" mode: files opened with os.open() stop on the first \x1a (Ctrl-Z) unless os.O_BINARY is used. Will backport to 3.1 ........
This commit is contained in:
parent
ac4a07c714
commit
36dfe78456
3 changed files with 16 additions and 12 deletions
|
@ -169,7 +169,6 @@ def _get_default_tempdir():
|
||||||
|
|
||||||
namer = _RandomNameSequence()
|
namer = _RandomNameSequence()
|
||||||
dirlist = _candidate_tempdir_list()
|
dirlist = _candidate_tempdir_list()
|
||||||
flags = _text_openflags
|
|
||||||
|
|
||||||
for dir in dirlist:
|
for dir in dirlist:
|
||||||
if dir != _os.curdir:
|
if dir != _os.curdir:
|
||||||
|
@ -179,7 +178,7 @@ def _get_default_tempdir():
|
||||||
name = next(namer)
|
name = next(namer)
|
||||||
filename = _os.path.join(dir, name)
|
filename = _os.path.join(dir, name)
|
||||||
try:
|
try:
|
||||||
fd = _os.open(filename, flags, 0o600)
|
fd = _os.open(filename, _bin_openflags, 0o600)
|
||||||
fp = _io.open(fd, 'wb')
|
fp = _io.open(fd, 'wb')
|
||||||
fp.write(b'blat')
|
fp.write(b'blat')
|
||||||
fp.close()
|
fp.close()
|
||||||
|
@ -434,10 +433,7 @@ def NamedTemporaryFile(mode='w+b', buffering=-1, encoding=None,
|
||||||
if dir is None:
|
if dir is None:
|
||||||
dir = gettempdir()
|
dir = gettempdir()
|
||||||
|
|
||||||
if 'b' in mode:
|
flags = _bin_openflags
|
||||||
flags = _bin_openflags
|
|
||||||
else:
|
|
||||||
flags = _text_openflags
|
|
||||||
|
|
||||||
# Setting O_TEMPORARY in the flags causes the OS to delete
|
# Setting O_TEMPORARY in the flags causes the OS to delete
|
||||||
# the file when it is closed. This is only supported by Windows.
|
# the file when it is closed. This is only supported by Windows.
|
||||||
|
@ -475,10 +471,7 @@ else:
|
||||||
if dir is None:
|
if dir is None:
|
||||||
dir = gettempdir()
|
dir = gettempdir()
|
||||||
|
|
||||||
if 'b' in mode:
|
flags = _bin_openflags
|
||||||
flags = _bin_openflags
|
|
||||||
else:
|
|
||||||
flags = _text_openflags
|
|
||||||
|
|
||||||
(fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
|
(fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -309,8 +309,12 @@ class test__mkstemp_inner(TC):
|
||||||
if not has_textmode:
|
if not has_textmode:
|
||||||
return # ugh, can't use SkipTest.
|
return # ugh, can't use SkipTest.
|
||||||
|
|
||||||
self.do_create(bin=0).write(b"blat\n")
|
# A text file is truncated at the first Ctrl+Z byte
|
||||||
# XXX should test that the file really is a text file
|
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)
|
test_classes.append(test__mkstemp_inner)
|
||||||
|
|
||||||
|
@ -761,6 +765,10 @@ class test_SpooledTemporaryFile(TC):
|
||||||
f.write("xyzzy\n")
|
f.write("xyzzy\n")
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
self.assertEqual(f.read(), "abc\ndef\nxyzzy\n")
|
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):
|
def test_text_newline_and_encoding(self):
|
||||||
f = tempfile.SpooledTemporaryFile(mode='w+', max_size=10,
|
f = tempfile.SpooledTemporaryFile(mode='w+', max_size=10,
|
||||||
|
|
|
@ -12,6 +12,9 @@ What's New in Python 3.1.2?
|
||||||
Core and Builtins
|
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
|
- Issue #7085: Fix crash when importing some extensions in a thread
|
||||||
on MacOSX 10.6.
|
on MacOSX 10.6.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue