diff options
author | Helmut Grohne <helmut@subdivi.de> | 2021-07-08 09:11:10 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2021-07-08 09:11:10 +0200 |
commit | d18841b1c6729cfca1da0f0c91900a08c396a4f1 (patch) | |
tree | 316c578b53e8f72d088db251f6d1b7087f581d0b /mdbp/common.py | |
parent | 1ae474fa8b329ea6fc422bbab593e04224290cea (diff) | |
download | mdbp-d18841b1c6729cfca1da0f0c91900a08c396a4f1.tar.gz |
uninline helper function temporary_static_file
Diffstat (limited to 'mdbp/common.py')
-rw-r--r-- | mdbp/common.py | 8 |
1 files changed, 8 insertions, 0 deletions
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.""" |