swarmauri-base 0.9.2.dev7__py3-none-any.whl → 0.9.2.dev9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- swarmauri_base/storage/StorageAdapterBase.py +79 -0
- {swarmauri_base-0.9.2.dev7.dist-info → swarmauri_base-0.9.2.dev9.dist-info}/METADATA +2 -2
- {swarmauri_base-0.9.2.dev7.dist-info → swarmauri_base-0.9.2.dev9.dist-info}/RECORD +5 -5
- {swarmauri_base-0.9.2.dev7.dist-info → swarmauri_base-0.9.2.dev9.dist-info}/WHEEL +0 -0
- {swarmauri_base-0.9.2.dev7.dist-info → swarmauri_base-0.9.2.dev9.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import io
|
|
4
4
|
import os
|
|
5
|
+
import re
|
|
5
6
|
from typing import BinaryIO, Optional, Literal
|
|
6
7
|
from pydantic import Field
|
|
7
8
|
|
|
@@ -56,6 +57,84 @@ class StorageAdapterBase(IStorageAdapter, ComponentBase):
|
|
|
56
57
|
def pull(self, prefix: str, dest_dir: str | os.PathLike) -> None:
|
|
57
58
|
self.download_dir(prefix, dest_dir)
|
|
58
59
|
|
|
60
|
+
# ------------------------------------------------------------------
|
|
61
|
+
async def ensure_bucket(self) -> None:
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
# ------------------------------------------------------------------
|
|
65
|
+
async def put_bytes(self, object_key: str, data: bytes, content_type: str) -> None:
|
|
66
|
+
del content_type
|
|
67
|
+
self.put_blob(object_key, data)
|
|
68
|
+
|
|
69
|
+
# ------------------------------------------------------------------
|
|
70
|
+
async def get_bytes(self, object_key: str) -> bytes:
|
|
71
|
+
return self.get_blob(object_key)
|
|
72
|
+
|
|
73
|
+
# ------------------------------------------------------------------
|
|
74
|
+
def _parse_range(self, start: int, length: int, total: int) -> tuple[int, int]:
|
|
75
|
+
if total < 0:
|
|
76
|
+
raise ValueError("total must be >= 0")
|
|
77
|
+
if start < 0:
|
|
78
|
+
raise ValueError("start must be >= 0")
|
|
79
|
+
if length <= 0:
|
|
80
|
+
raise ValueError("length must be > 0")
|
|
81
|
+
if start >= total:
|
|
82
|
+
raise ValueError("range start out of bounds")
|
|
83
|
+
|
|
84
|
+
end_exclusive = min(start + length, total)
|
|
85
|
+
if end_exclusive <= start:
|
|
86
|
+
raise ValueError("invalid range interval")
|
|
87
|
+
return start, end_exclusive
|
|
88
|
+
|
|
89
|
+
# ------------------------------------------------------------------
|
|
90
|
+
def _parse_range_header(
|
|
91
|
+
self, range_header: str, total_size: int
|
|
92
|
+
) -> tuple[int, int]:
|
|
93
|
+
"""Return inclusive ``(start, end)`` for a valid HTTP Range header."""
|
|
94
|
+
if total_size <= 0:
|
|
95
|
+
raise ValueError("total_size must be > 0")
|
|
96
|
+
|
|
97
|
+
m = re.fullmatch(r"bytes=(\d*)-(\d*)", range_header.strip())
|
|
98
|
+
if not m:
|
|
99
|
+
raise ValueError("invalid range header")
|
|
100
|
+
|
|
101
|
+
start_s, end_s = m.group(1), m.group(2)
|
|
102
|
+
|
|
103
|
+
if start_s == "" and end_s == "":
|
|
104
|
+
raise ValueError("invalid range header")
|
|
105
|
+
|
|
106
|
+
if start_s == "":
|
|
107
|
+
suffix_len = int(end_s)
|
|
108
|
+
if suffix_len <= 0:
|
|
109
|
+
raise ValueError("invalid suffix length")
|
|
110
|
+
start = max(total_size - suffix_len, 0)
|
|
111
|
+
end = total_size - 1
|
|
112
|
+
return start, end
|
|
113
|
+
|
|
114
|
+
start = int(start_s)
|
|
115
|
+
if start >= total_size:
|
|
116
|
+
raise ValueError("range start out of bounds")
|
|
117
|
+
|
|
118
|
+
if end_s == "":
|
|
119
|
+
end = total_size - 1
|
|
120
|
+
else:
|
|
121
|
+
end = min(int(end_s), total_size - 1)
|
|
122
|
+
|
|
123
|
+
if end < start:
|
|
124
|
+
raise ValueError("invalid range interval")
|
|
125
|
+
|
|
126
|
+
return start, end
|
|
127
|
+
|
|
128
|
+
# ------------------------------------------------------------------
|
|
129
|
+
async def get_range(self, object_key: str, start: int, length: int) -> bytes:
|
|
130
|
+
payload = await self.get_bytes(object_key)
|
|
131
|
+
parsed_start, parsed_end = self._parse_range(start, length, len(payload))
|
|
132
|
+
return payload[parsed_start:parsed_end]
|
|
133
|
+
|
|
134
|
+
# ------------------------------------------------------------------
|
|
135
|
+
async def remove_object(self, object_key: str) -> None:
|
|
136
|
+
raise NotImplementedError("remove_object() must be implemented by subclass")
|
|
137
|
+
|
|
59
138
|
# ------------------------------------------------------------------
|
|
60
139
|
@classmethod
|
|
61
140
|
def from_uri(cls, uri: str) -> "StorageAdapterBase":
|
|
@@ -157,7 +157,7 @@ swarmauri_base/similarities/SimilarityBase.py,sha256=H2eDLCAGWP2JiGf2iTIeph5WEO3
|
|
|
157
157
|
swarmauri_base/similarities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
158
158
|
swarmauri_base/state/StateBase.py,sha256=0wFosKPNaR_-TSgJ1ZfLx8o9XUMmB6hM-OvPR4M9Ue4,1654
|
|
159
159
|
swarmauri_base/state/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
160
|
-
swarmauri_base/storage/StorageAdapterBase.py,sha256=
|
|
160
|
+
swarmauri_base/storage/StorageAdapterBase.py,sha256=4Xc2xkfl7L2ADZJ_e9DqHuuttZKtnHU1fcHIRsw7mDc,5544
|
|
161
161
|
swarmauri_base/storage/__init__.py,sha256=uAm5dCOX5uCFJo1sCVsCFKMtrbOLAIXY9kut1tAYm5g,85
|
|
162
162
|
swarmauri_base/stt/STTBase.py,sha256=W7tf9expYBtWNfNcvSF6V0uuWkIEeDkjLM-g6lIrBTA,2570
|
|
163
163
|
swarmauri_base/stt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -200,7 +200,7 @@ swarmauri_base/vlms/VLMBase.py,sha256=3EOMIRBddvPamvXXU0eAWFFogE9DqbIcZpr-3vleZi
|
|
|
200
200
|
swarmauri_base/vlms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
201
201
|
swarmauri_base/xmp/EmbedXmpBase.py,sha256=TDCKceS-m0hnsj7LGEmGXKRxUrvxlR0WhFxdenuceEs,1516
|
|
202
202
|
swarmauri_base/xmp/__init__.py,sha256=EOQpEK5Ziq5qmuI5SOoWxBnW7g_ZTv42TFR3n6jwKVY,135
|
|
203
|
-
swarmauri_base-0.9.2.
|
|
204
|
-
swarmauri_base-0.9.2.
|
|
205
|
-
swarmauri_base-0.9.2.
|
|
206
|
-
swarmauri_base-0.9.2.
|
|
203
|
+
swarmauri_base-0.9.2.dev9.dist-info/METADATA,sha256=Kg3azTRwPK_TZs3rg0bC3z7x8KFiPnpLNrtRbzXtlfo,9209
|
|
204
|
+
swarmauri_base-0.9.2.dev9.dist-info/WHEEL,sha256=kJCRJT_g0adfAJzTx2GUMmS80rTJIVHRCfG0DQgLq3o,88
|
|
205
|
+
swarmauri_base-0.9.2.dev9.dist-info/licenses/LICENSE,sha256=djUXOlCxLVszShEpZXshZ7v33G-2qIC_j9KXpWKZSzQ,11359
|
|
206
|
+
swarmauri_base-0.9.2.dev9.dist-info/RECORD,,
|
|
File without changes
|
{swarmauri_base-0.9.2.dev7.dist-info → swarmauri_base-0.9.2.dev9.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|