Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/multiplexer/filter/id_filter.py
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | def get(self, obj_id, *args, **kwargs): | ||||
return self.storage.get(*args, obj_id=obj_id, **kwargs) | return self.storage.get(*args, obj_id=obj_id, **kwargs) | ||||
raise ObjNotFoundError(obj_id) | raise ObjNotFoundError(obj_id) | ||||
def check(self, obj_id, *args, **kwargs): | def check(self, obj_id, *args, **kwargs): | ||||
if self.is_valid(obj_id): | if self.is_valid(obj_id): | ||||
return self.storage.check(*args, obj_id=obj_id, **kwargs) | return self.storage.check(*args, obj_id=obj_id, **kwargs) | ||||
raise ObjNotFoundError(obj_id) | raise ObjNotFoundError(obj_id) | ||||
def get_random(self, *args, **kwargs): | |||||
yield from filter( | |||||
lambda id: self.is_valid(id), self.storage.get_random(*args, **kwargs) | |||||
) | |||||
class RegexIdObjStorageFilter(IdObjStorageFilter): | class RegexIdObjStorageFilter(IdObjStorageFilter): | ||||
"""Filter that allow operations if the content's id as hex match a regex.""" | """Filter that allow operations if the content's id as hex match a regex.""" | ||||
def __init__(self, storage, regex): | def __init__(self, storage, regex): | ||||
super().__init__(storage) | super().__init__(storage) | ||||
self.regex = re.compile(regex) | self.regex = re.compile(regex) | ||||
Show All 15 Lines |