Changeset View
Changeset View
Standalone View
Standalone View
swh/journal/writer/inmemory.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 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 logging | import logging | ||||
from multiprocessing import Manager | from multiprocessing import Manager | ||||
from typing import Any, Generic, List, Tuple, TypeVar | from typing import Any, Callable, Dict, Generic, List, Tuple, TypeVar | ||||
from . import ValueProtocol | from . import ValueProtocol | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
TValue = TypeVar("TValue", bound=ValueProtocol) | TValue = TypeVar("TValue", bound=ValueProtocol) | ||||
class InMemoryJournalWriter(Generic[TValue]): | class InMemoryJournalWriter(Generic[TValue]): | ||||
objects: List[Tuple[str, TValue]] | objects: List[Tuple[str, TValue]] | ||||
privileged_objects: List[Tuple[str, TValue]] | privileged_objects: List[Tuple[str, TValue]] | ||||
def __init__(self, value_sanitizer: Any): | def __init__( | ||||
self, value_sanitizer: Callable[[str, Dict[str, Any]], Dict[str, Any]] | |||||
): | |||||
# Share the list of objects across processes, for RemoteAPI tests. | # Share the list of objects across processes, for RemoteAPI tests. | ||||
self.manager = Manager() | self.manager = Manager() | ||||
self.objects = self.manager.list() | self.objects = self.manager.list() | ||||
self.privileged_objects = self.manager.list() | self.privileged_objects = self.manager.list() | ||||
def write_addition( | def write_addition( | ||||
self, object_type: str, object_: TValue, privileged: bool = False | self, object_type: str, object_: TValue, privileged: bool = False | ||||
) -> None: | ) -> None: | ||||
Show All 13 Lines |