New submission from bbayles <bbay...@gmail.com>:

tarfile.open() allows for specifying both a compression type and a compression 
level. However, the compresslevel parameter doesn't work when using the xz 
modes.

    import tarfile
    good_archive = tarfile.open('/tmp/dummy.tar.gz', 'w:gz', compresslevel=9)
    bad_archive = tarfile.open('/tmp/dummy.tar.gz', 'w:xz', compresslevel=9)

This gives an error in the tarfile.TarFile constructor:

    TypeError: __init__() got an unexpected keyword argument 'compresslevel'

This appears to be due to tarfile.xzopen() specifying a preset keyword instead 
of a compresslevel keyword. This matches the LZMAFile compressor, but it means 
that it doesn't get passed in and is then carried along in the kwargs - see [1].

Changing to lzma.LZMAFile(fileobj or name, mode, preset=compresslevel) seems to 
fix the issue. Assuming that's the right fix, I'll submit a PR.

[1] 
https://github.com/python/cpython/blob/374c6e178a7599aae46c857b17c6c8bc19dfe4c2/Lib/tarfile.py#L1684-L1699

----------
components: Library (Lib)
messages: 310954
nosy: bbayles
priority: normal
severity: normal
status: open
title: tarfile.open() raises TypeError when using compresslevel parameter with 
LZMA
versions: Python 3.6, Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32695>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to