From f8faf217845e05028ce9439088339a5227823b67 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Fri, 23 Aug 2019 15:39:42 -0700 Subject: [PATCH 1/2] make storage pylint-clean --- .../storage/blob/_shared_access_signature.py | 10 ++++-- .../storage/blob/aio/blob_client_async.py | 6 ++-- .../blob/aio/blob_service_client_async.py | 5 +-- .../blob/aio/container_client_async.py | 4 +-- .../azure/storage/blob/blob_client.py | 12 +++---- .../azure/storage/blob/blob_service_client.py | 17 ++++++--- .../azure/storage/blob/container_client.py | 10 +++--- .../azure/storage/blob/lease.py | 4 ++- .../storage/file/_shared_access_signature.py | 10 ++++-- .../file/aio/directory_client_async.py | 5 ++- .../storage/file/aio/file_client_async.py | 3 +- .../file/aio/file_service_client_async.py | 6 ++-- .../storage/file/aio/share_client_async.py | 2 ++ .../azure/storage/file/directory_client.py | 5 ++- .../azure/storage/file/file_client.py | 12 +++---- .../azure/storage/file/file_service_client.py | 19 ++++++---- .../azure/storage/file/share_client.py | 35 ++++++++++--------- .../storage/queue/_shared_access_signature.py | 10 ++++-- .../storage/queue/aio/queue_client_async.py | 12 +++++-- .../queue/aio/queue_service_client_async.py | 2 +- .../azure/storage/queue/queue_client.py | 22 ++++++------ .../storage/queue/queue_service_client.py | 15 +++++--- 22 files changed, 143 insertions(+), 83 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py index f4790d47480d..a71db0b03fc9 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py @@ -1,3 +1,9 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + from azure.storage.blob._shared import sign_string, url_quote from azure.storage.blob._shared.constants import X_MS_VERSION from azure.storage.blob._shared.shared_access_signature import SharedAccessSignature, _SharedAccessHelper, \ @@ -187,7 +193,7 @@ def generate_container(self, container_name, permission=None, expiry=None, class _BlobSharedAccessHelper(_SharedAccessHelper): - def __init__(self): + def __init__(self): # pylint: disable=useless-super-delegation super(_BlobSharedAccessHelper, self).__init__() def add_timestamp(self, timestamp): @@ -254,4 +260,4 @@ def get_token(self): # this is to avoid having two snapshot ids in the query parameters when the user appends the snapshot timestamp exclude = [BlobQueryStringConstants.SIGNED_TIMESTAMP] return '&'.join(['{0}={1}'.format(n, url_quote(v)) - for n, v in self.query_dict.items() if v is not None and n not in exclude]) \ No newline at end of file + for n, v in self.query_dict.items() if v is not None and n not in exclude]) 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 5703f6a7fcf3..4a9a198068a4 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 @@ -1481,9 +1481,9 @@ async def upload_page( # type: ignore :rtype: dict(str, Any) """ options = self._upload_page_options( - page, - start_range, - end_range, + page=page, + start_range=start_range, + end_range=end_range, length=length, validate_content=validate_content, **kwargs) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/blob_service_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/blob_service_client_async.py index a6bbd7c46753..bd3b2e5cb292 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/blob_service_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/blob_service_client_async.py @@ -176,7 +176,7 @@ async def get_service_stats(self, timeout=None, **kwargs): # type: ignore @distributed_trace_async async def get_service_properties(self, timeout=None, **kwargs): - # type(Optional[int]) -> Dict[str, Any] + # type: (Optional[int], Any) -> Dict[str, Any] """Gets the properties of a storage account's Blob service, including Azure Storage Analytics. @@ -472,7 +472,8 @@ def get_blob_client( :type blob: str or ~azure.storage.blob.models.BlobProperties :param snapshot: The optional blob snapshot on which to operate. This can either be the ID of the snapshot, - or a dictionary output returned by :func:`~azure.storage.blob.aio.blob_client_async.BlobClient.create_snapshot()`. + or a dictionary output returned by + :func:`~azure.storage.blob.aio.blob_client_async.BlobClient.create_snapshot()`. :type snapshot: str or dict(str, Any) :returns: A BlobClient. :rtype: ~azure.storage.blob.aio.blob_client_async.BlobClient 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 47d7a8291d04..06829e09f94b 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 @@ -418,8 +418,8 @@ async def set_container_access_policy( public_access=None, # type: Optional[Union[str, PublicAccess]] lease=None, # type: Optional[Union[str, LeaseClient]] timeout=None, # type: Optional[int] - **kwargs - ): + **kwargs # type: Any + ): # type: (...) -> Dict[str, Union[str, datetime]] """Sets the permissions for the specified container or stored access policies that may be used with Shared Access Signatures. The permissions indicate whether blobs in a container may be accessed publicly. 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 331f8b15d76c..8ed459683db6 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 @@ -162,8 +162,8 @@ def __init__( self.snapshot = blob.snapshot # type: ignore except AttributeError: self.blob_name = blob or unquote(path_blob) - self._query_str, credential = self._format_query_string(sas_token, credential, self.snapshot) - super(BlobClient, self).__init__(parsed_url, 'blob', credential, **kwargs) + self._query_str, credential = self._format_query_string(sas_token, credential, snapshot=self.snapshot) + super(BlobClient, self).__init__(parsed_url, service='blob', credential=credential, **kwargs) self._client = AzureBlobStorage(self.url, pipeline=self._pipeline) def _format_url(self, hostname): @@ -185,7 +185,7 @@ def from_connection_string( snapshot=None, # type: Optional[str] credential=None, # type: Optional[Any] **kwargs # type: Any - ): + ): # type: (...) -> BlobClient """ Create BlobClient from a Connection String. @@ -2257,9 +2257,9 @@ def upload_page( # type: ignore :rtype: dict(str, Any) """ options = self._upload_page_options( - page, - start_range, - end_range, + page=page, + start_range=start_range, + end_range=end_range, length=length, validate_content=validate_content, **kwargs) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/blob_service_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/blob_service_client.py index 24840a80e67b..23c7937bb108 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/blob_service_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/blob_service_client.py @@ -113,7 +113,7 @@ def __init__( _, sas_token = parse_query(parsed_url.query) self._query_str, credential = self._format_query_string(sas_token, credential) - super(BlobServiceClient, self).__init__(parsed_url, 'blob', credential, **kwargs) + super(BlobServiceClient, self).__init__(parsed_url, service='blob', credential=credential, **kwargs) self._client = AzureBlobStorage(self.url, pipeline=self._pipeline) def _format_url(self, hostname): @@ -127,7 +127,7 @@ def from_connection_string( cls, conn_str, # type: str credential=None, # type: Optional[Any] **kwargs # type: Any - ): + ): # type: (...) -> BlobServiceClient """Create BlobServiceClient from a Connection String. :param str conn_str: @@ -159,7 +159,7 @@ def generate_shared_access_signature( start=None, # type: Optional[Union[datetime, str]] ip=None, # type: Optional[str] protocol=None # type: Optional[str] - ): + ): # type: (...) -> str """Generates a shared access signature for the blob service. Use the returned signature with the credential parameter of any BlobServiceClient, @@ -214,7 +214,14 @@ def generate_shared_access_signature( sas = SharedAccessSignature(self.credential.account_name, self.credential.account_key) return sas.generate_account( - Services.BLOB, resource_types, permission, expiry, start=start, ip=ip, protocol=protocol) # type: ignore + services=Services.BLOB, + resource_types=resource_types, + permission=permission, + expiry=expiry, + start=start, + ip=ip, + protocol=protocol + ) # type: ignore @distributed_trace def get_account_information(self, **kwargs): # type: ignore @@ -282,7 +289,7 @@ def get_service_stats(self, timeout=None, **kwargs): # type: ignore @distributed_trace def get_service_properties(self, timeout=None, **kwargs): - # type(Optional[int]) -> Dict[str, Any] + # type: (Optional[int], Any) -> Dict[str, Any] """Gets the properties of a storage account's Blob service, including Azure Storage Analytics. 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 e9c6693d533d..a25da2c35e50 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 @@ -16,11 +16,11 @@ from urlparse import urlparse # type: ignore from urllib2 import quote, unquote # type: ignore +import six + from azure.core.paging import ItemPaged from azure.core.tracing.decorator import distributed_trace -import six - from ._shared.base_client import StorageAccountHostsMixin, parse_connection_str, parse_query from ._shared.request_handlers import add_metadata_headers, serialize_iso from ._shared.response_handlers import ( @@ -133,7 +133,7 @@ def __init__( except AttributeError: self.container_name = container or unquote(path_container) # type: ignore self._query_str, credential = self._format_query_string(sas_token, credential) - super(ContainerClient, self).__init__(parsed_url, 'blob', credential, **kwargs) + super(ContainerClient, self).__init__(parsed_url, service='blob', credential=credential, **kwargs) self._client = AzureBlobStorage(self.url, pipeline=self._pipeline) def _format_url(self, hostname): @@ -152,7 +152,7 @@ def from_connection_string( container, # type: Union[str, ContainerProperties] credential=None, # type: Optional[Any] **kwargs # type: Any - ): + ): # type: (...) -> ContainerClient """Create ContainerClient from a Connection String. :param str conn_str: @@ -581,7 +581,7 @@ def set_container_access_policy( lease=None, # type: Optional[Union[str, LeaseClient]] timeout=None, # type: Optional[int] **kwargs - ): + ): # type: (...) -> Dict[str, Union[str, datetime]] """Sets the permissions for the specified container or stored access policies that may be used with Shared Access Signatures. The permissions indicate whether blobs in a container may be accessed publicly. 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 731c625fe8a9..f4c5b227ded0 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/lease.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/lease.py @@ -58,7 +58,9 @@ class LeaseClient(object): A string representing the lease ID of an existing lease. This value does not need to be specified in order to acquire a new lease, or break one. """ - def __init__(self, client, lease_id=None): + def __init__( + self, client, lease_id=None + ): # pylint: disable=missing-client-constructor-parameter-credential,missing-client-constructor-parameter-kwargs # type: (Union[BlobClient, ContainerClient], Optional[str]) -> None self.id = lease_id or str(uuid.uuid4()) self.last_modified = None diff --git a/sdk/storage/azure-storage-file/azure/storage/file/_shared_access_signature.py b/sdk/storage/azure-storage-file/azure/storage/file/_shared_access_signature.py index 858d96e2a5f2..3d153c2a3593 100644 --- a/sdk/storage/azure-storage-file/azure/storage/file/_shared_access_signature.py +++ b/sdk/storage/azure-storage-file/azure/storage/file/_shared_access_signature.py @@ -1,3 +1,9 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + from azure.storage.file._shared import sign_string from azure.storage.file._shared.constants import X_MS_VERSION from azure.storage.file._shared.shared_access_signature import SharedAccessSignature, _str, _SharedAccessHelper, \ @@ -179,7 +185,7 @@ def generate_share(self, share_name, permission=None, expiry=None, class _FileSharedAccessHelper(_SharedAccessHelper): - def __init__(self): + def __init__(self): # pylint: disable=useless-super-delegation super(_FileSharedAccessHelper, self).__init__() def add_resource_signature(self, account_name, account_key, path): @@ -214,4 +220,4 @@ def get_value_to_append(query): string_to_sign = string_to_sign[:-1] self._add_query(QueryStringConstants.SIGNED_SIGNATURE, - sign_string(account_key, string_to_sign)) \ No newline at end of file + sign_string(account_key, string_to_sign)) diff --git a/sdk/storage/azure-storage-file/azure/storage/file/aio/directory_client_async.py b/sdk/storage/azure-storage-file/azure/storage/file/aio/directory_client_async.py index deab7f3507a3..e2afb3e9f8ff 100644 --- a/sdk/storage/azure-storage-file/azure/storage/file/aio/directory_client_async.py +++ b/sdk/storage/azure-storage-file/azure/storage/file/aio/directory_client_async.py @@ -96,6 +96,7 @@ def __init__( # type: ignore self._loop = loop def get_file_client(self, file_name, **kwargs): + # type: (str, Any) -> FileClient """Get a client to interact with a specific file. The file need not already exist. @@ -113,6 +114,7 @@ def get_file_client(self, file_name, **kwargs): _location_mode=self._location_mode, loop=self._loop, **kwargs) def get_subdirectory_client(self, directory_name, **kwargs): + # type: (str, Any) -> DirectoryClient """Get a client to interact with a specific subdirectory. The subdirectory need not already exist. @@ -227,7 +229,8 @@ def list_directories_and_files(self, name_starts_with=None, timeout=None, **kwar page_iterator_class=DirectoryPropertiesPaged) @distributed_trace - def list_handles(self, recursive=False, timeout=None, **kwargs) -> AsyncItemPaged: + def list_handles(self, recursive=False, timeout=None, **kwargs): + # type: (bool, Optional[int], Any) -> AsyncItemPaged """Lists opened handles on a directory or a file under the directory. :param bool recursive: diff --git a/sdk/storage/azure-storage-file/azure/storage/file/aio/file_client_async.py b/sdk/storage/azure-storage-file/azure/storage/file/aio/file_client_async.py index 5ca795b07486..1c4cae12a634 100644 --- a/sdk/storage/azure-storage-file/azure/storage/file/aio/file_client_async.py +++ b/sdk/storage/azure-storage-file/azure/storage/file/aio/file_client_async.py @@ -677,7 +677,8 @@ async def resize_file(self, size, timeout=None, **kwargs): # type: ignore process_storage_error(error) @distributed_trace - def list_handles(self, timeout=None, **kwargs) -> AsyncItemPaged: + def list_handles(self, timeout=None, **kwargs): + # type: (Optional[int], Any) -> AsyncItemPaged """Lists handles for file. :param int timeout: diff --git a/sdk/storage/azure-storage-file/azure/storage/file/aio/file_service_client_async.py b/sdk/storage/azure-storage-file/azure/storage/file/aio/file_service_client_async.py index 9d94ce9f6156..7d72f2caa95f 100644 --- a/sdk/storage/azure-storage-file/azure/storage/file/aio/file_service_client_async.py +++ b/sdk/storage/azure-storage-file/azure/storage/file/aio/file_service_client_async.py @@ -91,7 +91,7 @@ def __init__( @distributed_trace_async async def get_service_properties(self, timeout=None, **kwargs): - # type(Optional[int]) -> Dict[str, Any] + # type: (Optional[int], Any) -> Dict[str, Any] """Gets the properties of a storage account's File service, including Azure Storage Analytics. @@ -166,8 +166,8 @@ def list_shares( include_metadata=False, # type: Optional[bool] include_snapshots=False, # type: Optional[bool] timeout=None, # type: Optional[int] - **kwargs - ) -> AsyncItemPaged: + **kwargs # type: Any + ): # type: (...) -> AsyncItemPaged """Returns auto-paging iterable of dict-like ShareProperties under the specified account. The generator will lazily follow the continuation tokens returned by the service and stop when all shares have been returned. diff --git a/sdk/storage/azure-storage-file/azure/storage/file/aio/share_client_async.py b/sdk/storage/azure-storage-file/azure/storage/file/aio/share_client_async.py index 29728d584bf6..94ce53967f5b 100644 --- a/sdk/storage/azure-storage-file/azure/storage/file/aio/share_client_async.py +++ b/sdk/storage/azure-storage-file/azure/storage/file/aio/share_client_async.py @@ -89,6 +89,7 @@ def __init__( # type: ignore self._loop = loop def get_directory_client(self, directory_path=None): + # type: (Optional[str]) -> DirectoryClient """Get a client to interact with the specified directory. The directory need not already exist. @@ -103,6 +104,7 @@ def get_directory_client(self, directory_path=None): _location_mode=self._location_mode, loop=self._loop) def get_file_client(self, file_path): + # type: (str) -> FileClient """Get a client to interact with the specified file. The file need not already exist. diff --git a/sdk/storage/azure-storage-file/azure/storage/file/directory_client.py b/sdk/storage/azure-storage-file/azure/storage/file/directory_client.py index 3a66cc2a1e8f..e5fcef0ba4cd 100644 --- a/sdk/storage/azure-storage-file/azure/storage/file/directory_client.py +++ b/sdk/storage/azure-storage-file/azure/storage/file/directory_client.py @@ -118,7 +118,7 @@ def __init__( # type: ignore self._query_str, credential = self._format_query_string( sas_token, credential, share_snapshot=self.snapshot) - super(DirectoryClient, self).__init__(parsed_url, 'file', credential, **kwargs) + super(DirectoryClient, self).__init__(parsed_url, service='file', credential=credential, **kwargs) self._client = AzureFileStorage(version=VERSION, url=self.url, pipeline=self._pipeline) def _format_url(self, hostname): @@ -168,6 +168,7 @@ def from_connection_string( account_url, share=share, directory_path=directory_path, credential=credential, **kwargs) def get_file_client(self, file_name, **kwargs): + # type: (str, Any) -> FileClient """Get a client to interact with a specific file. The file need not already exist. @@ -185,6 +186,7 @@ def get_file_client(self, file_name, **kwargs): _location_mode=self._location_mode, **kwargs) def get_subdirectory_client(self, directory_name, **kwargs): + # type: (str, Any) -> DirectoryClient """Get a client to interact with a specific subdirectory. The subdirectory need not already exist. @@ -300,6 +302,7 @@ def list_directories_and_files(self, name_starts_with=None, timeout=None, **kwar @distributed_trace def list_handles(self, recursive=False, timeout=None, **kwargs): + # type: (bool, Optional[int], Any) -> ItemPaged """Lists opened handles on a directory or a file under the directory. :param bool recursive: diff --git a/sdk/storage/azure-storage-file/azure/storage/file/file_client.py b/sdk/storage/azure-storage-file/azure/storage/file/file_client.py index a9ed8a5b4c03..1ecd7ab8b236 100644 --- a/sdk/storage/azure-storage-file/azure/storage/file/file_client.py +++ b/sdk/storage/azure-storage-file/azure/storage/file/file_client.py @@ -167,7 +167,7 @@ def __init__( # type: ignore self.directory_path = "/".join(self.file_path[:-1]) self._query_str, credential = self._format_query_string( sas_token, credential, share_snapshot=self.snapshot) - super(FileClient, self).__init__(parsed_url, 'file', credential, **kwargs) + super(FileClient, self).__init__(parsed_url, service='file', credential=credential, **kwargs) self._client = AzureFileStorage(version=VERSION, url=self.url, pipeline=self._pipeline) def _format_url(self, hostname): @@ -302,11 +302,11 @@ def generate_shared_access_signature( else: file_path = None # type: ignore return sas.generate_file( # type: ignore - self.share_name, - file_path, - self.file_name, - permission, - expiry, + share_name=self.share_name, + directory_name=file_path, + file_name=self.file_name, + permission=permission, + expiry=expiry, start=start, policy_id=policy_id, ip=ip, diff --git a/sdk/storage/azure-storage-file/azure/storage/file/file_service_client.py b/sdk/storage/azure-storage-file/azure/storage/file/file_service_client.py index 48b38754661c..5322d4fcbb78 100644 --- a/sdk/storage/azure-storage-file/azure/storage/file/file_service_client.py +++ b/sdk/storage/azure-storage-file/azure/storage/file/file_service_client.py @@ -98,7 +98,7 @@ def __init__( raise ValueError( 'You need to provide either an account key or SAS token when creating a storage service.') self._query_str, credential = self._format_query_string(sas_token, credential) - super(FileServiceClient, self).__init__(parsed_url, 'file', credential, **kwargs) + super(FileServiceClient, self).__init__(parsed_url, service='file', credential=credential, **kwargs) self._client = AzureFileStorage(version=VERSION, url=self.url, pipeline=self._pipeline) def _format_url(self, hostname): @@ -112,7 +112,7 @@ def from_connection_string( cls, conn_str, # type: str credential=None, # type: Optional[Any] **kwargs # type: Any - ): + ): # type: (...) -> FileServiceClient """Create FileServiceClient from a Connection String. :param str conn_str: @@ -142,7 +142,7 @@ def generate_shared_access_signature( start=None, # type: Optional[Union[datetime, str]] ip=None, # type: Optional[str] protocol=None # type: Optional[str] - ): + ): # type: (...) -> str """Generates a shared access signature for the file service. Use the returned signature with the credential parameter of any FileServiceClient, @@ -195,11 +195,18 @@ def generate_shared_access_signature( sas = SharedAccessSignature(self.credential.account_name, self.credential.account_key) return sas.generate_account( - Services.FILE, resource_types, permission, expiry, start=start, ip=ip, protocol=protocol) # type: ignore + services=Services.FILE, + resource_types=resource_types, + permission=permission, + expiry=expiry, + start=start, + ip=ip, + protocol=protocol + ) # type: ignore @distributed_trace def get_service_properties(self, timeout=None, **kwargs): - # type(Optional[int]) -> Dict[str, Any] + # type: (Optional[int], Any) -> Dict[str, Any] """Gets the properties of a storage account's File service, including Azure Storage Analytics. @@ -349,7 +356,7 @@ def create_share( :caption: Create a share in the file service. """ share = self.get_share_client(share_name) - share.create_share(metadata, quota, timeout, **kwargs) + share.create_share(metadata, quota=quota, timeout=timeout, **kwargs) return share @distributed_trace diff --git a/sdk/storage/azure-storage-file/azure/storage/file/share_client.py b/sdk/storage/azure-storage-file/azure/storage/file/share_client.py index b5ed26f74eb0..7bfc8330b72e 100644 --- a/sdk/storage/azure-storage-file/azure/storage/file/share_client.py +++ b/sdk/storage/azure-storage-file/azure/storage/file/share_client.py @@ -33,7 +33,7 @@ from ._shared_access_signature import FileSharedAccessSignature if TYPE_CHECKING: - from .models import ShareProperties, AccessPolicy + from .models import ShareProperties, AccessPolicy, SharePermissions class ShareClient(StorageAccountHostsMixin): @@ -113,7 +113,7 @@ def __init__( # type: ignore self.share_name = share or unquote(path_share) self._query_str, credential = self._format_query_string( sas_token, credential, share_snapshot=self.snapshot) - super(ShareClient, self).__init__(parsed_url, 'file', credential, **kwargs) + super(ShareClient, self).__init__(parsed_url, service='file', credential=credential, **kwargs) self._client = AzureFileStorage(version=VERSION, url=self.url, pipeline=self._pipeline) def _format_url(self, hostname): @@ -167,17 +167,18 @@ def from_connection_string( account_url, share=share, snapshot=snapshot, credential=credential, **kwargs) def generate_shared_access_signature( - self, permission=None, - expiry=None, - start=None, - policy_id=None, - ip=None, - protocol=None, - cache_control=None, - content_disposition=None, - content_encoding=None, - content_language=None, - content_type=None): + self, permission=None, # type: Optional[Union[SharePermissions, str]] + expiry=None, # type: Optional[Union[datetime, str]] + start=None, # type: Optional[Union[datetime, str]] + policy_id=None, # type: Optional[str] + ip=None, # type: Optional[str] + protocol=None, # type: Optional[str] + cache_control=None, # type: Optional[str] + content_disposition=None, # type: Optional[str] + content_encoding=None, # type: Optional[str] + content_language=None, # type: Optional[str] + content_type=None + ): # type: (...) -> str """Generates a shared access signature for the share. Use the returned signature with the credential parameter of any FileServiceClient, ShareClient, DirectoryClient, or FileClient. @@ -239,9 +240,9 @@ def generate_shared_access_signature( raise ValueError("No account SAS key available.") sas = FileSharedAccessSignature(self.credential.account_name, self.credential.account_key) return sas.generate_share( - self.share_name, - permission, - expiry, + share_name=self.share_name, + permission=permission, + expiry=expiry, start=start, policy_id=policy_id, ip=ip, @@ -254,6 +255,7 @@ def generate_shared_access_signature( ) def get_directory_client(self, directory_path=None): + # type: (Optional[str]) -> DirectoryClient """Get a client to interact with the specified directory. The directory need not already exist. @@ -268,6 +270,7 @@ def get_directory_client(self, directory_path=None): _location_mode=self._location_mode) def get_file_client(self, file_path): + # type: (str) -> FileClient """Get a client to interact with the specified file. The file need not already exist. diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py index 3316bf237001..cd2bdf6be15d 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py @@ -1,3 +1,9 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + from azure.storage.queue._shared import sign_string from azure.storage.queue._shared.constants import X_MS_VERSION from azure.storage.queue._shared.shared_access_signature import SharedAccessSignature, _SharedAccessHelper, \ @@ -73,7 +79,7 @@ def generate_queue(self, queue_name, permission=None, class _QueueSharedAccessHelper(_SharedAccessHelper): - def __init__(self): + def __init__(self): # pylint: disable=useless-super-delegation super(_QueueSharedAccessHelper, self).__init__() def add_resource_signature(self, account_name, account_key, path): # pylint: disable=arguments-differ @@ -103,4 +109,4 @@ def get_value_to_append(query): string_to_sign = string_to_sign[:-1] self._add_query(QueryStringConstants.SIGNED_SIGNATURE, - sign_string(account_key, string_to_sign)) \ No newline at end of file + sign_string(account_key, string_to_sign)) diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_client_async.py index e370da036795..37f9a9f56dec 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_client_async.py @@ -365,7 +365,9 @@ async def enqueue_message( # type: ignore :caption: Enqueue messages. """ self._config.message_encode_policy.configure( - self.require_encryption, self.key_encryption_key, self.key_resolver_function + require_encryption=self.require_encryption, + key_encryption_key=self.key_encryption_key, + resolver=self.key_resolver_function ) content = self._config.message_encode_policy(content) new_message = GenQueueMessage(message_text=content) @@ -429,7 +431,9 @@ def receive_messages(self, messages_per_page=None, visibility_timeout=None, time :caption: Receive messages from the queue. """ self._config.message_decode_policy.configure( - self.require_encryption, self.key_encryption_key, self.key_resolver_function + require_encryption=self.require_encryption, + key_encryption_key=self.key_encryption_key, + resolver=self.key_resolver_function ) try: command = functools.partial( @@ -584,7 +588,9 @@ async def peek_messages(self, max_messages=None, timeout=None, **kwargs): # typ if max_messages and not 1 <= max_messages <= 32: raise ValueError("Number of messages to peek should be between 1 and 32") self._config.message_decode_policy.configure( - self.require_encryption, self.key_encryption_key, self.key_resolver_function + require_encryption=self.require_encryption, + key_encryption_key=self.key_encryption_key, + resolver=self.key_resolver_function ) try: messages = await self._client.messages.peek( diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_service_client_async.py b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_service_client_async.py index 0e57858ea5cd..96577954ad61 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_service_client_async.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/aio/queue_service_client_async.py @@ -223,7 +223,7 @@ def list_queues( results_per_page=None, # type: Optional[int] timeout=None, # type: Optional[int] **kwargs - ) -> AsyncItemPaged: + ): # type: (...) -> AsyncItemPaged """Returns a generator to list the queues under the specified account. The generator will lazily follow the continuation tokens returned by diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/queue_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/queue_client.py index 019d00395264..d1fc7766aaf6 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/queue_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/queue_client.py @@ -107,7 +107,7 @@ def __init__( except AttributeError: self.queue_name = queue or unquote(path_queue) self._query_str, credential = self._format_query_string(sas_token, credential) - super(QueueClient, self).__init__(parsed_url, 'queue', credential, **kwargs) + super(QueueClient, self).__init__(parsed_url, service='queue', credential=credential, **kwargs) self._config.message_encode_policy = kwargs.get('message_encode_policy') or TextXMLEncodePolicy() self._config.message_decode_policy = kwargs.get('message_decode_policy') or TextXMLDecodePolicy() @@ -168,7 +168,7 @@ def generate_shared_access_signature( policy_id=None, # type: Optional[str] ip=None, # type: Optional[str] protocol=None # type: Optional[str] - ): + ): # type: (...) -> str """Generates a shared access signature for the queue. Use the returned signature with the credential parameter of any Queue Service. @@ -490,9 +490,9 @@ def enqueue_message( # type: ignore :caption: Enqueue messages. """ self._config.message_encode_policy.configure( - self.require_encryption, - self.key_encryption_key, - self.key_resolver_function) + require_encryption=self.require_encryption, + key_encryption_key=self.key_encryption_key, + resolver=self.key_resolver_function) content = self._config.message_encode_policy(content) new_message = GenQueueMessage(message_text=content) @@ -554,9 +554,9 @@ def receive_messages(self, messages_per_page=None, visibility_timeout=None, time :caption: Receive messages from the queue. """ self._config.message_decode_policy.configure( - self.require_encryption, - self.key_encryption_key, - self.key_resolver_function) + require_encryption=self.require_encryption, + key_encryption_key=self.key_encryption_key, + resolver=self.key_resolver_function) try: command = functools.partial( self._client.messages.dequeue, @@ -703,9 +703,9 @@ def peek_messages(self, max_messages=None, timeout=None, **kwargs): # type: igno if max_messages and not 1 <= max_messages <= 32: raise ValueError("Number of messages to peek should be between 1 and 32") self._config.message_decode_policy.configure( - self.require_encryption, - self.key_encryption_key, - self.key_resolver_function) + require_encryption=self.require_encryption, + key_encryption_key=self.key_encryption_key, + resolver=self.key_resolver_function) try: messages = self._client.messages.peek( number_of_messages=max_messages, diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/queue_service_client.py b/sdk/storage/azure-storage-queue/azure/storage/queue/queue_service_client.py index 58cd13d57b94..9da5bc06ada8 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/queue_service_client.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/queue_service_client.py @@ -108,7 +108,7 @@ def __init__( if not sas_token and not credential: raise ValueError("You need to provide either a SAS token or an account key to authenticate.") self._query_str, credential = self._format_query_string(sas_token, credential) - super(QueueServiceClient, self).__init__(parsed_url, 'queue', credential, **kwargs) + super(QueueServiceClient, self).__init__(parsed_url, service='queue', credential=credential, **kwargs) self._client = AzureQueueStorage(self.url, pipeline=self._pipeline) def _format_url(self, hostname): @@ -122,7 +122,7 @@ def from_connection_string( cls, conn_str, # type: str credential=None, # type: Optional[Any] **kwargs # type: Any - ): + ): # type: (...) -> QueueServiceClient """Create QueueServiceClient from a Connection String. :param str conn_str: @@ -154,7 +154,7 @@ def generate_shared_access_signature( start=None, # type: Optional[Union[datetime, str]] ip=None, # type: Optional[str] protocol=None # type: Optional[str] - ): + ): # type: (...) -> str """Generates a shared access signature for the queue service. Use the returned signature with the credential parameter of any Queue Service. @@ -196,7 +196,14 @@ def generate_shared_access_signature( sas = SharedAccessSignature(self.credential.account_name, self.credential.account_key) return sas.generate_account( - Services.QUEUE, resource_types, permission, expiry, start=start, ip=ip, protocol=protocol) # type: ignore + services=Services.QUEUE, + resource_types=resource_types, + permission=permission, + expiry=expiry, + start=start, + ip=ip, + protocol=protocol + ) # type: ignore @distributed_trace def get_service_stats(self, timeout=None, **kwargs): # type: ignore From 09433c6139223fdd233dccd06e3e2fbc27eba237 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Fri, 23 Aug 2019 16:10:11 -0700 Subject: [PATCH 2/2] feedback --- .../azure/storage/blob/_shared_access_signature.py | 2 -- .../azure/storage/file/_shared_access_signature.py | 2 -- .../azure/storage/queue/_shared_access_signature.py | 2 -- 3 files changed, 6 deletions(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py index a71db0b03fc9..e127185d7895 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_shared_access_signature.py @@ -193,8 +193,6 @@ def generate_container(self, container_name, permission=None, expiry=None, class _BlobSharedAccessHelper(_SharedAccessHelper): - def __init__(self): # pylint: disable=useless-super-delegation - super(_BlobSharedAccessHelper, self).__init__() def add_timestamp(self, timestamp): self._add_query(BlobQueryStringConstants.SIGNED_TIMESTAMP, timestamp) diff --git a/sdk/storage/azure-storage-file/azure/storage/file/_shared_access_signature.py b/sdk/storage/azure-storage-file/azure/storage/file/_shared_access_signature.py index 3d153c2a3593..5c4e99a1c568 100644 --- a/sdk/storage/azure-storage-file/azure/storage/file/_shared_access_signature.py +++ b/sdk/storage/azure-storage-file/azure/storage/file/_shared_access_signature.py @@ -185,8 +185,6 @@ def generate_share(self, share_name, permission=None, expiry=None, class _FileSharedAccessHelper(_SharedAccessHelper): - def __init__(self): # pylint: disable=useless-super-delegation - super(_FileSharedAccessHelper, self).__init__() def add_resource_signature(self, account_name, account_key, path): def get_value_to_append(query): diff --git a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py index cd2bdf6be15d..d4b2e27327f8 100644 --- a/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py +++ b/sdk/storage/azure-storage-queue/azure/storage/queue/_shared_access_signature.py @@ -79,8 +79,6 @@ def generate_queue(self, queue_name, permission=None, class _QueueSharedAccessHelper(_SharedAccessHelper): - def __init__(self): # pylint: disable=useless-super-delegation - super(_QueueSharedAccessHelper, self).__init__() def add_resource_signature(self, account_name, account_key, path): # pylint: disable=arguments-differ def get_value_to_append(query):