Skip to content
Myr

Some usability stuff for atomic writes

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #357

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parent 5855b85 · Browse files · 2 files+14 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−0 removed

  • other:+14 added−0 removed

2 files+14 added−0 removed

modified:click/_compat.py+13 added
401 unmodified lines
402 if encoding is None:403 return open(filename, mode), True404 return io.open(filename, mode, encoding=encoding, errors=errors), True405406 # Some usability stuff for atomic writes407 if 'a' in mode:408 raise ValueError(409 'Appending to an existing file is not supported, because that '410 'would involve an expensive `copy`-operation to a temporary '411 'file. Open the file in normal `w`-mode and copy explicitly '412 'if that\'s what you\'re after.'413 )414 if 'x' in mode:415 raise ValueError('Use the `overwrite`-parameter instead.')416 if 'w' not in mode:417 raise ValueError('Atomic writes only make sense with `w`-mode.')418419 # Atomic writes are more complicated. They work by opening a file420 # as a proxy in the same folder and then using the fdopen421 # functionality to wrap it in a Python file. Then we wrap it in an422 # atomic file that moves the file over on close.
163 unmodified lines
modified:CHANGES+1 added
7 unmodified lines
89(codename to be decided, release date to be determined)1011- Removed various deprecated functionality.12- Atomic files now only accept the `w` mode.1314Version 4.115-----------16
218 unmodified lines