From fcead6fb1d9b58da95a782db1c94475066d98b6a Mon Sep 17 00:00:00 2001 From: Aaron Sierra Date: Tue, 10 Mar 2020 21:51:28 -0500 Subject: [PATCH] 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. --- libarchive/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libarchive/__init__.py b/libarchive/__init__.py index 4ff6b14..985bac4 100644 --- a/libarchive/__init__.py +++ b/libarchive/__init__.py @@ -117,7 +117,10 @@ def get_func(name, items, index): 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) if filter: filename, ext = os.path.splitext(filename)