MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / get_file

Method get_file

tools/tempfiles.py:30–48  ·  view source on GitHub ↗

Return an object representing a RAII-like access to a temp file. The the result is a context manager object that can be used in a 'with' statement: 'with TempFiles.get_file(..) as filename:'. The file will be deleted immediately once the 'with' block is exited.

(self, suffix)

Source from the content-addressed store, hash-verified

28 return named_file
29
30 def get_file(self, suffix):
31 """Return an object representing a RAII-like access to a temp file.
32
33 The the result is a context manager object that can be used in a 'with' statement:
34
35 'with TempFiles.get_file(..) as filename:'.
36
37 The file will be deleted immediately once the 'with' block is exited.
38 """
39 class TempFileObject:
40 def __enter__(self_): # noqa: DC02
41 self_.file = tempfile.NamedTemporaryFile(dir=self.tmpdir, suffix=suffix, delete=False)
42 self_.file.close() # NamedTemporaryFile passes out open file handles, but callers prefer filenames (and open their own handles manually if needed)
43 return self_.file.name
44
45 def __exit__(self_, _type, _value, _traceback): # noqa: DC02
46 if not self.save_debug_files:
47 utils.delete_file(self_.file.name)
48 return TempFileObject()
49
50 def get_dir(self):
51 """Return a named temp directory with the given prefix."""

Callers 6

create_reproduce_fileFunction · 0.80
modularizeFunction · 0.80
finalize_wasmFunction · 0.80
minify_shellMethod · 0.80
run_on_fileFunction · 0.80

Calls 1

TempFileObjectClass · 0.85

Tested by

no test coverage detected