brintos

brintos / llvm-project-archived public Read only

0
0
Text · 566 B · a21e212 Raw
24 lines · python
1"""2Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3See https://llvm.org/LICENSE.txt for license information.4SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5"""6 7import os8import tempfile9 10 11class OnDiskTempFile:12    def __init__(self, delete=True):13        self.path = None14 15    def __enter__(self):16        fd, path = tempfile.mkstemp()17        os.close(fd)18        self.path = path19        return self20 21    def __exit__(self, exc_type, exc_val, exc_tb):22        if os.path.exists(self.path):23            os.remove(self.path)24