A small extension for the tempfile module.
Project description
Temporary files and directories.
Contains replacement for tempfile.NamedTemporaryFile that does not delete the file on close(), but still unlinks it after the context manager ends, as well as a mkdtemp-based temporary directory implementation.
Mostly reuses the stdlib implementations, supporting the same signatures.
Due to that, uses the OS’s built-in temporary file facilities, no custom schemes.
Tested on Python 2.6+ and 3.3+
Usage
A typical use-case that is not possible with the regular NamedTemporaryFile:
import volatile
with volatile.file() as tmp:
# tmp behaves like a regular NamedTemporaryFile here, except for that
# it gets unlinked at the end of the context manager, instead of when
# close() is called.
tmp.close()
# run the users $EDITOR
run_editor(tmp.name)
buf = open(tmp.name).read()
# ...
Temporary directories:
import volatile
with volatile.dir(): as dtmp:
pass # ... can use directory here
# a missing dtmp will not throw an exception!
Unix domain sockets:
import volatile
with volatile.unix_socket(): as (sock, addr):
# sock is the bound socket, addr its address on the filesystem
pass # ... can use directory here
The source is fairly short and contains API docs in the comments.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file volatile-2.1.0.tar.gz
.
File metadata
- Download URL: volatile-2.1.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9be36ad508e3354e016c115de0397dc2203b9800a73d9d177ca9d37a8d3a31d3 |
|
MD5 | 8863bbb62432f6d01c095f8f8a7d51a2 |
|
BLAKE2b-256 | 0dc68ab8520c95262ba253e7cc93ba4636bdeeb9ab2c0bdec5034b46e01b607d |