MCPcopy Create free account
hub / github.com/ipython/ipython / NamedFileInTemporaryDirectory

Class NamedFileInTemporaryDirectory

IPython/utils/tempdir.py:11–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10
11class 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()
30 self._tmpdir.cleanup()
31
32 __del__ = cleanup
33
34 def __enter__(self):
35 return self.file
36
37 def __exit__(self, type, value, traceback):
38 self.cleanup()
39
40
41class TemporaryWorkingDirectory(TemporaryDirectory):

Callers 3

test_ipython_embedFunction · 0.90
test_video_embeddingFunction · 0.90

Calls

no outgoing calls

Tested by 3

test_ipython_embedFunction · 0.72
test_video_embeddingFunction · 0.72