mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 14:50:16 +00:00
Catch AttributeError in utils.super_len (#5239)
* Catch AttributeError in utils.super_len This allows it to handle files obtained via `Tarfile.extractfile()`.
This commit is contained in:
committed by
Nate Prewitt
parent
e77dd8de6e
commit
2d2447e210
@@ -4,6 +4,7 @@ import os
|
||||
import copy
|
||||
import filecmp
|
||||
from io import BytesIO
|
||||
import tarfile
|
||||
import zipfile
|
||||
from collections import deque
|
||||
|
||||
@@ -86,6 +87,18 @@ class TestSuperLen:
|
||||
assert super_len(fd) == 4
|
||||
assert len(recwarn) == warnings_num
|
||||
|
||||
def test_tarfile_member(self, tmpdir):
|
||||
file_obj = tmpdir.join('test.txt')
|
||||
file_obj.write('Test')
|
||||
|
||||
tar_obj = str(tmpdir.join('test.tar'))
|
||||
with tarfile.open(tar_obj, 'w') as tar:
|
||||
tar.add(str(file_obj), arcname='test.txt')
|
||||
|
||||
with tarfile.open(tar_obj) as tar:
|
||||
member = tar.extractfile('test.txt')
|
||||
assert super_len(member) == 4
|
||||
|
||||
def test_super_len_with__len__(self):
|
||||
foo = [1,2,3,4]
|
||||
len_foo = super_len(foo)
|
||||
|
||||
Reference in New Issue
Block a user