refactored url_has_any_extension function

Co-authored-by: Adrián Chaves <adrian@chaves.io>
This commit is contained in:
Yann Defretin 2022-03-17 11:19:09 +01:00 committed by GitHub
parent 5b4b8b6fb1
commit 0905d42e33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -31,7 +31,8 @@ def url_is_from_spider(url, spider):
def url_has_any_extension(url, extensions):
"""Return True if the url ends with one of the extensions provided"""
return any(parse_url(url).path.lower().endswith(ext) for ext in extensions)
lowercase_path = parse_url(url).path.lower()
return any(lowercase_path.endswith(ext) for ext in extensions)
def parse_url(url, encoding=None):
"""Return urlparsed url from the given argument (which could be an already