[issue5178] Add content manager for temporary directory

2009-02-07 Thread Neil Schemenauer

New submission from Neil Schemenauer nas-pyt...@arctrix.com:

I noticed that it would be nice to have a temporary directory context
manager while trying to fix a broken unittest.  The attached patch
provides a pretty minimal implementation.  There appears to be lots of
unit tests that could use such a thing (just search for rmtree).

I'm not sure if TemporaryDirectory is the best name.  Also, perhaps it
should have a __del__ method although that's tricky business.

--
assignee: ncoghlan
files: tempdir.patch
keywords: patch
messages: 81342
nosy: nascheme, ncoghlan
severity: normal
stage: patch review
status: open
title: Add content manager for temporary directory
type: feature request
Added file: http://bugs.python.org/file12970/tempdir.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5178
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5178] Add content manager for temporary directory

2009-02-07 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

A __del__ method is definitely desirable (tempfile._TemporaryFileWrapper
gives an example of how to cache the relevant globals on the class
object to avoid attempting calls to None during interpreter shutdown).

The new examples are good, but may give the misleading impression that
TemporaryFile can't be used as a context manager (it can, and the file
will be closed at the end of the with statement). A second file example
showing it being used as a context manager would probably be helpful.

There is also at least one existing contextlib based temp_dir context
managers that could be replaced given the addition of this (i.e. in
test_cmd_line_script.py, test_dir could be changed to a class that
inherits from tempfile.TemporaryDirectory and overrides __enter__ to
invoke realname() on the directory name).

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5178
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5178] Add content manager for temporary directory

2009-02-07 Thread Nick Coghlan

Changes by Nick Coghlan ncogh...@gmail.com:


--
priority:  - normal
versions: +Python 2.7, Python 3.1

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5178
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com