[Python-Dev] Python 2.5.1 (original) (raw)
Calvin Spealman ironfroggy at gmail.com
Sat Apr 28 20:21:12 CEST 2007
- Previous message: [Python-Dev] Python 2.5.1
- Next message: [Python-Dev] Python 2.5.1
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 4/28/07, Jean-Paul Calderone <exarkun at divmod.com> wrote:
On Sat, 28 Apr 2007 09:32:57 -0400, Raghuram Devarakonda <draghuram at gmail.com> wrote: >On 4/28/07, Calvin Spealman <ironfroggy at gmail.com> wrote: >> Index: testos.py >> =================================================================== >> --- testos.py (revision 54982) >> +++ testos.py (working copy) >> @@ -6,6 +6,7 @@ >> import unittest >> import warnings >> import sys >> +import tempfile >> from test import testsupport >> >> warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, name) >> @@ -241,13 +242,18 @@ >> self.assertEquals(os.stat(self.fname).stmtime, t1) >> >> def test1686475(self): >> + fn = tempfile.mktemp() >> + openfile = open(fn, 'w') >> # Verify that an open file can be stat'ed >> try: >> - os.stat(r"c:\pagefile.sys") >> + os.stat(fn) >> except WindowsError, e: >> if e == 2: # file does not exist; cannot run test >> return >> self.fail("Could not stat pagefile.sys") >> + finally: >> + openfile.close() >> + os.remove(fn) >> >> from test import mappingtests > >mktemp() is deprecated. You may want to use mkstemp(). There will be >no need for explicit open as well as mkstemp() also returns open >descriptor.
You still need fdopen() though, since os.stat() won't take a file descriptor. The patch is incomplete though, since it should remove the ENOENT handling and the remaining reference to pagefile.sys. As for mktemp() being deprecated - the docstring warns users away, but actually calling it emits no warning. Sure, using it can lead to insecurities, but there's hardly any worry of that here. If the function were actually deprecated (that is, if calling it emitted a DeprecationWarning), that would be a good reason to avoid calling it, though. Jean-Paul
Yes, duh, I changed the pagefile.sys in the message, which was silly to have left.
As for os.fdopen(), it is not needed. tempfile.mkstemp() returns both the file descriptor and the path, so we simply ignore the file descriptor and pass the path to os.stat().
I'll report the patch with the message fixed.
-- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/
- Previous message: [Python-Dev] Python 2.5.1
- Next message: [Python-Dev] Python 2.5.1
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]