Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/api/client.py
# Copyright (C) 2015-2017 The Software Heritage developers | # Copyright (C) 2015-2017 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 | ||||
import abc | |||||
from swh.core.api import SWHRemoteAPI | from swh.core.api import SWHRemoteAPI, MetaSWHRemoteAPI | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from ..objstorage import ObjStorage, DEFAULT_CHUNK_SIZE | from ..objstorage import ObjStorage, DEFAULT_CHUNK_SIZE | ||||
from ..exc import ObjNotFoundError, ObjStorageAPIError | from ..exc import ObjNotFoundError, ObjStorageAPIError | ||||
class RemoteObjStorage(ObjStorage, SWHRemoteAPI): | class MetaRemoteObjStorage(MetaSWHRemoteAPI, abc.ABCMeta): | ||||
"""Hackish class to make multiple inheritance with different metaclasses | |||||
work.""" | |||||
pass | |||||
class RemoteObjStorage(ObjStorage, SWHRemoteAPI, | |||||
metaclass=MetaRemoteObjStorage): | |||||
"""Proxy to a remote object storage. | """Proxy to a remote object storage. | ||||
This class allows to connect to an object storage server via | This class allows to connect to an object storage server via | ||||
http protocol. | http protocol. | ||||
Attributes: | Attributes: | ||||
url (string): The url of the server to connect. Must end | url (string): The url of the server to connect. Must end | ||||
with a '/' | with a '/' | ||||
session: The session to send requests. | session: The session to send requests. | ||||
""" | """ | ||||
def __init__(self, url, **kwargs): | def __init__(self, url, **kwargs): | ||||
super().__init__(api_exception=ObjStorageAPIError, url=url, **kwargs) | super().__init__(api_exception=ObjStorageAPIError, url=url, **kwargs) | ||||
def check_config(self, *, check_write): | def check_config(self, *, check_write): | ||||
return self.post('check_config', {'check_write': check_write}) | return self.post('check_config', {'check_write': check_write}) | ||||
def __contains__(self, obj_id): | def __contains__(self, obj_id): | ||||
return self.post('content/contains', {'obj_id': obj_id}) | return self.post('content/contains', {'obj_id': obj_id}) | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |