Skip to content

Commit fcead6f

Browse files
author
Aaron Sierra
committed
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.
1 parent bdedb5d commit fcead6f

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

libarchive/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ def get_func(name, items, index):
117117

118118

119119
def guess_format(filename):
120-
filename, ext = os.path.splitext(filename)
120+
if isinstance(filename, int):
121+
filename = ext = ''
122+
else:
123+
filename, ext = os.path.splitext(filename)
121124
filter = FILTER_EXTENSIONS.get(ext)
122125
if filter:
123126
filename, ext = os.path.splitext(filename)

0 commit comments

Comments
 (0)