Page MenuHomeSoftware Heritage
Paste P1480

(An Untitled Masterwork)
ActivePublic

Authored by anlambert on Oct 5 2022, 11:42 AM.
diff --git a/swh/lister/nixguix/lister.py b/swh/lister/nixguix/lister.py
index 0471b91..cd07caa 100644
--- a/swh/lister/nixguix/lister.py
+++ b/swh/lister/nixguix/lister.py
@@ -19,10 +19,9 @@ import base64
from dataclasses import dataclass
from enum import Enum
import logging
-from pathlib import Path
import random
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union
-from urllib.parse import parse_qsl, urlparse
+from urllib.parse import parse_qs, urlparse
import requests
from requests.exceptions import ConnectionError, InvalidSchema, SSLError
@@ -157,22 +156,15 @@ def is_tarball(urls: List[str], request: Optional[Any] = None) -> Tuple[bool, st
if urlparsed.scheme not in ("http", "https", "ftp"):
raise ArtifactNatureMistyped(f"Mistyped artifact '{url}'")
- errors = []
- query_params = dict(parse_qsl(urlparsed.query))
- for path in [query_params.get(key) for key in ["f", "file", "url", "name"]] + [
- urlparsed.path
- ]:
- if not path:
- continue
- try:
- file_ = Path(path).suffixes[-1]
- break
- except IndexError as e:
- errors.append(ArtifactWithoutExtension(e))
-
- if errors:
- raise errors[-1]
- return file_.lstrip(".") in TARBALL_EXTENSIONS
+ tarball_ext = any(
+ path.endswith(tuple(TARBALL_EXTENSIONS))
+ for path in (urlparsed.path,) + tuple(parse_qs(urlparsed.query).keys())
+ )
+
+ if tarball_ext:
+ return True
+
+ raise ArtifactWithoutExtension()
index = random.randrange(len(urls))
url = urls[index]