MCPcopy Index your code
hub / github.com/RustPython/RustPython / _tempfile

Function _tempfile

Lib/importlib/resources/_common.py:122–145  ·  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

120
121@contextlib.contextmanager
122def _tempfile(
123 reader,
124 suffix='',
125 # gh-93353: Keep a reference to call os.remove() in late Python
126 # finalization.
127 *,
128 _os_remove=os.remove,
129):
130 # Not using tempfile.NamedTemporaryFile as it leads to deeper 'try'
131 # blocks due to the need to close the temporary file to work on Windows
132 # properly.
133 fd, raw_path = tempfile.mkstemp(suffix=suffix)
134 try:
135 try:
136 os.write(fd, reader())
137 finally:
138 os.close(fd)
139 del reader
140 yield pathlib.Path(raw_path)
141 finally:
142 try:
143 _os_remove(raw_path)
144 except FileNotFoundError:
145 pass
146
147
148def _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