From d18841b1c6729cfca1da0f0c91900a08c396a4f1 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 8 Jul 2021 09:11:10 +0200 Subject: uninline helper function temporary_static_file --- mdbp/common.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'mdbp/common.py') diff --git a/mdbp/common.py b/mdbp/common.py index 5c67f58..e4f4792 100644 --- a/mdbp/common.py +++ b/mdbp/common.py @@ -198,6 +198,14 @@ def clean_dir(directory: pathlib.Path, patterns: typing.List[str]) -> None: for pattern in patterns): entry.unlink() +@contextlib.contextmanager +def temporary_static_file(content: str) -> typing.Iterator[pathlib.Path]: + """Create a named temporary file with given content and return its path.""" + with tempfile.NamedTemporaryFile("w") as tmpf: + tmpf.write(content) + tmpf.flush() + yield pathlib.Path(tmpf.name) + class AddSpaceSeparatedValues(argparse.Action): """The action extends the destination array with the space-sparated parts of the passed value.""" -- cgit v1.2.3