diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2022-09-24 22:15:13 +0300 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2022-09-24 22:15:13 +0300 |
commit | 2fda2c8663933ac1c860767a7fa439e851b77017 (patch) | |
tree | 61418362024e2b705b4ba4a4eccd24d957406e85 /src/snakeoil | |
parent | test/mixins: remove `mk_named_tempfile` (diff) | |
download | snakeoil-2fda2c8663933ac1c860767a7fa439e851b77017.tar.gz snakeoil-2fda2c8663933ac1c860767a7fa439e851b77017.tar.bz2 snakeoil-2fda2c8663933ac1c860767a7fa439e851b77017.zip |
fileutils: remove deprecated `write_file`
Last usage was removed, so we can remove the function as well. In most
cases, like tests, you can use `Path.write_text` or `Path.write_bytes`
instead. If not in tests, just use `open` and `write`.
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'src/snakeoil')
-rw-r--r-- | src/snakeoil/data_source.py | 4 | ||||
-rw-r--r-- | src/snakeoil/fileutils.py | 15 |
2 files changed, 2 insertions, 17 deletions
diff --git a/src/snakeoil/data_source.py b/src/snakeoil/data_source.py index ea85ec72..8b9cf72b 100644 --- a/src/snakeoil/data_source.py +++ b/src/snakeoil/data_source.py @@ -456,7 +456,5 @@ class invokable_data_source(data_source): def transfer_between_files(read_file, write_file, bufsize=(32 * 1024)): - data = read_file.read(bufsize) - while data: + while data := read_file.read(bufsize): write_file.write(data) - data = read_file.read(bufsize) diff --git a/src/snakeoil/fileutils.py b/src/snakeoil/fileutils.py index 7d79a25b..2f9da9a3 100644 --- a/src/snakeoil/fileutils.py +++ b/src/snakeoil/fileutils.py @@ -2,7 +2,7 @@ file related operations, mainly reading """ -__all__ = ("AtomicWriteFile", 'write_file', 'UnbufferedWriteHandle', 'touch') +__all__ = ("AtomicWriteFile", 'UnbufferedWriteHandle', 'touch') types = [""] + list("_%s" % x for x in ("ascii", "utf8")) __all__ += tuple("readfile%s" % x for x in types) + tuple("readlines%s" % x for x in types) del types @@ -36,19 +36,6 @@ def touch(fname, mode=0o644, **kwargs): f.fileno() if os.utime in os.supports_fd else fname, dir_fd=None if os.supports_fd else dir_fd, **kwargs) - -def write_file(path, mode, stream, encoding=None): - f = None - try: - f = open(path, mode, encoding=encoding) - if isinstance(stream, (str, bytes)): - stream = [stream] - for data in stream: - f.write(data) - finally: - if f is not None: - f.close() - def mmap_or_open_for_read(path): size = os.stat(path).st_size if size == 0: |