Merge pull request #204 from sevdog/fix-realdownload-check

Use safer check in RealDownloadMiddleware
This commit is contained in:
Peter Marheine 2024-08-01 09:53:07 +10:00 committed by GitHub
commit 71488c49c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -75,14 +75,10 @@ class RealDownloadMiddleware(BaseDownloadMiddleware):
whose file attribute have either an URL or a file name.
"""
if super().is_download_response(response):
try:
return response.file.url or response.file.name
except AttributeError:
return False
else:
return True
return False
return (
super().is_download_response(response)
and bool(getattr(response.file, 'url', None) or getattr(response.file, 'name', None))
)
class DownloadDispatcher: