Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/client.py
Show All 11 Lines | |||||
import logging | import logging | ||||
import os | import os | ||||
from typing import Any, Dict | from typing import Any, Dict | ||||
from urllib.parse import urljoin | from urllib.parse import urljoin | ||||
import requests | import requests | ||||
import xmltodict | import xmltodict | ||||
from swh.core.config import config_basepath, read_raw_config | from swh.core.config import load_from_envvar | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
class MaintenanceError(ValueError): | class MaintenanceError(ValueError): | ||||
"""Informational maintenance error exception | """Informational maintenance error exception | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def _parse_with_filter(stream, encoding="utf-8", keys=[]): | ||||
return m | return m | ||||
class BaseApiDepositClient: | class BaseApiDepositClient: | ||||
"""Deposit client base class | """Deposit client base class | ||||
""" | """ | ||||
def __init__(self, config=None, _client=requests): | def __init__(self, config=None, _client=requests): | ||||
if config is None: | self.config: Dict[str, Any] = config or load_from_envvar() | ||||
vlorentz: alternatively, if you prefer: `self.config = config or load_from_envvar()` | |||||
Done Inline Actionsheh, thanks. ardumont: heh, thanks.
jsyk, i'm adding a test for it... | |||||
config_file = os.environ["SWH_CONFIG_FILENAME"] | |||||
self.config: Dict[str, Any] = read_raw_config(config_basepath(config_file)) | |||||
else: | |||||
self.config = config | |||||
self._client = _client | self._client = _client | ||||
self.base_url = self.config["url"].strip("/") + "/" | self.base_url = self.config["url"].strip("/") + "/" | ||||
auth = self.config["auth"] | auth = self.config["auth"] | ||||
if auth == {}: | if auth == {}: | ||||
self.auth = None | self.auth = None | ||||
else: | else: | ||||
self.auth = (auth["username"], auth["password"]) | self.auth = (auth["username"], auth["password"]) | ||||
▲ Show 20 Lines • Show All 556 Lines • Show Last 20 Lines |
alternatively, if you prefer: self.config = config or load_from_envvar()