Skip to content

Commit cce505a

Browse files
[Storage] [Named Keywords] [Blob] _blob_client.py and aio (#40206)
1 parent 7656cf2 commit cce505a

8 files changed

+2524
-545
lines changed

sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py

+1,131-217
Large diffs are not rendered by default.

sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client_helpers.py

+280-101
Large diffs are not rendered by default.

sdk/storage/azure-storage-blob/azure/storage/blob/_blob_service_client.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,17 @@ class BlobServiceClient(StorageAccountHostsMixin, StorageEncryptionMixin):
121121
def __init__(
122122
self, account_url: str,
123123
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
124+
*,
125+
api_version: Optional[str] = None,
126+
# TODO
124127
**kwargs: Any
125128
) -> None:
126129
parsed_url, sas_token = _parse_url(account_url=account_url)
127130
_, sas_token = parse_query(parsed_url.query)
128131
self._query_str, credential = self._format_query_string(sas_token, credential)
129132
super(BlobServiceClient, self).__init__(parsed_url, service='blob', credential=credential, **kwargs)
130133
self._client = AzureBlobStorage(self.url, base_url=self.url, pipeline=self._pipeline)
131-
self._client._config.version = get_api_version(kwargs) # type: ignore [assignment]
134+
self._client._config.version = get_api_version(api_version) # type: ignore [assignment]
132135
self._configure_encryption(kwargs)
133136

134137
def _format_url(self, hostname):
@@ -240,7 +243,7 @@ def get_account_information(self, **kwargs: Any) -> Dict[str, str]:
240243
:caption: Getting account information for the blob service.
241244
"""
242245
try:
243-
return self._client.service.get_account_info(cls=return_response_headers, **kwargs) # type: ignore
246+
return self._client.service.get_account_info(cls=return_response_headers, **kwargs) # type: ignore
244247
except HttpResponseError as error:
245248
process_storage_error(error)
246249

@@ -284,7 +287,7 @@ def get_service_stats(self, **kwargs: Any) -> Dict[str, Any]:
284287
"""
285288
timeout = kwargs.pop('timeout', None)
286289
try:
287-
stats = self._client.service.get_statistics( # type: ignore
290+
stats = self._client.service.get_statistics( # type: ignore
288291
timeout=timeout, use_location=LocationMode.SECONDARY, **kwargs)
289292
return service_stats_deserialize(stats)
290293
except HttpResponseError as error:
@@ -391,7 +394,7 @@ def set_service_properties(
391394
logging=analytics_logging,
392395
hour_metrics=hour_metrics,
393396
minute_metrics=minute_metrics,
394-
cors=CorsRule._to_generated(cors), # pylint: disable=protected-access
397+
cors=CorsRule._to_generated(cors), # pylint: disable=protected-access
395398
default_service_version=target_version,
396399
delete_retention_policy=delete_retention_policy,
397400
static_website=static_website
@@ -648,7 +651,7 @@ def _rename_container(self, name: str, new_name: str, **kwargs: Any) -> Containe
648651
except AttributeError:
649652
kwargs['source_lease_id'] = lease
650653
try:
651-
renamed_container._client.container.rename(name, **kwargs) # pylint: disable = protected-access
654+
renamed_container._client.container.rename(name, **kwargs) # pylint: disable=protected-access
652655
return renamed_container
653656
except HttpResponseError as error:
654657
process_storage_error(error)
@@ -685,7 +688,7 @@ def undelete_container(
685688
warnings.warn("`new_name` is no longer supported.", DeprecationWarning)
686689
container = self.get_container_client(new_name or deleted_container_name)
687690
try:
688-
container._client.container.restore(deleted_container_name=deleted_container_name, # pylint: disable = protected-access
691+
container._client.container.restore(deleted_container_name=deleted_container_name, # pylint: disable=protected-access
689692
deleted_container_version=deleted_container_version,
690693
timeout=kwargs.pop('timeout', None), **kwargs)
691694
return container
@@ -718,8 +721,8 @@ def get_container_client(self, container: Union[ContainerProperties, str]) -> Co
718721
else:
719722
container_name = container
720723
_pipeline = Pipeline(
721-
transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
722-
policies=self._pipeline._impl_policies # pylint: disable = protected-access
724+
transport=TransportWrapper(self._pipeline._transport), # pylint: disable=protected-access
725+
policies=self._pipeline._impl_policies # pylint: disable=protected-access
723726
)
724727
return ContainerClient(
725728
self.url, container_name=container_name,
@@ -776,8 +779,8 @@ def get_blob_client(
776779
else:
777780
container_name = container
778781
_pipeline = Pipeline(
779-
transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access
780-
policies=self._pipeline._impl_policies # pylint: disable = protected-access
782+
transport=TransportWrapper(self._pipeline._transport), # pylint: disable=protected-access
783+
policies=self._pipeline._impl_policies # pylint: disable=protected-access
781784
)
782785
return BlobClient(
783786
self.url, container_name=container_name, blob_name=blob_name, snapshot=snapshot,

sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ def __init__(
137137
self, account_url: str,
138138
container_name: str,
139139
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
140+
*,
141+
api_version: Optional[str] = None,
142+
# TODO
140143
**kwargs: Any
141144
) -> None:
142145
parsed_url, sas_token = _parse_url(account_url=account_url, container_name=container_name)
@@ -146,7 +149,7 @@ def __init__(
146149
self._raw_credential = credential if credential else sas_token
147150
self._query_str, credential = self._format_query_string(sas_token, credential)
148151
super(ContainerClient, self).__init__(parsed_url, service='blob', credential=credential, **kwargs)
149-
self._api_version = get_api_version(kwargs)
152+
self._api_version = get_api_version(api_version)
150153
self._client = self._build_generated_client()
151154
self._configure_encryption(kwargs)
152155

sdk/storage/azure-storage-blob/azure/storage/blob/_serialize.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
if TYPE_CHECKING:
3333
from ._lease import BlobLeaseClient
34+
from aio._lease_async import BlobLeaseClient as AsyncBlobLeaseClient
3435

3536

3637
_SUPPORTED_API_VERSIONS = [
@@ -90,12 +91,16 @@ def _get_match_headers(
9091
return if_match, if_none_match
9192

9293

93-
def get_access_conditions(lease: Optional[Union["BlobLeaseClient", str]]) -> Optional[LeaseAccessConditions]:
94-
try:
95-
lease_id = lease.id # type: ignore
96-
except AttributeError:
97-
lease_id = lease # type: ignore
98-
return LeaseAccessConditions(lease_id=lease_id) if lease_id else None
94+
def get_access_conditions(
95+
lease: Optional[Union["BlobLeaseClient", "AsyncBlobLeaseClient", str]]
96+
) -> Optional[LeaseAccessConditions]:
97+
if lease is None:
98+
return None
99+
if hasattr(lease, "id"):
100+
lease_id = lease.id # type: ignore
101+
else:
102+
lease_id = lease # type: ignore
103+
return LeaseAccessConditions(lease_id=lease_id)
99104

100105

101106
def get_modify_conditions(kwargs: Dict[str, Any]) -> ModifiedAccessConditions:
@@ -143,18 +148,19 @@ def get_container_cpk_scope_info(kwargs: Dict[str, Any]) -> Optional[ContainerCp
143148
return None
144149

145150

146-
def get_api_version(kwargs: Dict[str, Any]) -> str:
147-
api_version = kwargs.get('api_version', None)
151+
def get_api_version(api_version: Optional[str] = None) -> str:
148152
if api_version and api_version not in _SUPPORTED_API_VERSIONS:
149153
versions = '\n'.join(_SUPPORTED_API_VERSIONS)
150154
raise ValueError(f"Unsupported API version '{api_version}'. Please select from:\n{versions}")
151155
return api_version or _SUPPORTED_API_VERSIONS[-1]
152156

157+
153158
def get_version_id(self_vid: Optional[str], kwargs: Dict[str, Any]) -> Optional[str]:
154159
if 'version_id' in kwargs:
155160
return cast(str, kwargs.pop('version_id'))
156161
return self_vid
157162

163+
158164
def serialize_blob_tags_header(tags: Optional[Dict[str, str]] = None) -> Optional[str]:
159165
if tags is None:
160166
return None

0 commit comments

Comments
 (0)