Commit Graph

70 Commits

Author SHA1 Message Date
Skip Montanaro ea59a84244 A few small changes:
* The only exception we should catch when trying to import cStringIO is an
  ImportError.
* Delete the function signatures embedded in the mk*temp docstrings.
* The tempdir global variable was initialized twice.
2008-04-27 22:49:56 +00:00
Nick Coghlan 97fac3eb0a Issue 2021: Allow NamedTemporaryFile and SpooledTemporaryFile to be used as context managers. (The NamedTemporaryFile fix should be considered for backporting to 2.5) 2008-02-09 15:28:09 +00:00
Neal Norwitz 0d4c06e06e Whitespace normalization. Ugh, we really need to do this more often.
You might want to review this change as it's my first time.  Be gentle. :-)
2007-04-25 06:30:05 +00:00
Collin Winter a8785cc26a Patch #1630118: add a SpooledTemporaryFile class to tempfile. 2007-03-19 18:52:08 +00:00
Georg Brandl 35ef9c19fe Patch #1537850: tempfile.NamedTemporaryFile now has a "delete" parameter
which can be set to False to prevent the default delete-on-close
behavior.
2007-03-13 18:31:49 +00:00
Collin Winter 9b2a109540 Patch #1668482: don't use '-' in mkstemp 2007-03-08 22:16:25 +00:00
Neal Norwitz 946aea2cd5 Param name is dir, not directory. Update docstring. Backport candidate 2006-06-16 04:31:06 +00:00
Martin v. Löwis 879768dd97 Change WindowsError to carry the Win32 error code in winerror,
and the DOS error code in errno. Revert changes where
WindowsError catch blocks unnecessarily special-case OSError.
2006-05-11 13:28:43 +00:00
Martin v. Löwis d4e3bb3d39 Port access, chmod, parts of getcwdu, mkdir, and utime to direct Win32 API. 2006-05-06 16:32:54 +00:00
Raymond Hettinger faa10ebdd0 SF bug #1099516: tempfile files not types.FileType
Clarified that the returned object is file-like rather than an actual file.
2005-01-11 15:33:03 +00:00
Tim Peters 90ee7eb18e Record that FCNTL.py has gone away; remove FCNTL hack in tempfile.py;
another hack remains in test___all__.py, but the problem that one
addresses is more general than *just* FCNTL, so leaving it alone.
2004-07-18 23:58:17 +00:00
Guido van Rossum b256159396 mktemp() shouldn't rely on os.path.exists(), which can return False if
the file is a symlink.  Instead, use os.lstat directly, if it exists;
fall back on os.stat or the built-in open.  Thanks to Iustin Pop.
2003-11-10 02:16:36 +00:00
Alex Martelli f09994e527 fixed wrong error checking on fcntl call as per SF bug # 821896
(same as commit of Sun Nov 2 to the release23-maint branch)
2003-11-09 16:44:09 +00:00
Martin v. Löwis d662548c72 Patch #810914: Return absolute path for mkstemp. Fixes #810408.
This should not be backported to 2.3, as it might break backwards
compatibility.
2003-10-12 17:37:01 +00:00
Tim Peters 291f14e3d3 Windows fix: When PYTHONCASEOK is set, or for any other reason imports
are satisfied in a case-insensitive manner, the attempt to import (the
non-existent) fcntl gets satisfied by FCNTL.py instead, and the tempfile
module defines a Unix-specific _set_cloexec() function in that case.  As
a result, temp files can't be created then (blows up with an AttributeError
trying to reference fcntl.fcntl).  This just popped up in the spambayes
project, where there is no apparent workaround (which is why I'm pushing
this in now).
2003-07-22 02:50:01 +00:00
Jack Jansen bb829b7c02 Getting rid of macfs. 2003-03-21 12:55:38 +00:00
Guido van Rossum a0934246d3 Use the dummy_thread module in Queue.py and tempfile.py.
tempfile.py already contained code to let it run without threads present;
for Queue.py this is considered a useful feature too.
2002-12-30 22:36:09 +00:00
Guido van Rossum 44f602dd3b Comment out the warnings about mktemp(). These are too annoying, and
often unavoidable.
2002-11-22 15:56:29 +00:00
Tim Peters 97701b507b _RandomNameSequence(): style guide changes, small speedup, don't
put more in the critical section than absolutely needed, acquire
the mutex before the "try".
2002-11-21 15:59:59 +00:00
Tim Peters 6ef966e1ad _TemporaryFileWrapper: changed self.close_called to a proper bool. 2002-11-21 15:48:33 +00:00
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