Git Product home page Git Product logo

volatile's Introduction

volatile

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.

volatile's People

Contributors

mbr avatar

Watchers

John Vandenberg avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.