Browse Source

Handle file-like objects with integer name attribute

When io.BufferedReader (and others) are init-ed based on a file
descriptor, their name attribute will be an integer. Handle these
objects by explicitly checking for an integer type in guess_format() and
setting sane values (empty strings).

We don't trap an exception because Python 2 and 3 throw different types;
AttributeError and TypeError, respectively. So, this way seemed cleaner.
test_fixup
Aaron Sierra 4 years ago
parent
commit
fcead6fb1d
1 changed files with 4 additions and 1 deletions
  1. +4
    -1
      libarchive/__init__.py

+ 4
- 1
libarchive/__init__.py View File

@@ -117,7 +117,10 @@ def get_func(name, items, index):




def guess_format(filename): def guess_format(filename):
filename, ext = os.path.splitext(filename)
if isinstance(filename, int):
filename = ext = ''
else:
filename, ext = os.path.splitext(filename)
filter = FILTER_EXTENSIONS.get(ext) filter = FILTER_EXTENSIONS.get(ext)
if filter: if filter:
filename, ext = os.path.splitext(filename) filename, ext = os.path.splitext(filename)


Loading…
Cancel
Save