mirror of
https://github.com/python/cpython.git
synced 2025-08-24 18:55:00 +00:00
Issue #4662: os.tempnam(), os.tmpfile() and os.tmpnam() now raise a py3k
DeprecationWarning.
This commit is contained in:
parent
f11d1832ec
commit
b061461596
4 changed files with 99 additions and 70 deletions
|
@ -80,8 +80,10 @@ class TemporaryFileTests(unittest.TestCase):
|
||||||
def test_tempnam(self):
|
def test_tempnam(self):
|
||||||
if not hasattr(os, "tempnam"):
|
if not hasattr(os, "tempnam"):
|
||||||
return
|
return
|
||||||
|
with warnings.catch_warnings():
|
||||||
warnings.filterwarnings("ignore", "tempnam", RuntimeWarning,
|
warnings.filterwarnings("ignore", "tempnam", RuntimeWarning,
|
||||||
r"test_os$")
|
r"test_os$")
|
||||||
|
warnings.filterwarnings("ignore", "tempnam", DeprecationWarning)
|
||||||
self.check_tempfile(os.tempnam())
|
self.check_tempfile(os.tempnam())
|
||||||
|
|
||||||
name = os.tempnam(test_support.TESTFN)
|
name = os.tempnam(test_support.TESTFN)
|
||||||
|
@ -108,6 +110,9 @@ class TemporaryFileTests(unittest.TestCase):
|
||||||
# test that a subsequent call to os.tmpfile() raises the same error. If
|
# test that a subsequent call to os.tmpfile() raises the same error. If
|
||||||
# it doesn't, assume we're on XP or below and the user running the test
|
# it doesn't, assume we're on XP or below and the user running the test
|
||||||
# has administrative privileges, and proceed with the test as normal.
|
# has administrative privileges, and proceed with the test as normal.
|
||||||
|
with warnings.catch_warnings():
|
||||||
|
warnings.filterwarnings("ignore", "tmpfile", DeprecationWarning)
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
name = '\\python_test_os_test_tmpfile.txt'
|
name = '\\python_test_os_test_tmpfile.txt'
|
||||||
if os.path.exists(name):
|
if os.path.exists(name):
|
||||||
|
@ -142,8 +147,11 @@ class TemporaryFileTests(unittest.TestCase):
|
||||||
def test_tmpnam(self):
|
def test_tmpnam(self):
|
||||||
if not hasattr(os, "tmpnam"):
|
if not hasattr(os, "tmpnam"):
|
||||||
return
|
return
|
||||||
|
with warnings.catch_warnings():
|
||||||
warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning,
|
warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning,
|
||||||
r"test_os$")
|
r"test_os$")
|
||||||
|
warnings.filterwarnings("ignore", "tmpnam", DeprecationWarning)
|
||||||
|
|
||||||
name = os.tmpnam()
|
name = os.tmpnam()
|
||||||
if sys.platform in ("win32",):
|
if sys.platform in ("win32",):
|
||||||
# The Windows tmpnam() seems useless. From the MS docs:
|
# The Windows tmpnam() seems useless. From the MS docs:
|
||||||
|
|
|
@ -38,6 +38,8 @@ class PosixTester(unittest.TestCase):
|
||||||
"getpid", "getpgrp", "getppid", "getuid",
|
"getpid", "getpgrp", "getppid", "getuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
with warnings.catch_warnings():
|
||||||
|
warnings.filterwarnings("ignore", "", DeprecationWarning)
|
||||||
for name in NO_ARG_FUNCTIONS:
|
for name in NO_ARG_FUNCTIONS:
|
||||||
posix_func = getattr(posix, name, None)
|
posix_func = getattr(posix, name, None)
|
||||||
if posix_func is not None:
|
if posix_func is not None:
|
||||||
|
@ -290,12 +292,16 @@ class PosixTester(unittest.TestCase):
|
||||||
|
|
||||||
def test_tempnam(self):
|
def test_tempnam(self):
|
||||||
if hasattr(posix, 'tempnam'):
|
if hasattr(posix, 'tempnam'):
|
||||||
|
with warnings.catch_warnings():
|
||||||
|
warnings.filterwarnings("ignore", "tempnam", DeprecationWarning)
|
||||||
self.assertTrue(posix.tempnam())
|
self.assertTrue(posix.tempnam())
|
||||||
self.assertTrue(posix.tempnam(os.curdir))
|
self.assertTrue(posix.tempnam(os.curdir))
|
||||||
self.assertTrue(posix.tempnam(os.curdir, 'blah'))
|
self.assertTrue(posix.tempnam(os.curdir, 'blah'))
|
||||||
|
|
||||||
def test_tmpfile(self):
|
def test_tmpfile(self):
|
||||||
if hasattr(posix, 'tmpfile'):
|
if hasattr(posix, 'tmpfile'):
|
||||||
|
with warnings.catch_warnings():
|
||||||
|
warnings.filterwarnings("ignore", "tmpfile", DeprecationWarning)
|
||||||
fp = posix.tmpfile()
|
fp = posix.tmpfile()
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #4662: os.tempnam(), os.tmpfile() and os.tmpnam() now raise a py3k
|
||||||
|
DeprecationWarning.
|
||||||
|
|
||||||
- Subclasses of collections.OrderedDict now work correctly with __missing__.
|
- Subclasses of collections.OrderedDict now work correctly with __missing__.
|
||||||
|
|
||||||
- Issue 10753 - Characters ';','=' and ',' in the PATH_INFO environment
|
- Issue 10753 - Characters ';','=' and ',' in the PATH_INFO environment
|
||||||
|
|
|
@ -7295,6 +7295,10 @@ posix_tempnam(PyObject *self, PyObject *args)
|
||||||
"tempnam is a potential security risk to your program") < 0)
|
"tempnam is a potential security risk to your program") < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (PyErr_WarnPy3k("tempnam has been removed in 3.x; "
|
||||||
|
"use the tempfile module", 1) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
name = _tempnam(dir, pfx);
|
name = _tempnam(dir, pfx);
|
||||||
#else
|
#else
|
||||||
|
@ -7319,6 +7323,10 @@ posix_tmpfile(PyObject *self, PyObject *noargs)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
|
if (PyErr_WarnPy3k("tmpfile has been removed in 3.x; "
|
||||||
|
"use the tempfile module", 1) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
fp = tmpfile();
|
fp = tmpfile();
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return posix_error();
|
return posix_error();
|
||||||
|
@ -7342,6 +7350,10 @@ posix_tmpnam(PyObject *self, PyObject *noargs)
|
||||||
"tmpnam is a potential security risk to your program") < 0)
|
"tmpnam is a potential security risk to your program") < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (PyErr_WarnPy3k("tmpnam has been removed in 3.x; "
|
||||||
|
"use the tempfile module", 1) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
#ifdef USE_TMPNAM_R
|
#ifdef USE_TMPNAM_R
|
||||||
name = tmpnam_r(buffer);
|
name = tmpnam_r(buffer);
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue