Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/core/lister_transports.py
# Copyright (C) 2017-2018 the Software Heritage developers | # Copyright (C) 2017-2018 the Software Heritage developers | ||||
# 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 | ||||
import abc | import abc | ||||
import random | import random | ||||
from datetime import datetime | from datetime import datetime | ||||
from email.utils import parsedate | from email.utils import parsedate | ||||
from pprint import pformat | from pprint import pformat | ||||
import logging | import logging | ||||
import requests | import requests | ||||
import xmltodict | import xmltodict | ||||
from typing import Optional, Union | from typing import Optional, Union | ||||
from swh.lister import __version__ | from swh.lister import USER_AGENT_TEMPLATE, __version__ | ||||
from .abstractattribute import AbstractAttribute | from .abstractattribute import AbstractAttribute | ||||
from .lister_base import FetchError | from .lister_base import FetchError | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
Show All 14 Lines | class ListerHttpTransport(abc.ABC): | ||||
EXPECTED_STATUS_CODES = (200, 429, 403, 404) | EXPECTED_STATUS_CODES = (200, 429, 403, 404) | ||||
def request_headers(self): | def request_headers(self): | ||||
"""Returns dictionary of any request headers needed by the server. | """Returns dictionary of any request headers needed by the server. | ||||
MAY BE OVERRIDDEN if request headers are needed. | MAY BE OVERRIDDEN if request headers are needed. | ||||
""" | """ | ||||
return { | return { | ||||
'User-Agent': 'Software Heritage lister (%s)' % self.lister_version | 'User-Agent': USER_AGENT_TEMPLATE % self.lister_version | ||||
} | } | ||||
def request_instance_credentials(self): | def request_instance_credentials(self): | ||||
"""Returns dictionary of any credentials configuration needed by the | """Returns dictionary of any credentials configuration needed by the | ||||
forge instance to list. | forge instance to list. | ||||
The 'credentials' configuration is expected to be a dict of multiple | The 'credentials' configuration is expected to be a dict of multiple | ||||
levels. The first level is the lister's name, the second is the | levels. The first level is the lister's name, the second is the | ||||
▲ Show 20 Lines • Show All 176 Lines • Show Last 20 Lines |