1
1
from abc import abstractmethod , ABC
2
2
3
- from typing import List , Tuple
3
+ from typing import List , Tuple , Optional
4
4
5
5
6
6
class Store (ABC ):
7
- pass
8
-
9
-
10
- class ReadStore (Store ):
11
7
@abstractmethod
12
- async def get (self , key : str ) -> bytes :
8
+ async def get (
9
+ self , key : str , byte_range : Optional [Tuple [int , Optional [int ]]] = None
10
+ ) -> Optional [bytes ]:
13
11
"""Retrieve the value associated with a given key.
14
12
15
13
Parameters
16
14
----------
17
15
key : str
16
+ byte_range : tuple[int, Optional[int]], optional
18
17
19
18
Returns
20
19
-------
@@ -23,7 +22,9 @@ async def get(self, key: str) -> bytes:
23
22
...
24
23
25
24
@abstractmethod
26
- async def get_partial_values (self , key_ranges : List [Tuple [str , Tuple [int , int ]]]) -> List [bytes ]:
25
+ async def get_partial_values (
26
+ self , key_ranges : List [Tuple [str , Tuple [int , int ]]]
27
+ ) -> List [bytes ]:
27
28
"""Retrieve possibly partial values from given key_ranges.
28
29
29
30
Parameters
@@ -38,6 +39,7 @@ async def get_partial_values(self, key_ranges: List[Tuple[str, Tuple[int, int]]]
38
39
"""
39
40
...
40
41
42
+ @abstractmethod
41
43
async def exists (self , key : str ) -> bool :
42
44
"""Check if a key exists in the store.
43
45
@@ -51,8 +53,12 @@ async def exists(self, key: str) -> bool:
51
53
"""
52
54
...
53
55
56
+ @property
57
+ @abstractmethod
58
+ def supports_writes (self ) -> bool :
59
+ """Does the store support writes?"""
60
+ ...
54
61
55
- class WriteStore (ReadStore ):
56
62
@abstractmethod
57
63
async def set (self , key : str , value : bytes ) -> None :
58
64
"""Store a (key, value) pair.
@@ -64,7 +70,8 @@ async def set(self, key: str, value: bytes) -> None:
64
70
"""
65
71
...
66
72
67
- async def delete (self , key : str ) -> None
73
+ @abstractmethod
74
+ async def delete (self , key : str ) -> None :
68
75
"""Remove a key from the store
69
76
70
77
Parameters
@@ -73,10 +80,11 @@ async def delete(self, key: str) -> None
73
80
"""
74
81
...
75
82
76
-
77
- class PartialWriteStore (WriteStore ):
78
- # TODO, instead of using this, should we just check if the store is a PartialWriteStore?
79
- supports_partial_writes = True
83
+ @property
84
+ @abstractmethod
85
+ def supports_partial_writes (self ) -> bool :
86
+ """Does the store support partial writes?"""
87
+ ...
80
88
81
89
@abstractmethod
82
90
async def set_partial_values (self , key_start_values : List [Tuple [str , int , bytes ]]) -> None :
@@ -91,8 +99,12 @@ async def set_partial_values(self, key_start_values: List[Tuple[str, int, bytes]
91
99
"""
92
100
...
93
101
102
+ @property
103
+ @abstractmethod
104
+ def supports_listing (self ) -> bool :
105
+ """Does the store support listing?"""
106
+ ...
94
107
95
- class ListMixin :
96
108
@abstractmethod
97
109
async def list (self ) -> List [str ]:
98
110
"""Retrieve all keys in the store.
@@ -132,11 +144,3 @@ async def list_dir(self, prefix: str) -> List[str]:
132
144
list[str]
133
145
"""
134
146
...
135
-
136
-
137
- class ReadListStore (ReadStore , ListMixin ):
138
- pass
139
-
140
-
141
- class WriteListStore (WriteStore , ListMixin ):
142
- pass
0 commit comments