test code working
diff --git a/wally/storage.py b/wally/storage.py
index a17e3c0..6879dcf 100644
--- a/wally/storage.py
+++ b/wally/storage.py
@@ -5,6 +5,7 @@
import os
import abc
import array
+import shutil
from typing import Any, Iterator, TypeVar, Type, IO, Tuple, cast, List, Dict, Union, Iterable
@@ -59,6 +60,10 @@
def sub_storage(self, path: str) -> 'ISimpleStorage':
pass
+ @abc.abstractmethod
+ def clear(self, path: str) -> None:
+ pass
+
class ISerializer(metaclass=abc.ABCMeta):
"""Interface for serialization class"""
@@ -135,6 +140,10 @@
def sub_storage(self, path: str) -> 'FSStorage':
return self.__class__(self.j(path), self.existing)
+ def clear(self, path: str) -> None:
+ if os.path.exists(path):
+ shutil.rmtree(self.j(path))
+
class YAMLSerializer(ISerializer):
"""Serialize data to yaml"""
@@ -175,7 +184,6 @@
def __delitem__(self, path: Union[str, Iterable[str]]) -> None:
if not isinstance(path, str):
path = "/".join(path)
-
del self.storage[path]
def __contains__(self, path: Union[str, Iterable[str]]) -> bool:
@@ -184,14 +192,13 @@
return path in self.storage
def store_raw(self, val: bytes, *path: str) -> None:
- if not isinstance(path, str):
- path = "/".join(path)
- self.storage[path] = val
+ self.storage["/".join(path)] = val
+
+ def clear(self, *path: str) -> None:
+ self.storage.clear("/".join(path))
def get_raw(self, *path: str) -> bytes:
- if not isinstance(path, str):
- path = "/".join(path)
- return self.storage[path]
+ return self.storage["/".join(path)]
def list(self, *path: str) -> Iterator[Tuple[bool, str]]:
return self.storage.list("/".join(path))