|
56 | 56 | normalize_dtype, normalize_fill_value, normalize_order,
|
57 | 57 | normalize_shape, normalize_storage_path, retry_call)
|
58 | 58 |
|
| 59 | +from zarr._storage.abstore import ABSStore |
| 60 | + |
59 | 61 | __doctest_requires__ = {
|
60 | 62 | ('RedisStore', 'RedisStore.*'): ['redis'],
|
61 | 63 | ('MongoDBStore', 'MongoDBStore.*'): ['pymongo'],
|
62 |
| - ('ABSStore', 'ABSStore.*'): ['azure.storage.blob'], |
63 | 64 | ('LRUStoreCache', 'LRUStoreCache.*'): ['s3fs'],
|
64 | 65 | }
|
65 | 66 |
|
@@ -2208,196 +2209,6 @@ def __delitem__(self, key):
|
2208 | 2209 | self._invalidate_value(key)
|
2209 | 2210 |
|
2210 | 2211 |
|
2211 |
| -class ABSStore(MutableMapping): |
2212 |
| - """Storage class using Azure Blob Storage (ABS). |
2213 |
| -
|
2214 |
| - Parameters |
2215 |
| - ---------- |
2216 |
| - container : string |
2217 |
| - The name of the ABS container to use. |
2218 |
| - .. deprecated:: |
2219 |
| - Use ``client`` instead. |
2220 |
| - prefix : string |
2221 |
| - Location of the "directory" to use as the root of the storage hierarchy |
2222 |
| - within the container. |
2223 |
| - account_name : string |
2224 |
| - The Azure blob storage account name. |
2225 |
| - .. deprecated:: 2.8.3 |
2226 |
| - Use ``client`` instead. |
2227 |
| - account_key : string |
2228 |
| - The Azure blob storage account access key. |
2229 |
| - .. deprecated:: 2.8.3 |
2230 |
| - Use ``client`` instead. |
2231 |
| - blob_service_kwargs : dictionary |
2232 |
| - Extra arguments to be passed into the azure blob client, for e.g. when |
2233 |
| - using the emulator, pass in blob_service_kwargs={'is_emulated': True}. |
2234 |
| - .. deprecated:: 2.8.3 |
2235 |
| - Use ``client`` instead. |
2236 |
| - dimension_separator : {'.', '/'}, optional |
2237 |
| - Separator placed between the dimensions of a chunk. |
2238 |
| - client : azure.storage.blob.ContainerClient, optional |
2239 |
| - And ``azure.storage.blob.ContainerClient`` to connect with. See |
2240 |
| - `here <https://docs.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.containerclient?view=azure-python>`_ # noqa |
2241 |
| - for more. |
2242 |
| -
|
2243 |
| - .. versionadded:: 2.8.3 |
2244 |
| -
|
2245 |
| - Notes |
2246 |
| - ----- |
2247 |
| - In order to use this store, you must install the Microsoft Azure Storage SDK for Python, |
2248 |
| - ``azure-storage-blob>=12.5.0``. |
2249 |
| - """ |
2250 |
| - |
2251 |
| - def __init__(self, container=None, prefix='', account_name=None, account_key=None, |
2252 |
| - blob_service_kwargs=None, dimension_separator=None, |
2253 |
| - client=None, |
2254 |
| - ): |
2255 |
| - self._dimension_separator = dimension_separator |
2256 |
| - self.prefix = normalize_storage_path(prefix) |
2257 |
| - if client is None: |
2258 |
| - # deprecated option, try to construct the client for them |
2259 |
| - msg = ( |
2260 |
| - "Providing 'container', 'account_name', 'account_key', and 'blob_service_kwargs'" |
2261 |
| - "is deprecated. Provide and instance of 'azure.storage.blob.ContainerClient' " |
2262 |
| - "'client' instead." |
2263 |
| - ) |
2264 |
| - warnings.warn(msg, FutureWarning, stacklevel=2) |
2265 |
| - from azure.storage.blob import ContainerClient |
2266 |
| - blob_service_kwargs = blob_service_kwargs or {} |
2267 |
| - client = ContainerClient( |
2268 |
| - "https://{}.blob.core.windows.net/".format(account_name), container, |
2269 |
| - credential=account_key, **blob_service_kwargs |
2270 |
| - ) |
2271 |
| - |
2272 |
| - self.client = client |
2273 |
| - self._container = container |
2274 |
| - self._account_name = account_name |
2275 |
| - self._account_key = account_key |
2276 |
| - |
2277 |
| - def _warn_deprecated(self, property_): |
2278 |
| - msg = ("The {} property is deprecated and will be removed in a future " |
2279 |
| - "version. Get the property from 'ABSStore.client' instead.") |
2280 |
| - warnings.warn(msg.format(property_), FutureWarning, stacklevel=3) |
2281 |
| - |
2282 |
| - @property |
2283 |
| - def container(self): |
2284 |
| - self._warn_deprecated("container") |
2285 |
| - return self._container |
2286 |
| - |
2287 |
| - @property |
2288 |
| - def account_name(self): |
2289 |
| - self._warn_deprecated("account_name") |
2290 |
| - return self._account_name |
2291 |
| - |
2292 |
| - @property |
2293 |
| - def account_key(self): |
2294 |
| - self._warn_deprecated("account_key") |
2295 |
| - return self._account_key |
2296 |
| - |
2297 |
| - def _append_path_to_prefix(self, path): |
2298 |
| - if self.prefix == '': |
2299 |
| - return normalize_storage_path(path) |
2300 |
| - else: |
2301 |
| - return '/'.join([self.prefix, normalize_storage_path(path)]) |
2302 |
| - |
2303 |
| - @staticmethod |
2304 |
| - def _strip_prefix_from_path(path, prefix): |
2305 |
| - # normalized things will not have any leading or trailing slashes |
2306 |
| - path_norm = normalize_storage_path(path) |
2307 |
| - prefix_norm = normalize_storage_path(prefix) |
2308 |
| - if prefix: |
2309 |
| - return path_norm[(len(prefix_norm)+1):] |
2310 |
| - else: |
2311 |
| - return path_norm |
2312 |
| - |
2313 |
| - def __getitem__(self, key): |
2314 |
| - from azure.core.exceptions import ResourceNotFoundError |
2315 |
| - blob_name = self._append_path_to_prefix(key) |
2316 |
| - try: |
2317 |
| - return self.client.download_blob(blob_name).readall() |
2318 |
| - except ResourceNotFoundError: |
2319 |
| - raise KeyError('Blob %s not found' % blob_name) |
2320 |
| - |
2321 |
| - def __setitem__(self, key, value): |
2322 |
| - value = ensure_bytes(value) |
2323 |
| - blob_name = self._append_path_to_prefix(key) |
2324 |
| - self.client.upload_blob(blob_name, value, overwrite=True) |
2325 |
| - |
2326 |
| - def __delitem__(self, key): |
2327 |
| - from azure.core.exceptions import ResourceNotFoundError |
2328 |
| - try: |
2329 |
| - self.client.delete_blob(self._append_path_to_prefix(key)) |
2330 |
| - except ResourceNotFoundError: |
2331 |
| - raise KeyError('Blob %s not found' % key) |
2332 |
| - |
2333 |
| - def __eq__(self, other): |
2334 |
| - return ( |
2335 |
| - isinstance(other, ABSStore) and |
2336 |
| - self.client == other.client and |
2337 |
| - self.prefix == other.prefix |
2338 |
| - ) |
2339 |
| - |
2340 |
| - def keys(self): |
2341 |
| - return list(self.__iter__()) |
2342 |
| - |
2343 |
| - def __iter__(self): |
2344 |
| - if self.prefix: |
2345 |
| - list_blobs_prefix = self.prefix + '/' |
2346 |
| - else: |
2347 |
| - list_blobs_prefix = None |
2348 |
| - for blob in self.client.list_blobs(list_blobs_prefix): |
2349 |
| - yield self._strip_prefix_from_path(blob.name, self.prefix) |
2350 |
| - |
2351 |
| - def __len__(self): |
2352 |
| - return len(self.keys()) |
2353 |
| - |
2354 |
| - def __contains__(self, key): |
2355 |
| - blob_name = self._append_path_to_prefix(key) |
2356 |
| - return self.client.get_blob_client(blob_name).exists() |
2357 |
| - |
2358 |
| - def listdir(self, path=None): |
2359 |
| - dir_path = normalize_storage_path(self._append_path_to_prefix(path)) |
2360 |
| - if dir_path: |
2361 |
| - dir_path += '/' |
2362 |
| - items = [ |
2363 |
| - self._strip_prefix_from_path(blob.name, dir_path) |
2364 |
| - for blob in self.client.walk_blobs(name_starts_with=dir_path, delimiter='/') |
2365 |
| - ] |
2366 |
| - return items |
2367 |
| - |
2368 |
| - def rmdir(self, path=None): |
2369 |
| - dir_path = normalize_storage_path(self._append_path_to_prefix(path)) |
2370 |
| - if dir_path: |
2371 |
| - dir_path += '/' |
2372 |
| - for blob in self.client.list_blobs(name_starts_with=dir_path): |
2373 |
| - self.client.delete_blob(blob) |
2374 |
| - |
2375 |
| - def getsize(self, path=None): |
2376 |
| - store_path = normalize_storage_path(path) |
2377 |
| - fs_path = self._append_path_to_prefix(store_path) |
2378 |
| - if fs_path: |
2379 |
| - blob_client = self.client.get_blob_client(fs_path) |
2380 |
| - else: |
2381 |
| - blob_client = None |
2382 |
| - |
2383 |
| - if blob_client and blob_client.exists(): |
2384 |
| - return blob_client.get_blob_properties().size |
2385 |
| - else: |
2386 |
| - size = 0 |
2387 |
| - if fs_path == '': |
2388 |
| - fs_path = None |
2389 |
| - elif not fs_path.endswith('/'): |
2390 |
| - fs_path += '/' |
2391 |
| - for blob in self.client.walk_blobs(name_starts_with=fs_path, delimiter='/'): |
2392 |
| - blob_client = self.client.get_blob_client(blob) |
2393 |
| - if blob_client.exists(): |
2394 |
| - size += blob_client.get_blob_properties().size |
2395 |
| - return size |
2396 |
| - |
2397 |
| - def clear(self): |
2398 |
| - self.rmdir() |
2399 |
| - |
2400 |
| - |
2401 | 2212 | class SQLiteStore(MutableMapping):
|
2402 | 2213 | """Storage class using SQLite.
|
2403 | 2214 |
|
|
0 commit comments