From 87a6e3282446579115f1fea0e76d4ebf10a01e1b Mon Sep 17 00:00:00 2001 From: tasherif-msft <69483382+tasherif-msft@users.noreply.github.com> Date: Thu, 13 Aug 2020 22:01:16 -0700 Subject: [PATCH] Move get_access_conditions to _serialize.py (#13105) * refactored get access conditions * added newline spacing after refactor * moved the method within serialize * fixed linter --- .../azure/storage/blob/_blob_client.py | 4 ++-- .../azure/storage/blob/_container_client.py | 4 ++-- .../azure/storage/blob/_lease.py | 16 +++------------- .../azure/storage/blob/_serialize.py | 11 ++++++++++- .../azure/storage/blob/aio/_blob_client_async.py | 3 +-- .../storage/blob/aio/_container_client_async.py | 3 +-- .../azure/storage/fileshare/_serialize.py | 1 + 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py index b5366051d7ac..f78cf7319140 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py @@ -44,7 +44,7 @@ get_api_version, serialize_blob_tags_header, serialize_blob_tags, - serialize_query_format + serialize_query_format, get_access_conditions ) from ._deserialize import get_page_ranges_result, deserialize_blob_properties, deserialize_blob_stream, parse_tags from ._quick_query_helper import BlobQueryReader @@ -54,7 +54,7 @@ upload_page_blob) from ._models import BlobType, BlobBlock, BlobProperties, BlobQueryError from ._download import StorageStreamDownloader -from ._lease import BlobLeaseClient, get_access_conditions +from ._lease import BlobLeaseClient if TYPE_CHECKING: from datetime import datetime diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py index d771d19ccfcb..575611c4e7a9 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py @@ -36,13 +36,13 @@ StorageErrorException, SignedIdentifier) from ._deserialize import deserialize_container_properties -from ._serialize import get_modify_conditions, get_container_cpk_scope_info, get_api_version +from ._serialize import get_modify_conditions, get_container_cpk_scope_info, get_api_version, get_access_conditions from ._models import ( # pylint: disable=unused-import ContainerProperties, BlobProperties, BlobType) from ._list_blobs_helper import BlobPrefix, BlobPropertiesPaged -from ._lease import BlobLeaseClient, get_access_conditions +from ._lease import BlobLeaseClient from ._blob_client import BlobClient if TYPE_CHECKING: diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_lease.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_lease.py index 7d384233c221..6180d7851aae 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_lease.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_lease.py @@ -7,32 +7,22 @@ import uuid from typing import ( # pylint: disable=unused-import - Union, Optional, Any, IO, Iterable, AnyStr, Dict, List, Tuple, - TypeVar, TYPE_CHECKING + Union, Optional, Any, TypeVar, TYPE_CHECKING ) from azure.core.tracing.decorator import distributed_trace from ._shared.response_handlers import return_response_headers, process_storage_error -from ._generated.models import StorageErrorException, LeaseAccessConditions +from ._generated.models import StorageErrorException from ._serialize import get_modify_conditions if TYPE_CHECKING: from datetime import datetime - from ._generated.operations import BlobOperations, ContainerOperations + BlobClient = TypeVar("BlobClient") ContainerClient = TypeVar("ContainerClient") -def get_access_conditions(lease): - # type: (Optional[Union[BlobLeaseClient, str]]) -> Union[LeaseAccessConditions, None] - try: - lease_id = lease.id # type: ignore - except AttributeError: - lease_id = lease # type: ignore - return LeaseAccessConditions(lease_id=lease_id) if lease_id else None - - class BlobLeaseClient(object): """Creates a new BlobLeaseClient. diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_serialize.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_serialize.py index 6781096700b5..1b4ee9f4608d 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_serialize.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_serialize.py @@ -26,7 +26,7 @@ JsonTextConfiguration, QueryFormatType, BlobTag, - BlobTags + BlobTags, LeaseAccessConditions ) @@ -63,6 +63,15 @@ def _get_match_headers(kwargs, match_param, etag_param): return if_match, if_none_match +def get_access_conditions(lease): + # type: (Optional[Union[BlobLeaseClient, str]]) -> Union[LeaseAccessConditions, None] + try: + lease_id = lease.id # type: ignore + except AttributeError: + lease_id = lease # type: ignore + return LeaseAccessConditions(lease_id=lease_id) if lease_id else None + + def get_modify_conditions(kwargs): # type: (Dict[str, Any]) -> ModifiedAccessConditions if_match, if_none_match = _get_match_headers(kwargs, 'match_condition', 'etag') diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.py index 3275d02004f8..edf6e2dfc468 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_blob_client_async.py @@ -16,7 +16,7 @@ from .._shared.policies_async import ExponentialRetry from .._shared.response_handlers import return_response_headers, process_storage_error from .._deserialize import get_page_ranges_result, parse_tags -from .._serialize import get_modify_conditions, get_api_version +from .._serialize import get_modify_conditions, get_api_version, get_access_conditions from .._generated import VERSION from .._generated.aio import AzureBlobStorage from .._generated.models import StorageErrorException, CpkInfo @@ -27,7 +27,6 @@ upload_append_blob, upload_page_blob) from .._models import BlobType, BlobBlock, BlobProperties -from .._lease import get_access_conditions from ._lease_async import BlobLeaseClient from ._download_async import StorageStreamDownloader diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py index 6217e9958478..0554fc661459 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py @@ -30,9 +30,8 @@ StorageErrorException, SignedIdentifier) from .._deserialize import deserialize_container_properties -from .._serialize import get_modify_conditions, get_container_cpk_scope_info, get_api_version +from .._serialize import get_modify_conditions, get_container_cpk_scope_info, get_api_version, get_access_conditions from .._container_client import ContainerClient as ContainerClientBase, _get_blob_name -from .._lease import get_access_conditions from .._models import ContainerProperties, BlobType, BlobProperties # pylint: disable=unused-import from ._list_blobs_helper import BlobPropertiesPaged, BlobPrefix from ._lease_async import BlobLeaseClient diff --git a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_serialize.py b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_serialize.py index c0755118477e..769eb975bed2 100644 --- a/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_serialize.py +++ b/sdk/storage/azure-storage-file-share/azure/storage/fileshare/_serialize.py @@ -54,6 +54,7 @@ def get_source_conditions(kwargs): source_if_none_match=if_none_match or kwargs.pop('source_if_none_match', None) ) + def get_access_conditions(lease): # type: (Optional[Union[ShareLeaseClient, str]]) -> Union[LeaseAccessConditions, None] try: