Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dedoc/version.py

# Distribution / packaging
.Python
etc/
env/
build/
develop-eggs/
Expand Down
21 changes: 13 additions & 8 deletions dedoc/readers/archive_reader/archive_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,19 @@ def __read_rar_archive(self, path: str, tmp_dir: str, need_content_analysis: boo
yield self.__save_archive_file(tmp_dir=tmp_dir, file_name=name, file=file, need_content_analysis=need_content_analysis)

def __read_7z_archive(self, path: str, tmp_dir: str, need_content_analysis: bool) -> Iterator[AttachedFile]:
import py7zlib

with open(path, "rb") as content:
arch_file = py7zlib.Archive7z(content)
names = arch_file.getnames()
for name in names:
file = arch_file.getmember(name)
yield self.__save_archive_file(tmp_dir=tmp_dir, file_name=name, file=file, need_content_analysis=need_content_analysis)
import os
import py7zr
import tempfile

with tempfile.TemporaryDirectory() as tmpdir:
with py7zr.SevenZipFile(path, "r") as arch_file:
arch_file.extractall(tmpdir)

for dir_path, _, file_names in os.walk(tmpdir):
for file_name in file_names:
file_path = os.path.join(dir_path, file_name)
with open(file_path, "rb") as file:
yield self.__save_archive_file(tmp_dir=tmp_dir, file_name=file_name, file=file, need_content_analysis=need_content_analysis)

def __save_archive_file(self, tmp_dir: str, file_name: str, file: IO[bytes], need_content_analysis: bool) -> AttachedFile:
import os
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pdf2image==1.10.0 #1.14.0 - there are converting artifacts '№' != '№\n\x0c'
pdfminer.six>=20211012,<=20231228
piexif==1.1.3
puremagic>=1.0,<2.0 # needs libmagic to be installed in the system
pylzma==0.5.0
py7zr~=1.0
pypdf>=4.0,<6.0
pytesseract==0.3.10
python-docx==0.8.11
Expand Down
Binary file removed tests/data/with_attachments/attachments.7z
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/unit_tests/test_module_attachment_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_archive_with_slash(self) -> None:
Tests attachment extraction from archives with files containing slash symbol in the name
"""
file_name_template = "attachments.{}"
for extension in "7z", "tar", "tar.gz", "zip":
for extension in "tar", "tar.gz", "zip":
file_name = file_name_template.format(extension)
files = self.__get_list_of_files_in_archive(file_name)
self.assertEqual(2, len(files))
Expand Down