Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/client.py
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | ): | ||||
if config: | if config: | ||||
url, auth = handle_deprecated_config(config) | url, auth = handle_deprecated_config(config) | ||||
# needed to help mypy not be fooled by the Optional nature of url | # needed to help mypy not be fooled by the Optional nature of url | ||||
assert url is not None | assert url is not None | ||||
self.base_url = url.strip("/") + "/" | self.base_url = url.strip("/") + "/" | ||||
self.auth = auth | self.auth = auth | ||||
self.session = requests.Session() | |||||
if auth: | |||||
self.session.auth = auth | |||||
def do(self, method, url, *args, **kwargs): | def do(self, method, url, *args, **kwargs): | ||||
"""Internal method to deal with requests, possibly with basic http | """Internal method to deal with requests, possibly with basic http | ||||
authentication. | authentication. | ||||
Args: | Args: | ||||
method (str): supported http methods as in self._methods' keys | method (str): supported http methods as in self._methods' keys | ||||
Returns: | Returns: | ||||
The request's execution | The request's execution | ||||
""" | """ | ||||
method_fn = getattr(requests, method) | |||||
if self.auth: | |||||
kwargs["auth"] = self.auth | |||||
full_url = urljoin(self.base_url, url.lstrip("/")) | full_url = urljoin(self.base_url, url.lstrip("/")) | ||||
return method_fn(full_url, *args, **kwargs) | return self.session.request(method, full_url, *args, **kwargs) | ||||
class PrivateApiDepositClient(BaseApiDepositClient): | class PrivateApiDepositClient(BaseApiDepositClient): | ||||
"""Private API deposit client to: | """Private API deposit client to: | ||||
- read a given deposit's archive(s) | - read a given deposit's archive(s) | ||||
- read a given deposit's metadata | - read a given deposit's metadata | ||||
- update a given deposit's status | - update a given deposit's status | ||||
▲ Show 20 Lines • Show All 551 Lines • Show Last 20 Lines |