Skip to content

Commit bdedb5d

Browse files
author
Aaron Sierra
committed
Fix Python 2 pathname type set by from_archive()
A trailing comma resulted in Entry.pathname being a tuple instead of a string when using Entry.from_archive() in Python 2. This partially reverts 5013165 ("Fix tests for python 2 and 3"), which accounted for Entry.pathname as a tuple, instead of addressing why it had become one. This also adds whitespace around the assignment operator for Python 2 and 3 to look less like a keyword argument assignment (which appears to be where the comma originally came from).
1 parent 6189b30 commit bdedb5d

2 files changed

Lines changed: 5 additions & 11 deletions

File tree

libarchive/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,11 @@ def from_archive(cls, archive, encoding=ENCODING):
312312
call_and_check(_libarchive.archive_read_next_header2, archive._a, archive._a, e)
313313
mode = _libarchive.archive_entry_filetype(e)
314314
mode |= _libarchive.archive_entry_perm(e)
315+
315316
if PY3:
316-
pathname=_libarchive.archive_entry_pathname(e)
317+
pathname = _libarchive.archive_entry_pathname(e)
317318
else:
318-
pathname=_libarchive.archive_entry_pathname(e).decode(encoding),
319+
pathname = _libarchive.archive_entry_pathname(e).decode(encoding)
319320

320321
entry = cls(
321322
pathname=pathname,
@@ -628,11 +629,7 @@ def reopen(self):
628629
def getentry(self, pathname):
629630
'''Take a name or entry object and returns an entry object.'''
630631
for entry in self:
631-
if PY3:
632-
entry_pathname = entry.pathname
633-
if not PY3:
634-
entry_pathname = entry.pathname[0]
635-
if entry_pathname == pathname:
632+
if entry.pathname == pathname:
636633
return entry
637634
raise KeyError(pathname)
638635

tests.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,7 @@ def test_filenames(self):
150150
z = ZipFile(self.f, 'r')
151151
names = []
152152
for e in z:
153-
if PY3:
154-
names.append(e.filename)
155-
else:
156-
names.append(e.filename[0])
153+
names.append(e.filename)
157154
self.assertEqual(names, FILENAMES, 'File names differ in archive.')
158155

159156
#~ def test_non_ascii(self):

0 commit comments

Comments
 (0)