MCPcopy Index your code
hub / github.com/python/cpython / _tempfile

Function _tempfile

Lib/importlib/resources/_common.py:88–111  ·  view source on GitHub ↗
(
    reader,
    suffix='',
    # gh-93353: Keep a reference to call os.remove() in late Python
    # finalization.
    *,
    _os_remove=os.remove,
)

Source from the content-addressed store, hash-verified

86
87@contextlib.contextmanager
88def _tempfile(
89 reader,
90 suffix='',
91 # gh-93353: Keep a reference to call os.remove() in late Python
92 # finalization.
93 *,
94 _os_remove=os.remove,
95):
96 # Not using tempfile.NamedTemporaryFile as it leads to deeper 'try'
97 # blocks due to the need to close the temporary file to work on Windows
98 # properly.
99 fd, raw_path = tempfile.mkstemp(suffix=suffix)
100 try:
101 try:
102 os.write(fd, reader())
103 finally:
104 os.close(fd)
105 del reader
106 yield pathlib.Path(raw_path)
107 finally:
108 try:
109 _os_remove(raw_path)
110 except FileNotFoundError:
111 pass
112
113
114def _temp_file(path):

Callers 1

_temp_fileFunction · 0.85

Calls 3

readerFunction · 0.85
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…