src/pylib/Lib/n_tempfile

Search:
Group by:
Source   Edit  

XXX: FIXED-NIM-BUG: though nimAllowNonVarDestructor is defined at least since 2.0.6, it still cannot be compiled till abour 2.1.1

Types

TemporaryDirectoryWrapper = object
  name*: string
Source   Edit  
TemporaryFileCloser[IO] = ref object
  file*: IO
  name*: string
Source   Edit  
TemporaryFileWrapper[IO] = object
Source   Edit  

Vars

tempdir {.threadvar.}: string
Source   Edit  

Consts

templ = "tmp"
Source   Edit  
TMP_MAX = 10000
Source   Edit  

Procs

proc `=destroy`(self: TemporaryDirectoryWrapper) {....raises: [],
    tags: [WriteDirEffect, ReadDirEffect], forbids: [].}
Source   Edit  
proc cleanup(self: TemporaryDirectoryWrapper) {....raises: [Exception],
    tags: [WriteDirEffect, ReadDirEffect], forbids: [].}
Source   Edit  
proc close(self: TemporaryDirectoryWrapper) {....raises: [],
    tags: [WriteDirEffect, ReadDirEffect], forbids: [].}
used to be called in with stmt (Python's doesn't have this) Source   Edit  
proc close[IO](self: TemporaryFileCloser[IO]; unlink = os.removeFile)
Source   Edit  
proc flush[IO](self: TemporaryFileWrapper[IO])
Source   Edit  
proc gettempdir(): string {....raises: [ValueError, OSError, FileNotFoundError],
                            tags: [ReadEnvEffect], forbids: [].}
XXX: TODO: gettempdir() should be considered os.fsencode/fsdecode? Source   Edit  
proc gettempprefix(): string {....raises: [], tags: [], forbids: [].}
Return the default prefix string used by mktemp(). This is 'tmp' on most systems.] Source   Edit  
proc mkdtemp(suffix = sNone; prefix = sNone; dir = sNone): string {.
    ...raises: [ValueError, OSError, FileNotFoundError],
    tags: [ReadEnvEffect, ReadDirEffect], forbids: [].}
Source   Edit  
proc mktemp(suffix = ""; prefix = templ; dir = ""; checker = fileExists): string {.
    ...raises: [OSError], tags: [ReadDirEffect], forbids: [].}
User-callable function to return a unique temporary file/dir name. The file/dir is not created. Source   Edit  
proc TemporaryDirectory(suffix = sNone; prefix = sNone; dir = sNone;
                        ignore_cleanup_errors = False; delete = True): TemporaryDirectoryWrapper {.
    ...raises: [ValueError, OSError, FileNotFoundError, IOError],
    tags: [ReadEnvEffect, ReadDirEffect, WriteDirEffect], forbids: [].}

Example:

import std/os
let d = TemporaryDirectory()
assert dirExists d.name
d.cleanup()
assert not dirExists d.name
Source   Edit  

Converters

converter sToOpt(s: string): SOption {....raises: [], tags: [], forbids: [].}
Source   Edit  

Templates

template name(self: TemporaryFileWrapper): string
Source   Edit  
template NamedTemporaryFile(mode: static[string | char] = "w+b"; buffering = -1;
                            encoding = DefEncoding; newline = DefNewLine;
                            suffix = sNone; prefix = sNone; dir = sNone;
                            delete = True; errors = DefErrors): TemporaryFileWrapper

Example:

var tempf = NamedTemporaryFile("w+t")
let msg = "test"
tempf.write(msg)
tempf.flush()
tempf.seek(0)
let s = tempf.read()
assert s == msg

import std/os
assert fileExists tempf.name
tempf.close()
assert not fileExists tempf.name
Source   Edit  
template read[IO](self: TemporaryFileWrapper[IO];
                  args`gensym13: varargs[typed]): untyped
Source   Edit  
template readline[IO](self: TemporaryFileWrapper[IO];
                      args`gensym14: varargs[typed]): untyped
Source   Edit  
template seek[IO](self: TemporaryFileWrapper[IO];
                  args`gensym15: varargs[typed]): untyped
Source   Edit  
template tell[IO](self: TemporaryFileWrapper[IO];
                  args`gensym16: varargs[typed]): untyped
Source   Edit  
template write[IO](self: TemporaryFileWrapper[IO];
                   args`gensym12: varargs[typed]): untyped
Source   Edit