Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/gogs/lister.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from dataclasses import asdict, dataclass | from dataclasses import asdict, dataclass | ||||
import logging | import logging | ||||
import random | import random | ||||
from typing import Any, Dict, Iterator, List, Optional, Tuple | from typing import Any, Dict, Iterator, List, Optional, Tuple | ||||
from urllib.parse import parse_qs, parse_qsl, urlencode, urljoin, urlparse | from urllib.parse import parse_qs, parse_qsl, urlencode, urljoin, urlparse | ||||
import iso8601 | import iso8601 | ||||
import requests | import requests | ||||
from tenacity.before_sleep import before_sleep_log | from tenacity.before_sleep import before_sleep_log | ||||
from swh.lister.utils import throttling_retry | from swh.lister.utils import http_retry | ||||
from swh.scheduler.interface import SchedulerInterface | from swh.scheduler.interface import SchedulerInterface | ||||
from swh.scheduler.model import ListedOrigin | from swh.scheduler.model import ListedOrigin | ||||
from .. import USER_AGENT | from .. import USER_AGENT | ||||
from ..pattern import CredentialsType, Lister | from ..pattern import CredentialsType, Lister | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | def on_anonymous_mode(self): | ||||
raise ValueError("No credentials or API token provided") | raise ValueError("No credentials or API token provided") | ||||
def state_from_dict(self, d: Dict[str, Any]) -> GogsListerState: | def state_from_dict(self, d: Dict[str, Any]) -> GogsListerState: | ||||
return GogsListerState(**d) | return GogsListerState(**d) | ||||
def state_to_dict(self, state: GogsListerState) -> Dict[str, Any]: | def state_to_dict(self, state: GogsListerState) -> Dict[str, Any]: | ||||
return asdict(state) | return asdict(state) | ||||
@throttling_retry(before_sleep=before_sleep_log(logger, logging.WARNING)) | @http_retry(before_sleep=before_sleep_log(logger, logging.WARNING)) | ||||
def page_request( | def page_request( | ||||
self, url: str, params: Dict[str, Any] | self, url: str, params: Dict[str, Any] | ||||
) -> Tuple[Dict[str, Any], Dict[str, Any]]: | ) -> Tuple[Dict[str, Any], Dict[str, Any]]: | ||||
logger.debug("Fetching URL %s with params %s", url, params) | logger.debug("Fetching URL %s with params %s", url, params) | ||||
response = self.session.get(url, params=params) | response = self.session.get(url, params=params) | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |