Commit Graph

50 Commits

Author SHA1 Message Date
Guido van Rossum e888cdc683 Get rid of _once(); inlining it takes less code. :-)
Also, don't call gettempdir() in the default expression for the 'dir'
argument to various functions; use 'dir=None' for the default and
insert 'if dir is None: dir = gettemptir()' in the bodies.  That way
the work done by gettempdir is postponed until needed.
2002-08-17 14:50:24 +00:00
Tim Peters 04490bf225 tempfile's mkstemp(): Changed last argument from
binary=True
to
    text=False

by BDFL Pronouncement.  All other changes follow from this.  The change
to the docs is ready to go, but blocked by another JackMacLock in the
doc directory.
2002-08-14 15:41:26 +00:00
Jason Tishler 80c02af345 Patch #595014: Cygwin tempfile patch
Although Cygwin attempts to be as Posix compliant
as possible, it has difficulties unlinking open
files. This is not surprising given that Cygwin is
dependent on Win32 which in turn has this problem
itself.

The attached tempfile patch acknowledges this
Cygwin limitation. Without this patch, Cygwin
fails test_tempfile (i.e., test_has_no_name) as
follows:

$ ./python -E -tt ../Lib/test/regrtest.py -l test_tempfile
test_tempfile
test test_tempfile failed -- Traceback (most recent call last):
  File "/home/jt/src/PythonCvs/Lib/test/test_tempfile.py", line 689, in test_has_no_name
    self.failOnException("rmdir", ei)
  File "/home/jt/src/PythonCvs/Lib/test/test_tempfile.py", line 33, in failOnException
    self.fail("%s raised %s: %s" % (what, ei[0], ei[1]))
  File "/home/jt/src/PythonCvs/Lib/unittest.py", line 260, in fail
    raise self.failureException, msg
AssertionError: rmdir raised exceptions.OSError: [Errno 90] Directory not empty: '/mnt/c/DOCUME~1/jatis/LOCALS~1/Temp/tmpM_z8nj'
2002-08-14 15:10:09 +00:00
Tim Peters d41bf34825 mkstemp(): Repaired error in docstring (the sense of the 'binary' flag
was reversed).
2002-08-14 00:49:50 +00:00
Tim Peters f69b3e9edc mkstemp(): The optional "binary" argument is clearly intended to be a
Boolean, so changed its default value from 1 to True.
2002-08-13 23:38:30 +00:00
Tim Peters c21ea74971 NamedTemporaryFile(), TemporaryFile(): removed needless local vrbl 'bin'. 2002-08-13 23:36:01 +00:00
Tim Peters bd7b4c7e46 template: removed special-casing for NT; there isn't an 8-character limit. 2002-08-13 23:33:56 +00:00
Tim Peters 1749b252c9 _once(): Removed obfuscating aliasing of _once_lock. 2002-08-13 23:31:02 +00:00
Tim Peters fd0f0c9f02 _once(): Simplified dict manipulation. 2002-08-13 23:29:21 +00:00
Tim Peters a0d55de877 Whitespace normalization. 2002-08-09 18:01:01 +00:00
Guido van Rossum 0e54871f82 Check-in of the most essential parts of SF 589982 (tempfile.py
rewrite, by Zack Weinberg).  This replaces most code in tempfile.py
(please review!!!) and adds extensive unit tests for it.

