Browse Source

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 5013165958 ("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).
test_fixup
Aaron Sierra 4 years ago
parent
commit
bdedb5d597
2 changed files with 5 additions and 11 deletions
  1. +4
    -7
      libarchive/__init__.py
  2. +1
    -4
      tests.py

+ 4
- 7
libarchive/__init__.py View File

@@ -312,10 +312,11 @@ class Entry(object):
call_and_check(_libarchive.archive_read_next_header2, archive._a, archive._a, e)
mode = _libarchive.archive_entry_filetype(e)
mode |= _libarchive.archive_entry_perm(e)

if PY3:
pathname=_libarchive.archive_entry_pathname(e)
pathname = _libarchive.archive_entry_pathname(e)
else:
pathname=_libarchive.archive_entry_pathname(e).decode(encoding),
pathname = _libarchive.archive_entry_pathname(e).decode(encoding)

entry = cls(
pathname=pathname,
@@ -628,11 +629,7 @@ class SeekableArchive(Archive):
def getentry(self, pathname):
'''Take a name or entry object and returns an entry object.'''
for entry in self:
if PY3:
entry_pathname = entry.pathname
if not PY3:
entry_pathname = entry.pathname[0]
if entry_pathname == pathname:
if entry.pathname == pathname:
return entry
raise KeyError(pathname)



+ 1
- 4
tests.py View File

@@ -150,10 +150,7 @@ class TestZipRead(unittest.TestCase):
z = ZipFile(self.f, 'r')
names = []
for e in z:
if PY3:
names.append(e.filename)
else:
names.append(e.filename[0])
names.append(e.filename)
self.assertEqual(names, FILENAMES, 'File names differ in archive.')

#~ def test_non_ascii(self):


Loading…
Cancel
Save