miurahr / py7zr

7zip in python3 with ZStandard, PPMd, LZMA2, LZMA1, Delta, BCJ, BZip2, and Deflate compressions, and AES encryption.
https://pypi.org/project/py7zr/
GNU Lesser General Public License v2.1
454 stars 73 forks source link

Add support for `mode="x"` in `SevenZipFile()` constructor #587

Closed Ravencentric closed 1 month ago

Ravencentric commented 5 months ago

Is your feature request related to a problem? Please describe. SevenZipFile does not support mode="x" which stands for "exclusive writing mode".

The official documentation for open() states open for exclusive creation, failing if the file already exists.

From my understanding:

w x
open for writing open for writing
create the file if it doesn't exist create the file if it doesn't exist
Overwrite the file if it exists raise FileExistsError if the file exists

Describe the solution you'd like Considering that w and x are near identical, minimal code changes are required. In fact, seems to me py7zr already has code in place to handle it?

https://github.com/miurahr/py7zr/blob/606b50ea2561601c59a1232b17dec43416f61bab/py7zr/py7zr.py#L360-L361 https://github.com/miurahr/py7zr/blob/606b50ea2561601c59a1232b17dec43416f61bab/py7zr/py7zr.py#L374-L375

But it fails here: https://github.com/miurahr/py7zr/blob/606b50ea2561601c59a1232b17dec43416f61bab/py7zr/py7zr.py#L343-L344

Describe alternatives you've considered Manually check for existing file before opening in mode="w".

Additional context N/A