Open a file named `filename` in a temporary directory. This context manager is preferred over `NamedTemporaryFile` in stdlib `tempfile` when one needs to reopen the file. Arguments `mode` and `bufsize` are passed to `open`. Rest of the arguments are passed
(self, filename, mode='w+b', bufsize=-1, **kwds)
| 11 | class NamedFileInTemporaryDirectory(object): |
| 12 | |
| 13 | def __init__(self, filename, mode='w+b', bufsize=-1, **kwds): |
| 14 | """ |
| 15 | Open a file named `filename` in a temporary directory. |
| 16 | |
| 17 | This context manager is preferred over `NamedTemporaryFile` in |
| 18 | stdlib `tempfile` when one needs to reopen the file. |
| 19 | |
| 20 | Arguments `mode` and `bufsize` are passed to `open`. |
| 21 | Rest of the arguments are passed to `TemporaryDirectory`. |
| 22 | |
| 23 | """ |
| 24 | self._tmpdir = TemporaryDirectory(**kwds) |
| 25 | path = _os.path.join(self._tmpdir.name, filename) |
| 26 | self.file = open(path, mode, bufsize) |
| 27 | |
| 28 | def cleanup(self): |
| 29 | self.file.close() |
nothing calls this directly
no outgoing calls
no test coverage detected