Repository: dtrx-py/dtrx (language: python)

Issue:
Cannot list contents of 7z archive
Hi ,
I really love having one tool to deal with so many archive formats. Thanks.

Unfortunately, i' m getting this error when trying to list archive content with this command:
dtrx -l archive.7z .

I already had experienced this error a few year ago. Since then i have tried many times with different python versions
over  multiple system installs.

Maybe it's related to the 7z output when listing.

```python
File "/home/user/.pyenv/versions/3.11.2/lib/python3.11/site-packages/dtrx/dtrx.py", line 716, in get_filenames
    fn_index = string.rindex(line, " ") + 1
               ^^^^^^^^^^^^^
AttributeError: module 'string' has no attribute 'rindex'
```
Again thanks for the good work.
Have a  nice day.


Discussion / hints:

Fix patch:
diff --git a/dtrx/dtrx.py b/dtrx/dtrx.py
index 2c549a1..ab8a836 100755
--- a/dtrx/dtrx.py
+++ b/dtrx/dtrx.py
@@ -713,8 +713,10 @@ def get_filenames(self):
 
 class SevenExtractor(NoPipeExtractor):
     file_type = "7z file"
-    list_command = ["7z", "l"]
+    list_command = ["7z", "l", "-ba"]
     border_re = re.compile("^[- ]+$")
+    extract_command = ["7z", "x"]
+    space_re = re.compile(" ")
 
     @property
     def extract_command(self):
@@ -727,15 +729,10 @@ def extract_command(self):
         return cmd
 
     def get_filenames(self):
-        fn_index = None
         for line in NoPipeExtractor.get_filenames(self):
-            if self.border_re.match(line):
-                if fn_index is not None:
-                    break
-                else:
-                    fn_index = string.rindex(line, " ") + 1
-            elif fn_index is not None:
-                yield line[fn_index:]
+            if " " in line:
+                pos = line.rindex(" ") + 1
+                yield line[pos:]
         self.archive.close()
 
     def send_stdout_to_dev_null(self):
@@ -767,7 +764,7 @@ def get_filenames(self):
                 if fn_index is not None:
                     break
                 else:
-                    fn_index = string.rindex(line, " ") + 1
+                    fn_index = line.rindex(" ") + 1
             elif fn_index is not None:
                 yield line[fn_index:]
         self.archive.close()
diff --git a/requirements.txt b/requirements.txt
index 8541a6a..40bec4e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,6 +4,6 @@ build==0.8.0
 docutils==0.16
 invoke==1.7.1
 pre-commit==2.20.0
-pyyaml==5.4.1
+pyyaml==5.3.1
 tox==3.26.0
 tox-pyenv==1.1.0
diff --git a/tox.ini b/tox.ini
index 6386205..3917685 100644
--- a/tox.ini
+++ b/tox.ini
@@ -14,7 +14,7 @@ envlist = py27, py37, py38, py39, py3.10, py3.11
 whitelist_externals =
     /bin/bash
 deps =
-    pyyaml==5.4.1
+    pyyaml==5.3.1
 setenv =
     TOX_INI_DIR = {toxinidir}
 commands =


Test patch:
diff --git a/tests/tests.yml b/tests/tests.yml
index 5c4c7cd..43b0c28 100644
--- a/tests/tests.yml
+++ b/tests/tests.yml
@@ -312,6 +312,19 @@
     a/b
     foobar
 
+- name: list contents of 7z
+  options: -n -l
+  filenames: test-1.23.7z
+  output: |
+    test-1.23.7z:
+    test-1.23/1/2/3
+    test-1.23/a/b
+    test-1.23/foobar
+    test-1.23/a
+    test-1.23/1/2
+    test-1.23/1
+    test-1.23
+
 - name: list contents of .arj
   options: -n -l
   filenames: test-1.23.arj