diff --git a/libarchive/entry.py b/libarchive/entry.py index 84ccd78..bd5e223 100644 --- a/libarchive/entry.py +++ b/libarchive/entry.py @@ -20,7 +20,7 @@ def format_time(seconds, nanos): return int(seconds) -class ArchiveEntry(object): +class ArchiveEntry: __slots__ = ('_archive_p', '_entry_p') diff --git a/libarchive/read.py b/libarchive/read.py index 4a252c6..c7b3c84 100644 --- a/libarchive/read.py +++ b/libarchive/read.py @@ -3,12 +3,14 @@ from os import fstat, stat from . import ffi -from .ffi import (ARCHIVE_EOF, OPEN_CALLBACK, READ_CALLBACK, CLOSE_CALLBACK, - SEEK_CALLBACK, VOID_CB, page_size) +from .ffi import ( + ARCHIVE_EOF, OPEN_CALLBACK, READ_CALLBACK, CLOSE_CALLBACK, SEEK_CALLBACK, + VOID_CB, page_size, +) from .entry import ArchiveEntry, new_archive_entry -class ArchiveRead(object): +class ArchiveRead: def __init__(self, archive_p): self._pointer = archive_p @@ -54,9 +56,9 @@ def new_archive_read(format_name='all', filter_name='all', passphrase=None): @contextmanager def custom_reader( - read_func, format_name='all', filter_name='all', - open_func=VOID_CB, close_func=VOID_CB, block_size=page_size, - archive_read_class=ArchiveRead, passphrase=None, + read_func, format_name='all', filter_name='all', + open_func=VOID_CB, close_func=VOID_CB, block_size=page_size, + archive_read_class=ArchiveRead, passphrase=None, ): """Read an archive using a custom function. """ @@ -69,8 +71,9 @@ def custom_reader( @contextmanager -def fd_reader(fd, format_name='all', filter_name='all', block_size=4096, - passphrase=None): +def fd_reader( + fd, format_name='all', filter_name='all', block_size=4096, passphrase=None, +): """Read an archive from a file descriptor. """ with new_archive_read(format_name, filter_name, passphrase) as archive_p: @@ -83,8 +86,9 @@ def fd_reader(fd, format_name='all', filter_name='all', block_size=4096, @contextmanager -def file_reader(path, format_name='all', filter_name='all', block_size=4096, - passphrase=None): +def file_reader( + path, format_name='all', filter_name='all', block_size=4096, passphrase=None, +): """Read an archive from a file. """ with new_archive_read(format_name, filter_name, passphrase) as archive_p: @@ -106,8 +110,10 @@ def memory_reader(buf, format_name='all', filter_name='all', passphrase=None): @contextmanager -def stream_reader(stream, format_name='all', filter_name='all', - block_size=page_size, passphrase=None): +def stream_reader( + stream, format_name='all', filter_name='all', block_size=page_size, + passphrase=None, +): """Read an archive from a stream. The `stream` object must support the standard `readinto` method. @@ -133,8 +139,10 @@ def read_func(archive_p, context, ptrptr): @contextmanager -def seekable_stream_reader(stream, format_name='all', filter_name='all', - block_size=page_size, passphrase=None): +def seekable_stream_reader( + stream, format_name='all', filter_name='all', block_size=page_size, + passphrase=None, +): """Read an archive from a seekable stream. The `stream` object must support the standard `readinto`, 'seek' and diff --git a/libarchive/write.py b/libarchive/write.py index e5b3963..6d023b3 100644 --- a/libarchive/write.py +++ b/libarchive/write.py @@ -27,7 +27,7 @@ def new_archive_read_disk(path, flags=0, lookup=False): read_free(archive_p) -class ArchiveWrite(object): +class ArchiveWrite: def __init__(self, archive_p): self._pointer = archive_p @@ -75,9 +75,9 @@ def add_files(self, *paths, **kw): entry_clear(entry_p) def add_file_from_memory( - self, entry_path, entry_size, entry_data, - filetype=REGULAR_FILE, permission=DEFAULT_UNIX_PERMISSION, - atime=None, mtime=None, ctime=None, birthtime=None, + self, entry_path, entry_size, entry_data, + filetype=REGULAR_FILE, permission=DEFAULT_UNIX_PERMISSION, + atime=None, mtime=None, ctime=None, birthtime=None, ): """"Add file from memory to archive. @@ -146,10 +146,7 @@ def add_file_from_memory( @contextmanager -def new_archive_write(format_name, - filter_name=None, - options='', - passphrase=None): +def new_archive_write(format_name, filter_name=None, options='', passphrase=None): archive_p = ffi.write_new() try: ffi.get_write_format_function(format_name)(archive_p) @@ -189,9 +186,9 @@ def new_archive_write(format_name, @contextmanager def custom_writer( - write_func, format_name, filter_name=None, - open_func=VOID_CB, close_func=VOID_CB, block_size=page_size, - archive_write_class=ArchiveWrite, options='', passphrase=None, + write_func, format_name, filter_name=None, + open_func=VOID_CB, close_func=VOID_CB, block_size=page_size, + archive_write_class=ArchiveWrite, options='', passphrase=None, ): def write_cb_internal(archive_p, context, buffer_, length): @@ -212,8 +209,8 @@ def write_cb_internal(archive_p, context, buffer_, length): @contextmanager def fd_writer( - fd, format_name, filter_name=None, - archive_write_class=ArchiveWrite, options='', passphrase=None, + fd, format_name, filter_name=None, + archive_write_class=ArchiveWrite, options='', passphrase=None, ): with new_archive_write(format_name, filter_name, options, passphrase) as archive_p: @@ -223,8 +220,8 @@ def fd_writer( @contextmanager def file_writer( - filepath, format_name, filter_name=None, - archive_write_class=ArchiveWrite, options='', passphrase=None, + filepath, format_name, filter_name=None, + archive_write_class=ArchiveWrite, options='', passphrase=None, ): with new_archive_write(format_name, filter_name, options, passphrase) as archive_p: @@ -234,8 +231,8 @@ def file_writer( @contextmanager def memory_writer( - buf, format_name, filter_name=None, - archive_write_class=ArchiveWrite, options='', passphrase=None, + buf, format_name, filter_name=None, + archive_write_class=ArchiveWrite, options='', passphrase=None, ): with new_archive_write(format_name, filter_name, options, passphrase) as archive_p: diff --git a/tests/test_security_flags.py b/tests/test_security_flags.py index 04c3fc4..d0302da 100644 --- a/tests/test_security_flags.py +++ b/tests/test_security_flags.py @@ -1,13 +1,13 @@ """Test security-related extraction flags.""" -from __future__ import division, print_function, unicode_literals import pytest import os from libarchive import extract_file from libarchive.ffi import version_number -from libarchive.extract import EXTRACT_SECURE_NOABSOLUTEPATHS, \ - EXTRACT_SECURE_NODOTDOT +from libarchive.extract import ( + EXTRACT_SECURE_NOABSOLUTEPATHS, EXTRACT_SECURE_NODOTDOT, +) from libarchive.exception import ArchiveError from . import data_dir @@ -24,13 +24,14 @@ def run_test(flag, filename): def test_no_dot_dot(): - run_test(EXTRACT_SECURE_NODOTDOT, - '../python-libarchive-c-test-dot-dot-file') + run_test(EXTRACT_SECURE_NODOTDOT, '../python-libarchive-c-test-dot-dot-file') def test_absolute(): # EXTRACT_SECURE_NOABSOLUTEPATHS was only added in 3.1.900 # 3.1.900 -> 3001009 if version_number() >= 3001009: - run_test(EXTRACT_SECURE_NOABSOLUTEPATHS, - '/tmp/python-libarchive-c-test-absolute-file') + run_test( + EXTRACT_SECURE_NOABSOLUTEPATHS, + '/tmp/python-libarchive-c-test-absolute-file' + )