-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathstorage.py
31 lines (21 loc) · 862 Bytes
/
storage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Dict, Optional
class SyncSupportedStorage(ABC):
@abstractmethod
def get_item(self, key: str) -> Optional[str]: ... # pragma: no cover
@abstractmethod
def set_item(self, key: str, value: str) -> None: ... # pragma: no cover
@abstractmethod
def remove_item(self, key: str) -> None: ... # pragma: no cover
class SyncMemoryStorage(SyncSupportedStorage):
def __init__(self):
self.storage: Dict[str, str] = {}
def get_item(self, key: str) -> Optional[str]:
if key in self.storage:
return self.storage[key]
def set_item(self, key: str, value: str) -> None:
self.storage[key] = value
def remove_item(self, key: str) -> None:
if key in self.storage:
del self.storage[key]