Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/multiplexer/filter/filter.py
Show All 18 Lines | class ObjStorageFilter(ObjStorage): | ||||
Filters can inherit from it and only redefine some methods in order | Filters can inherit from it and only redefine some methods in order | ||||
to change behavior. | to change behavior. | ||||
""" | """ | ||||
def __init__(self, storage): | def __init__(self, storage): | ||||
self.storage = storage | self.storage = storage | ||||
def __contains__(self, *args, **kwargs): | def __contains__(self, *args, **kwargs): | ||||
""" Indicates if the given object is present in the storage | |||||
See base class [ObjStorage]. | |||||
""" | |||||
return self.storage.__contains__(*args, **kwargs) | return self.storage.__contains__(*args, **kwargs) | ||||
def __iter__(self): | def __iter__(self): | ||||
""" Iterates over the content of each storages | |||||
Warning: The `__iter__` methods frequently have bad performance. You | |||||
almost certainly don't want to use this method in production as the | |||||
wrapped storage may cause performance issues. | |||||
""" | |||||
return self.storage.__iter__() | return self.storage.__iter__() | ||||
def __len__(self): | def __len__(self): | ||||
""" Compute the number of objects in the current object storage. | |||||
Warning: performance issue in `__iter__` also applies here. | |||||
Returns: | |||||
number of objects contained in the storage. | |||||
""" | |||||
return self.storage.__len__() | return self.storage.__len__() | ||||
def add(self, *args, **kwargs): | def add(self, content, obj_id=None, check_presence=True, *args, **kwargs): | ||||
return self.storage.add(*args, **kwargs) | """ Add a new object to the object storage. | ||||
def restore(self, *args, **kwargs): | See base class [ObjStorage]. | ||||
return self.storage.restore(*args, **kwargs) | """ | ||||
return self.storage.add(content, obj_id, check_presence, | |||||
*args, **kwargs) | |||||
def get(self, *args, **kwargs): | def restore(self, content, obj_id=None, *args, **kwargs): | ||||
return self.storage.get(*args, **kwargs) | """ Restore a content that have been corrupted. | ||||
def check(self, *args, **kwargs): | See base class [ObjStorage] & self.add() method. | ||||
return self.storage.check(*args, **kwargs) | """ | ||||
return self.storage.restore(content, obj_id, *args, **kwargs) | |||||
def get_random(self, *args, **kwargs): | def get(self, obj_id, *args, **kwargs): | ||||
return self.storage.get_random(*args, **kwargs) | """ Retrieve the content of a given object. | ||||
See base class [ObjStorage]. | |||||
""" | |||||
return self.storage.get(obj_id, *args, **kwargs) | |||||
def check(self, obj_id, *args, **kwargs): | |||||
""" Perform an integrity check for a given object. | |||||
See base class [ObjStorage]. | |||||
""" | |||||
return self.storage.check(obj_id, *args, **kwargs) | |||||
def get_random(self, batch_size, *args, **kwargs): | |||||
""" Get random ids of existing contents | |||||
See base class [ObjStorage]. | |||||
""" | |||||
return self.storage.get_random(batch_size, *args, **kwargs) |