This will cause some warnings in the test suite; I'll check those in
soon, and also the docs.
2002-08-09 16:14:33 +00:00
Raymond Hettinger 54f0222547 SF 563203. Replaced 'has_key()' with 'in'. 2002-06-01 14:18:47 +00:00
Neil Schemenauer 153cc0fddc If possible, set FD_CLOEXEC flag on file descriptors opened using
TemporaryFile.  This flag causes the fd to be closed on exec().
2002-03-24 22:21:48 +00:00
Tim Peters 40915bf8dd Thanks to Detlef Lannert for pointing out a typo in the code that
uses _DummyMutex on platforms without threads.
2002-01-30 09:11:42 +00:00
Tim Peters c7349ee2c6 New TemporaryFile implementation for Windows: this doesn't need a
TemproraryFileWrapper wrapper anymore, and should be immune from the
problem that a temp file inherited by a spawned process caused an
attempt to close the temp file in the spawning process to blow
up (the unlink in TemporaryFileWrapper.close() blew up with a
"Permission denied" error because, despite that the temp file got
closed in the spawning process, the spawned process still had it open
by virtue of C-level file descriptor inheritance).  In context,
that bug took days to figure out <wink/sigh>.
2002-01-30 07:47:51 +00:00
Tim Peters 4fd5a06580 SF bug #509805 tempfile.gettempdir not threadsafe
This is an ancient race when multiple threads call gettempdir() (or
anything relying on it) for the first time.

Fixed x-platform via the Big Hammer of rearranging the code to serialize
the first calls.  Subsequent calls are as fast as before.

Note that the Python test suite can't provoke this bug:  it requires
setting up multiple threads making the very first calls into tempfile,
but the test suite uses tempfile several times before getting to
test_threadedtempfile.

Bugfix candidate.
2002-01-28 23:11:23 +00:00
Tim Peters 81b61bdc1a TemporaryFileWrapper: fixed typo in new comment. 2001-12-18 23:22:01 +00:00
Tim Peters a255a72f0a TemporaryFileWrapper: cache the value of os.unlink for use by __del__,
to prevent mysterious errors at shutdown due to "os.unlink" turning into
"None.unlink".
2001-12-18 22:32:40 +00:00
Tim Peters c57a285cb4 SF bug #476138: tempfile behavior across platforms
Ensure that a tempfile can be closed any number of times without error.
This wasn't true on Windows.
2001-10-29 21:46:08 +00:00
Guido van Rossum e2ae77b8b8 SF patch #474590 -- RISC OS support 2001-10-24 20:42:55 +00:00
Guido van Rossum 7dcf84f2f8 Search /tmp before /var/tmp and /usr/tmp -- this seems preferred.
SF patch #404564, Gregor Hoffleit.
2001-03-02 05:51:16 +00:00
Skip Montanaro 40fc16059f final round of __all__ lists (I hope) - skipped urllib2 because Moshe may be
giving it a slight facelift
2001-03-01 04:27:19 +00:00
Jeremy Hylton c348cd7518 fix long line 2001-02-19 15:34:10 +00:00
Tim Peters b90f89a496 Whitespace normalization. 2001-01-15 03:26:36 +00:00
Tim Peters 8373218e28 Reverting a dumb experimental version I checked in by mistake. 2001-01-14 05:12:40 +00:00
Tim Peters 2caf8df868 SF bug 128713: type(mmap_object) blew up on Linux. 2001-01-14 05:05:51 +00:00
Tim Peters 9fadfb0d1d Guido found a brand new race in tempfile on Linux, due to Linux changing
pid across threads (but in that case, it's still the same process, and so
still sharing the "template" cache in tempfile.py).  Repaired that, and
added a new std test.
On Linux, someone please run that standalone with more files and/or more
threads; e.g.,

    python lib/test/test_threadedtempfile.py -f 1000 -t 10

to run with 10 threads each creating (and deleting) 1000 temp files.
2001-01-13 03:04:02 +00:00
Tim Peters 1baa22aff0 A variant of SF patch 103028 (Make tempfile.mktemp threadsafe).
Tested on Windows.  Should be tested on Linux.  Should also be
tested on some platform without threads (I simulated that by
making the "import thread" fail, but that's not the same as
actually doing it!).
2001-01-12 10:02:46 +00:00
Guido van Rossum e504c0c2dc Patch by tg@FreeBSD.org to try /var/tmp first.
This helps on 4.4BSD-based systems.
2000-08-29 14:55:03 +00:00
Guido van Rossum 00f09b3821 Security patch for Unix by Chris McDonough.
This uses the same precautions when trying to find a temporary
directory as when the actual tempfile is created (using O_CREAT and
O_EXCL).  On non-posix platforms, nothing is changed.
2000-04-24 13:28:02 +00:00
Guido van Rossum e7b146fb3b The third and final doc-string sweep by Ka-Ping Yee.
The attached patches update the standard library so that all modules
have docstrings beginning with one-line summaries.

A new docstring was added to formatter.  The docstring for os.py
was updated to mention nt, os2, ce in addition to posix, dos, mac.
2000-02-04 15:28:42 +00:00
Guido van Rossum 6b708d569c In class TemporaryFileWrapper, don't cache attributes of tpye int --
these happen to be 'closed' and 'softspace', which may change!

Noted by Dave Ascher (with slightly different solution).
1999-06-01 18:55:36 +00:00
Guido van Rossum 2457fc2a81 Improvement to the previous fix suggested by Thomas Bellman: if the
unlink() or fdopen() fail, close the file descriptor and re-raise the
exception.
1998-10-24 15:02:59 +00:00
Guido van Rossum dce3d5502e The TemporaryFile() function has a security leak -- because the
filenames generated are easily predictable, it is possible to trick an
unsuspecting program into overwriting another file by creating a
symbolic link with the predicted name.  Fix this by using the
low-level os.open() function with the O_EXCL flag and mode 0700.  On
non-Unix platforms, presumably there are no symbolic links so the
problem doesn't exist.  The explicit test for Unix (posix, actually)
makes it possible to change the non-Unix logic to work without a
try-except clause.

The mktemp() file is as unsafe as ever.
1998-10-24 01:34:45 +00:00
Guido van Rossum b0e5718643 Fix so that after a fork() -- on Unix only -- the template gets
recalculated.
1998-10-14 20:27:05 +00:00
Guido van Rossum 57a0661cb8 On the Mac, create the Temporary Items folder if it does not exist yet.
(Jack)
1998-04-28 16:03:34 +00:00
Guido van Rossum 29e5f5d81f When getcwd() doesn't exist or raises an exception, don't fail but
fall back to using os.curdir instead; if it is fine, don't use
os.curdir at all.
1998-04-09 14:27:57 +00:00
Guido van Rossum 45e2fbc2e7 Mass check-in after untabifying all files that need it. 1998-03-26 21:13:24 +00:00
Guido van Rossum b8c42c9825 Add new optional parameter 'suffix' (default ''), which is appended to
the temporary file name.  Also some minor formatting of Jim F's code.
1997-12-19 04:29:50 +00:00
Guido van Rossum 80fb344a18 On NT, use a better template, ~XXX- where XXX is os.getpid(). 1997-12-15 19:11:53 +00:00
Guido van Rossum ca54982b2a Added TemporaryFile and wrapper class by Jim Fulton.
Look in more env vars (for NT: TEMP, TMP).
1997-08-12 18:00:12 +00:00
Guido van Rossum f4f756cf55 (Jack:) Better MacOS support. 1997-04-11 19:00:53 +00:00
Guido van Rossum 3e065ada2c Attempt at Windows-NT compatibility. 1996-08-20 20:38:59 +00:00
Guido van Rossum 4033ad7576 Restore 1.3 behavior of gettempdir(): if tempdir is already set, believe it. 1996-08-08 18:33:56 +00:00
Guido van Rossum f4aaf862fd Be more careful about default temp dir 1996-05-28 23:31:34 +00:00
Guido van Rossum 41f9503c11 Mostly rewritten to be more flexible and more portable
./
1992-03-31 19:02:01 +00:00
Guido van Rossum cff3454eff Use $TMPDIR if it is set in the environment. 1992-01-14 18:31:56 +00:00
Guido van Rossum 4a3a41f1bb Use 'global' instead of struct kludge. 1991-12-26 13:10:50 +00:00
Guido van Rossum ce08448165 New class syntax. 1991-12-26 13:06:29 +00:00
Guido van Rossum eee9498b71 Initial revision 1991-11-12 15:38:08 +00:00