MCPcopy Index your code
hub / github.com/ipython/ipython / NamedFileInTemporaryDirectory

Class NamedFileInTemporaryDirectory

IPython/utils/tempdir.py:15–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14
15class NamedFileInTemporaryDirectory:
16 def __init__(self, filename: str, mode: str, bufsize: int=-1, add_to_syspath: bool=False, **kwds):
17 """
18 Open a file named `filename` in a temporary directory.
19
20 This context manager is preferred over `NamedTemporaryFile` in
21 stdlib `tempfile` when one needs to reopen the file.
22
23 Arguments `mode` and `bufsize` are passed to `open`.
24 Rest of the arguments are passed to `TemporaryDirectory`.
25
26 """
27 self._tmpdir = TemporaryDirectory(**kwds)
28 path = Path(self._tmpdir.name) / filename
29 encoding = None if "b" in mode else "utf-8"
30 self.file = open(path, mode, bufsize, encoding=encoding)
31
32 def cleanup(self):
33 self.file.close()
34 self._tmpdir.cleanup()
35
36 __del__ = cleanup
37
38 def __enter__(self) -> BufferedWriter:
39 return self.file
40
41 def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]):
42 self.cleanup()
43
44
45class TemporaryWorkingDirectory(TemporaryDirectory):

Callers 3

test_video_embeddingFunction · 0.90
test_ipython_embedFunction · 0.90

Calls

no outgoing calls

Tested by 3

test_video_embeddingFunction · 0.72
test_ipython_embedFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…