summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2003-10-12 17:37:01 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2003-10-12 17:37:01 (GMT)
commitd662548c728e5e1da15d5594a8b6e751213002f8 (patch)
tree92a8e88d48e7e2caca4d7292e0ed5dde1a6ff60c /Lib
parent411c60234974da975b0b1fbf62e362a31f6e4b3c (diff)
downloadcpython-d662548c728e5e1da15d5594a8b6e751213002f8.zip
cpython-d662548c728e5e1da15d5594a8b6e751213002f8.tar.gz
cpython-d662548c728e5e1da15d5594a8b6e751213002f8.tar.bz2
Patch #810914: Return absolute path for mkstemp. Fixes #810408.
This should not be backported to 2.3, as it might break backwards compatibility.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/tempfile.py2
-rw-r--r--Lib/test/test_tempfile.py8
2 files changed, 8 insertions, 2 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index 756d8c8..472fd83 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -214,7 +214,7 @@ def _mkstemp_inner(dir, pre, suf, flags):
try:
fd = _os.open(file, flags, 0600)
_set_cloexec(fd)
- return (fd, file)
+ return (fd, _os.path.abspath(file))
except OSError, e:
if e.errno == _errno.EEXIST:
continue # try again
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index 8df3856..d88d50f 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -49,7 +49,8 @@ class TC(unittest.TestCase):
npre = nbase[:len(pre)]
nsuf = nbase[len(nbase)-len(suf):]
- self.assertEqual(ndir, dir,
+ # check for equality of the absolute paths!
+ self.assertEqual(os.path.abspath(ndir), os.path.abspath(dir),
"file '%s' not in directory '%s'" % (name, dir))
self.assertEqual(npre, pre,
"file '%s' does not begin with '%s'" % (nbase, pre))
@@ -384,6 +385,10 @@ class test_mkstemp(TC):
dir = tempfile.gettempdir()
try:
(fd, name) = tempfile.mkstemp(dir=dir, prefix=pre, suffix=suf)
+ (ndir, nbase) = os.path.split(name)
+ adir = os.path.abspath(dir)
+ self.assertEqual(adir, ndir,
+ "Directory '%s' incorrectly returned as '%s'" % (adir, ndir))
except:
self.failOnException("mkstemp")
@@ -400,6 +405,7 @@ class test_mkstemp(TC):
self.do_create(suf="b")
self.do_create(pre="a", suf="b")
self.do_create(pre="aa", suf=".txt")
+ self.do_create(dir=".")
def test_choose_directory(self):
# mkstemp can create directories in a user-selected directory