-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement SupportedStorage abstract storage and MemoryStorage s…
…torage
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Dict, Optional | ||
|
||
|
||
class SupportedStorage(ABC): | ||
@abstractmethod | ||
def get_item(self, key: str) -> Optional[str]: | ||
... | ||
|
||
@abstractmethod | ||
def set_item(self, key: str, value: str) -> None: | ||
... | ||
|
||
@abstractmethod | ||
def remove_item(self, key: str) -> None: | ||
... | ||
|
||
|
||
class MemoryStorage(SupportedStorage): | ||
def __init__(self): | ||
self.storage: Dict[str, str] = {} | ||
|
||
def get_item(self, key: str) -> Optional[str]: | ||
return self.storage.get(key) | ||
|
||
def set_item(self, key: str, value: str) -> None: | ||
self.storage[key] = value | ||
|
||
def remove_item(self, key: str) -> None: | ||
del self.storage[key] |