From f4a5aebdc8b961ee799d8809e0d55f9f53b98984 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 14 Oct 2019 14:22:27 -0700 Subject: [PATCH 1/7] Queue kwargification --- .../storage/queue/aio/queue_client_async.py | 109 +++++++++-------- .../queue/aio/queue_service_client_async.py | 36 +++--- .../azure/storage/queue/queue_client.py | 114 ++++++++++-------- .../storage/queue/queue_service_client.py | 34 +++--- 4 files changed, 162 insertions(+), 131 deletions(-) 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 b8cf779f01ac..d75aa8ff566b 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 @@ -106,28 +106,28 @@ def __init__( queue_url, # type: str queue=None, # type: Optional[Union[QueueProperties, str]] credential=None, # type: Optional[Any] - loop=None, # type: Any **kwargs # type: Any ): # type: (...) -> None kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry(**kwargs) + loop = kwargs.pop('loop', None) super(QueueClient, self).__init__(queue_url, queue=queue, credential=credential, loop=loop, **kwargs) self._client = AzureQueueStorage(self.url, pipeline=self._pipeline, loop=loop) # type: ignore self._loop = loop @distributed_trace_async - async def create_queue(self, metadata=None, timeout=None, **kwargs): # type: ignore - # type: (Optional[Dict[str, Any]], Optional[int], Optional[Any]) -> None + async def create_queue(self, **kwargs): # type: ignore + # type: (Optional[Any]) -> None """Creates a new queue in the storage account. If a queue with the same name already exists, the operation fails. - :param metadata: + :keyword metadata: A dict containing name-value pairs to associate with the queue as metadata. Note that metadata names preserve the case with which they were created, but are case-insensitive when set or read. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. :return: None or the result of cls(response) :rtype: None @@ -143,6 +143,8 @@ async def create_queue(self, metadata=None, timeout=None, **kwargs): # type: ig :dedent: 8 :caption: Create a queue. """ + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) # type: ignore try: @@ -153,8 +155,8 @@ async def create_queue(self, metadata=None, timeout=None, **kwargs): # type: ig process_storage_error(error) @distributed_trace_async - async def delete_queue(self, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], Optional[Any]) -> None + async def delete_queue(self, **kwargs): # type: ignore + # type: (Optional[Any]) -> None """Deletes the specified queue and any messages it contains. When a queue is successfully deleted, it is immediately marked for deletion @@ -165,7 +167,7 @@ async def delete_queue(self, timeout=None, **kwargs): # type: ignore If an operation is attempted against the queue while it was being deleted, an :class:`HttpResponseError` will be thrown. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. :rtype: None @@ -178,19 +180,20 @@ async def delete_queue(self, timeout=None, **kwargs): # type: ignore :dedent: 12 :caption: Delete a queue. """ + timeout = kwargs.pop('timeout', None) try: await self._client.queue.delete(timeout=timeout, **kwargs) except StorageErrorException as error: process_storage_error(error) @distributed_trace_async - async def get_queue_properties(self, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], Optional[Any]) -> QueueProperties + async def get_queue_properties(self, **kwargs): # type: ignore + # type: (Optional[Any]) -> QueueProperties """Returns all user-defined metadata for the specified queue. The data returned does not include the queue's list of messages. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :return: Properties for the specified container within a container object. :rtype: ~azure.storage.queue.QueueProperties @@ -204,6 +207,7 @@ async def get_queue_properties(self, timeout=None, **kwargs): # type: ignore :dedent: 12 :caption: Get the properties on the queue. """ + timeout = kwargs.pop('timeout', None) try: response = await self._client.queue.get_properties( timeout=timeout, cls=deserialize_queue_properties, **kwargs @@ -214,8 +218,8 @@ async def get_queue_properties(self, timeout=None, **kwargs): # type: ignore return response # type: ignore @distributed_trace_async - async def set_queue_metadata(self, metadata=None, timeout=None, **kwargs): # type: ignore - # type: (Optional[Dict[str, Any]], Optional[int], Optional[Any]) -> None + async def set_queue_metadata(self, metadata=None, **kwargs): # type: ignore + # type: (Optional[Dict[str, Any]], Optional[Any]) -> None """Sets user-defined metadata on the specified queue. Metadata is associated with the queue as name-value pairs. @@ -224,7 +228,7 @@ async def set_queue_metadata(self, metadata=None, timeout=None, **kwargs): # ty A dict containing name-value pairs to associate with the queue as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. .. admonition:: Example: @@ -236,6 +240,7 @@ async def set_queue_metadata(self, metadata=None, timeout=None, **kwargs): # ty :dedent: 12 :caption: Set metadata on the queue. """ + timeout = kwargs.pop('timeout', None) headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) # type: ignore try: @@ -246,8 +251,8 @@ async def set_queue_metadata(self, metadata=None, timeout=None, **kwargs): # ty process_storage_error(error) @distributed_trace_async - async def get_queue_access_policy(self, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], Optional[Any]) -> Dict[str, Any] + async def get_queue_access_policy(self, **kwargs): # type: ignore + # type: (Optional[Any]) -> Dict[str, Any] """Returns details about any stored access policies specified on the queue that may be used with Shared Access Signatures. @@ -256,6 +261,7 @@ async def get_queue_access_policy(self, timeout=None, **kwargs): # type: ignore :return: A dictionary of access policies associated with the queue. :rtype: dict(str, ~azure.storage.queue.AccessPolicy) """ + timeout = kwargs.pop('timeout', None) try: _, identifiers = await self._client.queue.get_access_policy( timeout=timeout, cls=return_headers_and_deserialized, **kwargs @@ -265,7 +271,7 @@ async def get_queue_access_policy(self, timeout=None, **kwargs): # type: ignore return {s.id: s.access_policy or AccessPolicy() for s in identifiers} @distributed_trace_async - async def set_queue_access_policy(self, signed_identifiers, timeout=None, **kwargs): # type: ignore + async def set_queue_access_policy(self, signed_identifiers, **kwargs): # type: ignore # type: (Dict[str, AccessPolicy], Optional[int], Optional[Any]) -> None """Sets stored access policies for the queue that may be used with Shared Access Signatures. @@ -286,7 +292,7 @@ async def set_queue_access_policy(self, signed_identifiers, timeout=None, **kwar The list may contain up to 5 elements. An empty list will clear the access policies set on the service. :type signed_identifiers: dict(str, ~azure.storage.queue.AccessPolicy) - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. .. admonition:: Example: @@ -298,6 +304,7 @@ async def set_queue_access_policy(self, signed_identifiers, timeout=None, **kwar :dedent: 12 :caption: Set an access policy on the queue. """ + timeout = kwargs.pop('timeout', None) if len(signed_identifiers) > 15: raise ValueError( "Too many access policies provided. The server does not support setting " @@ -319,9 +326,6 @@ async def set_queue_access_policy(self, signed_identifiers, timeout=None, **kwar async def enqueue_message( # type: ignore self, content, # type: Any - visibility_timeout=None, # type: Optional[int] - time_to_live=None, # type: Optional[int] - timeout=None, # type: Optional[int] **kwargs # type: Optional[Any] ): # type: (...) -> QueueMessage @@ -342,18 +346,18 @@ async def enqueue_message( # type: ignore Message content. Allowed type is determined by the encode_function set on the service. Default is str. The encoded message can be up to 64KB in size. - :param int visibility_timeout: + :keyword int visibility_timeout: If not specified, the default value is 0. Specifies the new visibility timeout value, in seconds, relative to server time. The value must be larger than or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message cannot be set to a value later than the expiry time. visibility_timeout should be set to a value smaller than the time-to-live value. - :param int time_to_live: + :keyword int time_to_live: Specifies the time-to-live interval for the message, in seconds. The time-to-live may be any positive number or -1 for infinity. If this parameter is omitted, the default time-to-live is 7 days. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. :return: A :class:`~azure.storage.queue.QueueMessage` object. @@ -370,6 +374,9 @@ async def enqueue_message( # type: ignore :dedent: 12 :caption: Enqueue messages. """ + visibility_timeout = kwargs.pop('visibility_timeout', None) + time_to_live = kwargs.pop('time_to_live', None) + timeout = kwargs.pop('timeout', None) self._config.message_encode_policy.configure( require_encryption=self.require_encryption, key_encryption_key=self.key_encryption_key, @@ -397,8 +404,8 @@ async def enqueue_message( # type: ignore process_storage_error(error) @distributed_trace - def receive_messages(self, messages_per_page=None, visibility_timeout=None, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], Optional[int], Optional[int], Optional[Any]) -> AsyncItemPaged[Message] + def receive_messages(self, **kwargs): # type: ignore + # type: (Optional[Any]) -> AsyncItemPaged[Message] """Removes one or more messages from the front of the queue. When a message is retrieved from the queue, the response includes the message @@ -410,19 +417,19 @@ def receive_messages(self, messages_per_page=None, visibility_timeout=None, time If the key-encryption-key or resolver field is set on the local service object, the messages will be decrypted before being returned. - :param int messages_per_page: + :keyword int messages_per_page: A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a maximum of 32. If fewer are visible, the visible messages are returned. By default, a single message is retrieved from the queue with this operation. - :param int visibility_timeout: + :keyword int visibility_timeout: If not specified, the default value is 0. Specifies the new visibility timeout value, in seconds, relative to server time. The value must be larger than or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message cannot be set to a value later than the expiry time. visibility_timeout should be set to a value smaller than the time-to-live value. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. :return: Returns a message iterator of dict-like Message objects. @@ -437,6 +444,9 @@ def receive_messages(self, messages_per_page=None, visibility_timeout=None, time :dedent: 12 :caption: Receive messages from the queue. """ + messages_per_page = kwargs.pop('messages_per_page', None) + visibility_timeout = kwargs.pop('visibility_timeout', None) + timeout = kwargs.pop('timeout', None) self._config.message_decode_policy.configure( require_encryption=self.require_encryption, key_encryption_key=self.key_encryption_key, @@ -458,10 +468,8 @@ def receive_messages(self, messages_per_page=None, visibility_timeout=None, time async def update_message( self, message, - visibility_timeout=None, pop_receipt=None, # type: ignore content=None, - timeout=None, **kwargs ): # type: (Any, int, Optional[str], Optional[Any], Optional[int], Any) -> QueueMessage @@ -481,20 +489,20 @@ async def update_message( :param str message: The message object or id identifying the message to update. - :param int visibility_timeout: - Specifies the new visibility timeout value, in seconds, - relative to server time. The new value must be larger than or equal - to 0, and cannot be larger than 7 days. The visibility timeout of a - message cannot be set to a value later than the expiry time. A - message can be updated until it has been deleted or has expired. - The message object or message id identifying the message to update. :param str pop_receipt: A valid pop receipt value returned from an earlier call to the :func:`~receive_messages` or :func:`~update_message` operation. :param obj content: Message content. Allowed type is determined by the encode_function set on the service. Default is str. - :param int timeout: + :keyword int visibility_timeout: + Specifies the new visibility timeout value, in seconds, + relative to server time. The new value must be larger than or equal + to 0, and cannot be larger than 7 days. The visibility timeout of a + message cannot be set to a value later than the expiry time. A + message can be updated until it has been deleted or has expired. + The message object or message id identifying the message to update. + :keyword int timeout: The server timeout, expressed in seconds. :return: A :class:`~azure.storage.queue.QueueMessage` object. For convenience, @@ -510,6 +518,8 @@ async def update_message( :dedent: 12 :caption: Update a message. """ + visibility_timeout = kwargs.pop('visibility_timeout', None) + timeout = kwargs.pop('timeout', None) try: message_id = message.id message_text = content or message.content @@ -557,8 +567,8 @@ async def update_message( process_storage_error(error) @distributed_trace_async - async def peek_messages(self, max_messages=None, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], Optional[int], Optional[Any]) -> List[QueueMessage] + async def peek_messages(self, max_messages=None, **kwargs): # type: ignore + # type: (Optional[int], Optional[Any]) -> List[QueueMessage] """Retrieves one or more messages from the front of the queue, but does not alter the visibility of the message. @@ -577,7 +587,7 @@ async def peek_messages(self, max_messages=None, timeout=None, **kwargs): # typ A nonzero integer value that specifies the number of messages to peek from the queue, up to a maximum of 32. By default, a single message is peeked from the queue with this operation. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. :return: A list of :class:`~azure.storage.queue.QueueMessage` objects. Note that @@ -594,6 +604,7 @@ async def peek_messages(self, max_messages=None, timeout=None, **kwargs): # typ :dedent: 12 :caption: Peek messages. """ + timeout = kwargs.pop('timeout', None) 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( @@ -613,11 +624,11 @@ async def peek_messages(self, max_messages=None, timeout=None, **kwargs): # typ process_storage_error(error) @distributed_trace_async - async def clear_messages(self, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], Optional[Any]) -> None + async def clear_messages(self, **kwargs): # type: ignore + # type: (Optional[Any]) -> None """Deletes all messages from the specified queue. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. .. admonition:: Example: @@ -629,14 +640,15 @@ async def clear_messages(self, timeout=None, **kwargs): # type: ignore :dedent: 12 :caption: Clears all messages. """ + timeout = kwargs.pop('timeout', None) try: await self._client.messages.clear(timeout=timeout, **kwargs) except StorageErrorException as error: process_storage_error(error) @distributed_trace_async - async def delete_message(self, message, pop_receipt=None, timeout=None, **kwargs): # type: ignore - # type: (Any, Optional[str], Optional[str], Optional[int]) -> None + async def delete_message(self, message, pop_receipt=None, **kwargs): # type: ignore + # type: (Any, Optional[str], Any) -> None """Deletes the specified message. Normally after a client retrieves a message with the receive messages operation, @@ -654,7 +666,7 @@ async def delete_message(self, message, pop_receipt=None, timeout=None, **kwargs :param str pop_receipt: A valid pop receipt value returned from an earlier call to the :func:`~receive_messages` or :func:`~update_message`. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. .. admonition:: Example: @@ -666,6 +678,7 @@ async def delete_message(self, message, pop_receipt=None, timeout=None, **kwargs :dedent: 12 :caption: Delete a message. """ + timeout = kwargs.pop('timeout', None) try: message_id = message.id receipt = pop_receipt or message.pop_receipt 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 93397438f7bb..529db1d6eca8 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 @@ -94,11 +94,11 @@ class QueueServiceClient(AsyncStorageAccountHostsMixin, QueueServiceClientBase): def __init__( self, account_url, # type: str credential=None, # type: Optional[Any] - loop=None, # type: Any **kwargs # type: Any ): # type: (...) -> None kwargs['retry_policy'] = kwargs.get('retry_policy') or ExponentialRetry(**kwargs) + loop = kwargs.pop('loop', None) super(QueueServiceClient, self).__init__( # type: ignore account_url, credential=credential, @@ -108,8 +108,8 @@ def __init__( self._loop = loop @distributed_trace_async - async def get_service_stats(self, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], Optional[Any]) -> Dict[str, Any] + async def get_service_stats(self, **kwargs): # type: ignore + # type: (Optional[Any]) -> Dict[str, Any] """Retrieves statistics related to replication for the Queue service. It is only available when read-access geo-redundant replication is enabled for @@ -128,11 +128,12 @@ async def get_service_stats(self, timeout=None, **kwargs): # type: ignore access is available from the secondary location, if read-access geo-redundant replication is enabled for your storage account. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :return: The queue service stats. :rtype: ~azure.storage.queue._generated.models._models.StorageServiceStats """ + timeout = kwargs.pop('timeout', None) try: return await self._client.service.get_statistics( # type: ignore timeout=timeout, use_location=LocationMode.SECONDARY, **kwargs) @@ -140,12 +141,12 @@ async def get_service_stats(self, timeout=None, **kwargs): # type: ignore process_storage_error(error) @distributed_trace_async - async def get_service_properties(self, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], Optional[Any]) -> Dict[str, Any] + async def get_service_properties(self, **kwargs): # type: ignore + # type: (Optional[Any]) -> Dict[str, Any] """Gets the properties of a storage account's Queue service, including Azure Storage Analytics. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: ~azure.storage.queue._generated.models._models.StorageServiceProperties @@ -158,6 +159,7 @@ async def get_service_properties(self, timeout=None, **kwargs): # type: ignore :dedent: 8 :caption: Getting queue service properties. """ + timeout = kwargs.pop('timeout', None) try: return await self._client.service.get_properties(timeout=timeout, **kwargs) # type: ignore except StorageErrorException as error: @@ -169,7 +171,6 @@ async def set_service_properties( # type: ignore hour_metrics=None, # type: Optional[Metrics] minute_metrics=None, # type: Optional[Metrics] cors=None, # type: Optional[List[CorsRule]] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> None @@ -195,7 +196,7 @@ async def set_service_properties( # type: ignore list. If an empty list is specified, all CORS rules will be deleted, and CORS will be disabled for the service. :type cors: list(~azure.storage.queue.CorsRule) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -208,6 +209,7 @@ async def set_service_properties( # type: ignore :dedent: 8 :caption: Setting queue service properties. """ + timeout = kwargs.pop('timeout', None) props = StorageServiceProperties( logging=logging, hour_metrics=hour_metrics, @@ -223,8 +225,6 @@ async def set_service_properties( # type: ignore def list_queues( self, name_starts_with=None, # type: Optional[str] include_metadata=False, # type: Optional[bool] - results_per_page=None, # type: Optional[int] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> AsyncItemPaged """Returns a generator to list the queues under the specified account. @@ -237,10 +237,10 @@ def list_queues( begin with the specified prefix. :param bool include_metadata: Specifies that queue metadata be returned in the response. - :param int results_per_page: + :keyword int results_per_page: The maximum number of queue names to retrieve per API call. If the request does not specify the server will return up to 5,000 items. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. This function may make multiple calls to the service in which case the timeout value specified will be applied to each individual call. @@ -256,6 +256,8 @@ def list_queues( :dedent: 12 :caption: List queues in the service. """ + results_per_page = kwargs.pop('results_per_page', None) + timeout = kwargs.pop('timeout', None) include = ['metadata'] if include_metadata else None command = functools.partial( self._client.service.list_queues_segment, @@ -272,7 +274,6 @@ def list_queues( async def create_queue( # type: ignore self, name, # type: str metadata=None, # type: Optional[Dict[str, str]] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> QueueClient @@ -286,7 +287,7 @@ async def create_queue( # type: ignore A dict with name_value pairs to associate with the queue as metadata. Example: {'Category': 'test'} :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: ~azure.storage.queue.aio.QueueClient @@ -299,6 +300,7 @@ async def create_queue( # type: ignore :dedent: 8 :caption: Create a queue in the service. """ + timeout = kwargs.pop('timeout', None) queue = self.get_queue_client(name) kwargs.setdefault('merge_span', True) await queue.create_queue( @@ -308,7 +310,6 @@ async def create_queue( # type: ignore @distributed_trace_async async def delete_queue( # type: ignore self, queue, # type: Union[QueueProperties, str] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> None @@ -326,7 +327,7 @@ async def delete_queue( # type: ignore The queue to delete. This can either be the name of the queue, or an instance of QueueProperties. :type queue: str or ~azure.storage.queue.QueueProperties - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -339,6 +340,7 @@ async def delete_queue( # type: ignore :dedent: 12 :caption: Delete a queue in the service. """ + timeout = kwargs.pop('timeout', None) queue_client = self.get_queue_client(queue) kwargs.setdefault('merge_span', True) await queue_client.delete_queue(timeout=timeout, **kwargs) 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 d71f729c2482..227eac2d54a7 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 @@ -235,18 +235,18 @@ def generate_shared_access_signature( ) @distributed_trace - def create_queue(self, metadata=None, timeout=None, **kwargs): - # type: (Optional[Dict[str, Any]], Optional[int], Optional[Any]) -> None + def create_queue(self, **kwargs): + # type: (Optional[Any]) -> None """Creates a new queue in the storage account. If a queue with the same name already exists, the operation fails. - :param metadata: + :keyword metadata: A dict containing name-value pairs to associate with the queue as metadata. Note that metadata names preserve the case with which they were created, but are case-insensitive when set or read. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. :return: None or the result of cls(response) :rtype: None @@ -263,6 +263,8 @@ def create_queue(self, metadata=None, timeout=None, **kwargs): :caption: Create a queue. """ headers = kwargs.pop('headers', {}) + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) headers.update(add_metadata_headers(metadata)) # type: ignore try: return self._client.queue.create( # type: ignore @@ -275,8 +277,8 @@ def create_queue(self, metadata=None, timeout=None, **kwargs): process_storage_error(error) @distributed_trace - def delete_queue(self, timeout=None, **kwargs): - # type: (Optional[int], Optional[Any]) -> None + def delete_queue(self, **kwargs): + # type: (Optional[Any]) -> None """Deletes the specified queue and any messages it contains. When a queue is successfully deleted, it is immediately marked for deletion @@ -287,7 +289,7 @@ def delete_queue(self, timeout=None, **kwargs): If an operation is attempted against the queue while it was being deleted, an :class:`HttpResponseError` will be thrown. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. :rtype: None @@ -300,19 +302,20 @@ def delete_queue(self, timeout=None, **kwargs): :dedent: 12 :caption: Delete a queue. """ + timeout = kwargs.pop('timeout', None) try: self._client.queue.delete(timeout=timeout, **kwargs) except StorageErrorException as error: process_storage_error(error) @distributed_trace - def get_queue_properties(self, timeout=None, **kwargs): - # type: (Optional[int], Optional[Any]) -> QueueProperties + def get_queue_properties(self, **kwargs): + # type: (Optional[Any]) -> QueueProperties """Returns all user-defined metadata for the specified queue. The data returned does not include the queue's list of messages. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :return: Properties for the specified container within a container object. :rtype: ~azure.storage.queue.QueueProperties @@ -326,6 +329,7 @@ def get_queue_properties(self, timeout=None, **kwargs): :dedent: 12 :caption: Get the properties on the queue. """ + timeout = kwargs.pop('timeout', None) try: response = self._client.queue.get_properties( timeout=timeout, @@ -337,8 +341,8 @@ def get_queue_properties(self, timeout=None, **kwargs): return response # type: ignore @distributed_trace - def set_queue_metadata(self, metadata=None, timeout=None, **kwargs): - # type: (Optional[Dict[str, Any]], Optional[int], Optional[Any]) -> None + def set_queue_metadata(self, metadata=None, **kwargs): + # type: (Optional[Dict[str, Any]], Optional[Any]) -> None """Sets user-defined metadata on the specified queue. Metadata is associated with the queue as name-value pairs. @@ -347,7 +351,7 @@ def set_queue_metadata(self, metadata=None, timeout=None, **kwargs): A dict containing name-value pairs to associate with the queue as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. .. admonition:: Example: @@ -359,6 +363,7 @@ def set_queue_metadata(self, metadata=None, timeout=None, **kwargs): :dedent: 12 :caption: Set metadata on the queue. """ + timeout = kwargs.pop('timeout', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) # type: ignore try: @@ -371,16 +376,17 @@ def set_queue_metadata(self, metadata=None, timeout=None, **kwargs): process_storage_error(error) @distributed_trace - def get_queue_access_policy(self, timeout=None, **kwargs): - # type: (Optional[int], Optional[Any]) -> Dict[str, Any] + def get_queue_access_policy(self, **kwargs): + # type: (Optional[Any]) -> Dict[str, Any] """Returns details about any stored access policies specified on the queue that may be used with Shared Access Signatures. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. :return: A dictionary of access policies associated with the queue. :rtype: dict(str, ~azure.storage.queue.AccessPolicy) """ + timeout = kwargs.pop('timeout', None) try: _, identifiers = self._client.queue.get_access_policy( timeout=timeout, @@ -391,8 +397,8 @@ def get_queue_access_policy(self, timeout=None, **kwargs): return {s.id: s.access_policy or AccessPolicy() for s in identifiers} @distributed_trace - def set_queue_access_policy(self, signed_identifiers, timeout=None, **kwargs): - # type: (Dict[str, AccessPolicy], Optional[int], Optional[Any]) -> None + def set_queue_access_policy(self, signed_identifiers, **kwargs): + # type: (Dict[str, AccessPolicy], Optional[Any]) -> None """Sets stored access policies for the queue that may be used with Shared Access Signatures. @@ -412,7 +418,7 @@ def set_queue_access_policy(self, signed_identifiers, timeout=None, **kwargs): The list may contain up to 5 elements. An empty list will clear the access policies set on the service. :type signed_identifiers: dict(str, ~azure.storage.queue.AccessPolicy) - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. .. admonition:: Example: @@ -424,6 +430,7 @@ def set_queue_access_policy(self, signed_identifiers, timeout=None, **kwargs): :dedent: 12 :caption: Set an access policy on the queue. """ + timeout = kwargs.pop('timeout', None) if len(signed_identifiers) > 15: raise ValueError( 'Too many access policies provided. The server does not support setting ' @@ -446,9 +453,6 @@ def set_queue_access_policy(self, signed_identifiers, timeout=None, **kwargs): @distributed_trace def enqueue_message( # type: ignore self, content, # type: Any - visibility_timeout=None, # type: Optional[int] - time_to_live=None, # type: Optional[int] - timeout=None, # type: Optional[int] **kwargs # type: Optional[Any] ): # type: (...) -> QueueMessage @@ -469,18 +473,18 @@ def enqueue_message( # type: ignore Message content. Allowed type is determined by the encode_function set on the service. Default is str. The encoded message can be up to 64KB in size. - :param int visibility_timeout: + :keyword int visibility_timeout: If not specified, the default value is 0. Specifies the new visibility timeout value, in seconds, relative to server time. The value must be larger than or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message cannot be set to a value later than the expiry time. visibility_timeout should be set to a value smaller than the time-to-live value. - :param int time_to_live: + :keyword int time_to_live: Specifies the time-to-live interval for the message, in seconds. The time-to-live may be any positive number or -1 for infinity. If this parameter is omitted, the default time-to-live is 7 days. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. :return: A :class:`~azure.storage.queue.QueueMessage` object. @@ -497,6 +501,9 @@ def enqueue_message( # type: ignore :dedent: 12 :caption: Enqueue messages. """ + visibility_timeout = kwargs.pop('visibility_timeout', None) + time_to_live = kwargs.pop('time_to_live', None) + timeout = kwargs.pop('timeout', None) self._config.message_encode_policy.configure( require_encryption=self.require_encryption, key_encryption_key=self.key_encryption_key, @@ -522,8 +529,8 @@ def enqueue_message( # type: ignore process_storage_error(error) @distributed_trace - def receive_messages(self, messages_per_page=None, visibility_timeout=None, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], Optional[int], Optional[int], Optional[Any]) -> ItemPaged[Message] + def receive_messages(self, **kwargs): # type: ignore + # type: (Optional[Any]) -> ItemPaged[Message] """Removes one or more messages from the front of the queue. When a message is retrieved from the queue, the response includes the message @@ -535,19 +542,19 @@ def receive_messages(self, messages_per_page=None, visibility_timeout=None, time If the key-encryption-key or resolver field is set on the local service object, the messages will be decrypted before being returned. - :param int messages_per_page: + :keyword int messages_per_page: A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a maximum of 32. If fewer are visible, the visible messages are returned. By default, a single message is retrieved from the queue with this operation. - :param int visibility_timeout: + :keyword int visibility_timeout: If not specified, the default value is 0. Specifies the new visibility timeout value, in seconds, relative to server time. The value must be larger than or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message cannot be set to a value later than the expiry time. visibility_timeout should be set to a value smaller than the time-to-live value. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. :return: Returns a message iterator of dict-like Message objects. @@ -562,6 +569,9 @@ def receive_messages(self, messages_per_page=None, visibility_timeout=None, time :dedent: 12 :caption: Receive messages from the queue. """ + messages_per_page = kwargs.pop('messages_per_page', None) + visibility_timeout = kwargs.pop('visibility_timeout', None) + timeout = kwargs.pop('timeout', None) self._config.message_decode_policy.configure( require_encryption=self.require_encryption, key_encryption_key=self.key_encryption_key, @@ -579,9 +589,8 @@ def receive_messages(self, messages_per_page=None, visibility_timeout=None, time process_storage_error(error) @distributed_trace - def update_message(self, message, visibility_timeout=None, pop_receipt=None, # type: ignore - content=None, timeout=None, **kwargs): - # type: (Any, int, Optional[str], Optional[Any], Optional[int], Any) -> QueueMessage + def update_message(self, message, pop_receipt=None, content=None, **kwargs): # type: ignore + # type: (Any, Optional[str], Optional[Any], Any) -> QueueMessage """Updates the visibility timeout of a message. You can also use this operation to update the contents of a message. @@ -598,20 +607,20 @@ def update_message(self, message, visibility_timeout=None, pop_receipt=None, # t :param str message: The message object or id identifying the message to update. - :param int visibility_timeout: - Specifies the new visibility timeout value, in seconds, - relative to server time. The new value must be larger than or equal - to 0, and cannot be larger than 7 days. The visibility timeout of a - message cannot be set to a value later than the expiry time. A - message can be updated until it has been deleted or has expired. - The message object or message id identifying the message to update. :param str pop_receipt: A valid pop receipt value returned from an earlier call to the :func:`~receive_messages` or :func:`~update_message` operation. :param obj content: Message content. Allowed type is determined by the encode_function set on the service. Default is str. - :param int timeout: + :keyword int visibility_timeout: + Specifies the new visibility timeout value, in seconds, + relative to server time. The new value must be larger than or equal + to 0, and cannot be larger than 7 days. The visibility timeout of a + message cannot be set to a value later than the expiry time. A + message can be updated until it has been deleted or has expired. + The message object or message id identifying the message to update. + :keyword int timeout: The server timeout, expressed in seconds. :return: A :class:`~azure.storage.queue.QueueMessage` object. For convenience, @@ -627,6 +636,8 @@ def update_message(self, message, visibility_timeout=None, pop_receipt=None, # t :dedent: 12 :caption: Update a message. """ + visibility_timeout = kwargs.pop('visibility_timeout', None) + timeout = kwargs.pop('timeout', None) try: message_id = message.id message_text = content or message.content @@ -674,8 +685,8 @@ def update_message(self, message, visibility_timeout=None, pop_receipt=None, # t process_storage_error(error) @distributed_trace - def peek_messages(self, max_messages=None, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], Optional[int], Optional[Any]) -> List[QueueMessage] + def peek_messages(self, max_messages=None, **kwargs): # type: ignore + # type: (Optional[int], Optional[Any]) -> List[QueueMessage] """Retrieves one or more messages from the front of the queue, but does not alter the visibility of the message. @@ -694,7 +705,7 @@ def peek_messages(self, max_messages=None, timeout=None, **kwargs): # type: igno A nonzero integer value that specifies the number of messages to peek from the queue, up to a maximum of 32. By default, a single message is peeked from the queue with this operation. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. :return: A list of :class:`~azure.storage.queue.QueueMessage` objects. Note that @@ -711,6 +722,7 @@ def peek_messages(self, max_messages=None, timeout=None, **kwargs): # type: igno :dedent: 12 :caption: Peek messages. """ + timeout = kwargs.pop('timeout', None) 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( @@ -731,11 +743,11 @@ def peek_messages(self, max_messages=None, timeout=None, **kwargs): # type: igno process_storage_error(error) @distributed_trace - def clear_messages(self, timeout=None, **kwargs): - # type: (Optional[int], Optional[Any]) -> None + def clear_messages(self, **kwargs): + # type: (Optional[Any]) -> None """Deletes all messages from the specified queue. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. .. admonition:: Example: @@ -747,14 +759,15 @@ def clear_messages(self, timeout=None, **kwargs): :dedent: 12 :caption: Clears all messages. """ + timeout = kwargs.pop('timeout', None) try: self._client.messages.clear(timeout=timeout, **kwargs) except StorageErrorException as error: process_storage_error(error) @distributed_trace - def delete_message(self, message, pop_receipt=None, timeout=None, **kwargs): - # type: (Any, Optional[str], Optional[str], Optional[int]) -> None + def delete_message(self, message, pop_receipt=None, **kwargs): + # type: (Any, Optional[str], Any) -> None """Deletes the specified message. Normally after a client retrieves a message with the receive messages operation, @@ -772,7 +785,7 @@ def delete_message(self, message, pop_receipt=None, timeout=None, **kwargs): :param str pop_receipt: A valid pop receipt value returned from an earlier call to the :func:`~receive_messages` or :func:`~update_message`. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. .. admonition:: Example: @@ -784,6 +797,7 @@ def delete_message(self, message, pop_receipt=None, timeout=None, **kwargs): :dedent: 12 :caption: Delete a message. """ + timeout = kwargs.pop('timeout', None) try: message_id = message.id receipt = pop_receipt or message.pop_receipt 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 7c04e38d4813..59a16ff31c24 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 @@ -208,8 +208,8 @@ def generate_shared_access_signature( ) # type: ignore @distributed_trace - def get_service_stats(self, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], Optional[Any]) -> Dict[str, Any] + def get_service_stats(self, **kwargs): # type: ignore + # type: (Optional[Any]) -> Dict[str, Any] """Retrieves statistics related to replication for the Queue service. It is only available when read-access geo-redundant replication is enabled for @@ -228,11 +228,12 @@ def get_service_stats(self, timeout=None, **kwargs): # type: ignore access is available from the secondary location, if read-access geo-redundant replication is enabled for your storage account. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :return: The queue service stats. :rtype: ~azure.storage.queue.StorageServiceStats """ + timeout = kwargs.pop('timeout', None) try: return self._client.service.get_statistics( # type: ignore timeout=timeout, use_location=LocationMode.SECONDARY, **kwargs) @@ -240,12 +241,12 @@ def get_service_stats(self, timeout=None, **kwargs): # type: ignore process_storage_error(error) @distributed_trace - def get_service_properties(self, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], Optional[Any]) -> Dict[str, Any] + def get_service_properties(self, **kwargs): # type: ignore + # type: (Optional[Any]) -> Dict[str, Any] """Gets the properties of a storage account's Queue service, including Azure Storage Analytics. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: ~azure.storage.queue.StorageServiceProperties @@ -258,6 +259,7 @@ def get_service_properties(self, timeout=None, **kwargs): # type: ignore :dedent: 8 :caption: Getting queue service properties. """ + timeout = kwargs.pop('timeout', None) try: return self._client.service.get_properties(timeout=timeout, **kwargs) # type: ignore except StorageErrorException as error: @@ -269,7 +271,6 @@ def set_service_properties( # type: ignore hour_metrics=None, # type: Optional[Metrics] minute_metrics=None, # type: Optional[Metrics] cors=None, # type: Optional[List[CorsRule]] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> None @@ -295,7 +296,7 @@ def set_service_properties( # type: ignore list. If an empty list is specified, all CORS rules will be deleted, and CORS will be disabled for the service. :type cors: list(~azure.storage.queue.CorsRule) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -308,6 +309,7 @@ def set_service_properties( # type: ignore :dedent: 8 :caption: Setting queue service properties. """ + timeout = kwargs.pop('timeout', None) props = StorageServiceProperties( logging=logging, hour_metrics=hour_metrics, @@ -323,8 +325,6 @@ def set_service_properties( # type: ignore def list_queues( self, name_starts_with=None, # type: Optional[str] include_metadata=False, # type: Optional[bool] - results_per_page=None, # type: Optional[int] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> ItemPaged[QueueProperties] @@ -338,10 +338,10 @@ def list_queues( begin with the specified prefix. :param bool include_metadata: Specifies that queue metadata be returned in the response. - :param int results_per_page: + :keyword int results_per_page: The maximum number of queue names to retrieve per API call. If the request does not specify the server will return up to 5,000 items. - :param int timeout: + :keyword int timeout: The server timeout, expressed in seconds. This function may make multiple calls to the service in which case the timeout value specified will be applied to each individual call. @@ -357,6 +357,8 @@ def list_queues( :dedent: 12 :caption: List queues in the service. """ + results_per_page = kwargs.pop('results_per_page', None) + timeout = kwargs.pop('timeout', None) include = ['metadata'] if include_metadata else None command = functools.partial( self._client.service.list_queues_segment, @@ -373,7 +375,6 @@ def list_queues( def create_queue( self, name, # type: str metadata=None, # type: Optional[Dict[str, str]] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> QueueClient @@ -387,7 +388,7 @@ def create_queue( A dict with name_value pairs to associate with the queue as metadata. Example: {'Category': 'test'} :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: ~azure.storage.queue.QueueClient @@ -400,6 +401,7 @@ def create_queue( :dedent: 8 :caption: Create a queue in the service. """ + timeout = kwargs.pop('timeout', None) queue = self.get_queue_client(name) kwargs.setdefault('merge_span', True) queue.create_queue( @@ -409,7 +411,6 @@ def create_queue( @distributed_trace def delete_queue( self, queue, # type: Union[QueueProperties, str] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> None @@ -427,7 +428,7 @@ def delete_queue( The queue to delete. This can either be the name of the queue, or an instance of QueueProperties. :type queue: str or ~azure.storage.queue.QueueProperties - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -440,6 +441,7 @@ def delete_queue( :dedent: 12 :caption: Delete a queue in the service. """ + timeout = kwargs.pop('timeout', None) queue_client = self.get_queue_client(queue) kwargs.setdefault('merge_span', True) queue_client.delete_queue(timeout=timeout, **kwargs) From f393688f7a719e27ad5981cdfc93fad1cc835b73 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 15 Oct 2019 09:17:05 -0700 Subject: [PATCH 2/7] kwargify Files --- .../file/aio/directory_client_async.py | 85 +++++---- .../storage/file/aio/file_client_async.py | 159 ++++++++-------- .../file/aio/file_service_client_async.py | 33 ++-- .../storage/file/aio/share_client_async.py | 97 +++++----- .../azure/storage/file/directory_client.py | 99 +++++----- .../azure/storage/file/file_client.py | 180 +++++++++--------- .../azure/storage/file/file_service_client.py | 31 +-- .../azure/storage/file/share_client.py | 122 ++++++------ .../azure-storage-file/tests/test_share.py | 8 +- .../tests/test_share_async.py | 8 +- 10 files changed, 429 insertions(+), 393 deletions(-) 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 524b30ea28d3..ba4c0e9faecd 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 @@ -81,11 +81,11 @@ def __init__( # type: ignore directory_path=None, # type: Optional[str] snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] credential=None, # type: Optional[Any] - loop=None, # type: Any **kwargs # type: Optional[Any] ): # type: (...) -> None kwargs['retry_policy'] = kwargs.get('retry_policy') or ExponentialRetry(**kwargs) + loop = kwargs.pop('loop', None) super(DirectoryClient, self).__init__( directory_url, share=share, @@ -142,18 +142,14 @@ def get_subdirectory_client(self, directory_name, **kwargs): _location_mode=self._location_mode, loop=self._loop, **kwargs) @distributed_trace_async - async def create_directory( # type: ignore - self, metadata=None, # type: Optional[Dict[str, str]] - timeout=None, # type: Optional[int] - **kwargs # type: Optional[Any] - ): - # type: (...) -> Dict[str, Any] + async def create_directory( self, **kwargs): # type: ignore + # type: (Any) -> Dict[str, Any] """Creates a new directory under the directory referenced by the client. - :param metadata: + :keyword metadata: Name-value pairs associated with the directory as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Directory-updated property dict (Etag and last modified). :rtype: dict(str, Any) @@ -167,6 +163,8 @@ async def create_directory( # type: ignore :dedent: 12 :caption: Creates a directory. """ + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) # type: ignore try: @@ -179,12 +177,12 @@ async def create_directory( # type: ignore process_storage_error(error) @distributed_trace_async - async def delete_directory(self, timeout=None, **kwargs): - # type: (Optional[int], **Any) -> None + async def delete_directory(self, **kwargs): + # type: (**Any) -> None """Marks the directory for deletion. The directory is later deleted during garbage collection. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -197,20 +195,21 @@ async def delete_directory(self, timeout=None, **kwargs): :dedent: 12 :caption: Deletes a directory. """ + timeout = kwargs.pop('timeout', None) try: await self._client.directory.delete(timeout=timeout, **kwargs) except StorageErrorException as error: process_storage_error(error) @distributed_trace - def list_directories_and_files(self, name_starts_with=None, timeout=None, **kwargs): - # type: (Optional[str], Optional[int], **Any) -> AsyncItemPaged + def list_directories_and_files(self, name_starts_with=None, **kwargs): + # type: (Optional[str], Any) -> AsyncItemPaged """Lists all the directories and files under the directory. :param str name_starts_with: Filters the results to return only entities whose names begin with the specified prefix. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: An auto-paging iterable of dict-like DirectoryProperties and FileProperties :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.storage.file.DirectoryProperties] @@ -224,6 +223,7 @@ def list_directories_and_files(self, name_starts_with=None, timeout=None, **kwar :dedent: 12 :caption: List directories and files. """ + timeout = kwargs.pop('timeout', None) results_per_page = kwargs.pop('results_per_page', None) command = functools.partial( self._client.directory.list_files_and_directories_segment, @@ -235,18 +235,19 @@ 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): + def list_handles(self, recursive=False, **kwargs): # type: (bool, Optional[int], Any) -> AsyncItemPaged """Lists opened handles on a directory or a file under the directory. :param bool recursive: Boolean that specifies if operation should apply to the directory specified by the client, its files, its subdirectories and their files. Default value is False. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: An auto-paging iterable of HandleItem :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.storage.file.HandleItem] """ + timeout = kwargs.pop('timeout', None) results_per_page = kwargs.pop('results_per_page', None) command = functools.partial( self._client.directory.list_handles, @@ -262,7 +263,6 @@ def list_handles(self, recursive=False, timeout=None, **kwargs): async def close_handles( self, handle=None, # type: Union[str, HandleItem] recursive=False, # type: bool - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> Any @@ -278,11 +278,12 @@ async def close_handles( :param bool recursive: Boolean that specifies if operation should apply to the directory specified by the client, its files, its subdirectories and their files. Default value is False. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: A long-running poller to get operation status. :rtype: ~azure.core.polling.LROPoller """ + timeout = kwargs.pop('timeout', None) try: handle_id = handle.id # type: ignore except AttributeError: @@ -308,17 +309,18 @@ async def close_handles( polling_method) @distributed_trace_async - async def get_directory_properties(self, timeout=None, **kwargs): - # type: (Optional[int], Any) -> DirectoryProperties + async def get_directory_properties(self, **kwargs): + # type: (Any) -> DirectoryProperties """Returns all user-defined metadata and system properties for the specified directory. The data returned does not include the directory's list of files. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: DirectoryProperties :rtype: ~azure.storage.file.DirectoryProperties """ + timeout = kwargs.pop('timeout', None) try: response = await self._client.directory.get_properties( timeout=timeout, @@ -329,7 +331,7 @@ async def get_directory_properties(self, timeout=None, **kwargs): return response # type: ignore @distributed_trace_async - async def set_directory_metadata(self, metadata, timeout=None, **kwargs): # type: ignore + async def set_directory_metadata(self, metadata, **kwargs): # type: ignore # type: (Dict[str, Any], Optional[int], Any) -> Dict[str, Any] """Sets the metadata for the directory. @@ -340,11 +342,12 @@ async def set_directory_metadata(self, metadata, timeout=None, **kwargs): # type :param metadata: Name-value pairs associated with the directory as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Directory-updated property dict (Etag and last modified). :rtype: dict(str, Any) """ + timeout = kwargs.pop('timeout', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) try: @@ -362,12 +365,11 @@ async def set_http_headers(self, file_attributes="none", # type: Union[str, NTF file_last_write_time="preserve", # type: Union[str, datetime] file_permission=None, # type: Optional[str] permission_key=None, # type: Optional[str] - timeout=None, # type: Optional[int] **kwargs): # type: ignore # type: (...) -> Dict[str, Any] """Sets HTTP headers on the directory. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :param file_attributes: The file system attributes for files and directories. @@ -394,6 +396,7 @@ async def set_http_headers(self, file_attributes="none", # type: Union[str, NTF :returns: File-updated property dict (Etag and last modified). :rtype: dict(str, Any) """ + timeout = kwargs.pop('timeout', None) file_permission = _get_file_permission(file_permission, permission_key, 'preserve') try: return await self._client.directory.set_properties( # type: ignore @@ -411,8 +414,6 @@ async def set_http_headers(self, file_attributes="none", # type: Union[str, NTF @distributed_trace_async async def create_subdirectory( self, directory_name, # type: str - metadata=None, #type: Optional[Dict[str, Any]] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> DirectoryClient @@ -421,10 +422,10 @@ async def create_subdirectory( :param str directory_name: The name of the subdirectory. - :param metadata: + :keyword metadata: Name-value pairs associated with the subdirectory as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: DirectoryClient :rtype: ~azure.storage.file.aio.directory_client_async.DirectoryClient @@ -438,6 +439,8 @@ async def create_subdirectory( :dedent: 12 :caption: Create a subdirectory. """ + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) subdir = self.get_subdirectory_client(directory_name) await subdir.create_directory(metadata=metadata, timeout=timeout, **kwargs) return subdir # type: ignore @@ -445,7 +448,6 @@ async def create_subdirectory( @distributed_trace_async async def delete_subdirectory( self, directory_name, # type: str - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> None @@ -453,7 +455,7 @@ async def delete_subdirectory( :param str directory_name: The name of the subdirectory. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -466,6 +468,7 @@ async def delete_subdirectory( :dedent: 12 :caption: Delete a subdirectory. """ + timeout = kwargs.pop('timeout', None) subdir = self.get_subdirectory_client(directory_name) await subdir.delete_directory(timeout=timeout, **kwargs) @@ -474,12 +477,6 @@ async def upload_file( self, file_name, # type: str data, # type: Any length=None, # type: Optional[int] - metadata=None, # type: Optional[Dict[str, str]] - content_settings=None, # type: Optional[ContentSettings] - validate_content=False, # type: bool - max_concurrency=1, # type: Optional[int] - timeout=None, # type: Optional[int] - encoding='UTF-8', # type: str **kwargs # type: Any ): # type: (...) -> FileClient @@ -506,7 +503,7 @@ async def upload_file( file. :param int max_concurrency: Maximum number of parallel connections to use. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :param str encoding: Defaults to UTF-8. @@ -522,6 +519,12 @@ async def upload_file( :dedent: 12 :caption: Upload a file to a directory. """ + metadata = kwargs.pop('metadata', None) + content_settings = kwargs.pop('content_settings', None) + validate_content = kwargs.pop('validate_content', False) + max_concurrency = kwargs.pop('max_concurrency', 1) + timeout = kwargs.pop('timeout', None) + encoding = kwargs.pop('encoding', 'UTF-8') file_client = self.get_file_client(file_name) await file_client.upload_file( data, @@ -547,7 +550,7 @@ async def delete_file( :param str file_name: The name of the file to delete. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -561,4 +564,4 @@ async def delete_file( :caption: Delete a file in a directory. """ file_client = self.get_file_client(file_name) - await file_client.delete_file(timeout, **kwargs) + await file_client.delete_file(timeout=timeout, **kwargs) 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 c5493ca350d1..945f64e73e06 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 @@ -130,11 +130,11 @@ def __init__( # type: ignore file_path=None, # type: Optional[str] snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] credential=None, # type: Optional[Any] - loop=None, # type: Any **kwargs # type: Any ): # type: (...) -> None kwargs["retry_policy"] = kwargs.get("retry_policy") or ExponentialRetry(**kwargs) + loop = kwargs.pop('loop', None) super(FileClient, self).__init__( file_url, share=share, file_path=file_path, snapshot=snapshot, credential=credential, loop=loop, **kwargs ) @@ -145,14 +145,11 @@ def __init__( # type: ignore async def create_file( # type: ignore self, size, # type: int - content_settings=None, # type: Optional[ContentSettings] - metadata=None, # type: Optional[Dict[str, str]] file_attributes="none", # type: Union[str, NTFSAttributes] file_creation_time="now", # type: Union[str, datetime] file_last_write_time="now", # type: Union[str, datetime] file_permission=None, # type: Optional[str] permission_key=None, # type: Optional[str] - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> Dict[str, Any] @@ -162,13 +159,6 @@ async def create_file( # type: ignore :param int size: Specifies the maximum size for the file, up to 1 TB. - :param ~azure.storage.file.ContentSettings content_settings: - ContentSettings object used to set file properties. - :param metadata: - Name-value pairs associated with the file as metadata. - :type metadata: dict(str, str) - :param int timeout: - The timeout parameter is expressed in seconds. :param file_attributes: The file system attributes for files and directories. If not set, the default value would be "None" and the attributes will be set to "Archive". @@ -192,6 +182,13 @@ async def create_file( # type: ignore directory/file. Note: Only one of the x-ms-file-permission or x-ms-file-permission-key should be specified. :type permission_key: str + :keyword ~azure.storage.file.ContentSettings content_settings: + ContentSettings object used to set file properties. + :keyword metadata: + Name-value pairs associated with the file as metadata. + :type metadata: dict(str, str) + :keyword int timeout: + The timeout parameter is expressed in seconds. :returns: File-updated property dict (Etag and last modified). :rtype: dict(str, Any) @@ -204,6 +201,9 @@ async def create_file( # type: ignore :dedent: 12 :caption: Create a file. """ + content_settings = kwargs.pop('content_settings', None) + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) if self.require_encryption and not self.key_encryption_key: raise ValueError("Encryption required but no key was provided.") @@ -242,17 +242,11 @@ async def create_file( # type: ignore async def upload_file( self, data, # type: Any length=None, # type: Optional[int] - metadata=None, # type: Optional[Dict[str, str]] - content_settings=None, # type: Optional[ContentSettings] - validate_content=False, # type: bool - max_concurrency=1, # type: Optional[int] file_attributes="none", # type: Union[str, NTFSAttributes] file_creation_time="now", # type: Union[str, datetime] file_last_write_time="now", # type: Union[str, datetime] file_permission=None, # type: Optional[str] permission_key=None, # type: Optional[str] - encoding="UTF-8", # type: str - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> Dict[str, Any] @@ -262,24 +256,6 @@ async def upload_file( Content of the file. :param int length: Length of the file in bytes. Specify its maximum size, up to 1 TiB. - :param metadata: - Name-value pairs associated with the file as metadata. - :type metadata: dict(str, str) - :param ~azure.storage.file.ContentSettings content_settings: - ContentSettings object used to set file properties. - :param bool validate_content: - If true, calculates an MD5 hash for each range of the file. The storage - service checks the hash of the content that has arrived with the hash - that was sent. This is primarily valuable for detecting bitflips on - the wire if using http instead of https as https (the default) will - already validate. Note that this MD5 hash is not stored with the - file. - :param int max_concurrency: - Maximum number of parallel connections to use. - :param int timeout: - The timeout parameter is expressed in seconds. - :param str encoding: - Defaults to UTF-8. :param file_attributes: The file system attributes for files and directories. If not set, the default value would be "None" and the attributes will be set to "Archive". @@ -303,7 +279,24 @@ async def upload_file( directory/file. Note: Only one of the x-ms-file-permission or x-ms-file-permission-key should be specified. :type permission_key: str - + :keyword metadata: + Name-value pairs associated with the file as metadata. + :type metadata: dict(str, str) + :keyword ~azure.storage.file.ContentSettings content_settings: + ContentSettings object used to set file properties. + :keyword bool validate_content: + If true, calculates an MD5 hash for each range of the file. The storage + service checks the hash of the content that has arrived with the hash + that was sent. This is primarily valuable for detecting bitflips on + the wire if using http instead of https as https (the default) will + already validate. Note that this MD5 hash is not stored with the + file. + :keyword int max_concurrency: + Maximum number of parallel connections to use. + :keyword str encoding: + Defaults to UTF-8. + :keyword int timeout: + The timeout parameter is expressed in seconds. :returns: File-updated property dict (Etag and last modified). :rtype: dict(str, Any) @@ -316,6 +309,12 @@ async def upload_file( :dedent: 12 :caption: Upload a file. """ + metadata = kwargs.pop('metadata', None) + content_settings = kwargs.pop('content_settings', None) + max_concurrency = kwargs.pop('max_concurrency', 1) + validate_content = kwargs.pop('validate_content', False) + timeout = kwargs.pop('timeout', None) + encoding = kwargs.pop('encoding', 'UTF-8') if self.require_encryption or (self.key_encryption_key is not None): raise ValueError("Encryption not supported.") @@ -356,8 +355,6 @@ async def upload_file( async def start_copy_from_url( self, source_url, # type: str - metadata=None, # type: Optional[Dict[str, str]] - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> Any @@ -369,10 +366,10 @@ async def start_copy_from_url( :param str source_url: Specifies the URL of the source file. - :param metadata: + :keyword metadata: Name-value pairs associated with the file as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: dict(str, Any) @@ -385,6 +382,8 @@ async def start_copy_from_url( :dedent: 12 :caption: Copy a file from a URL """ + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) @@ -396,8 +395,8 @@ async def start_copy_from_url( process_storage_error(error) @distributed_trace_async - async def abort_copy(self, copy_id, timeout=None, **kwargs): - # type: (Union[str, FileProperties], Optional[int], Any) -> Dict[str, Any] + async def abort_copy(self, copy_id, **kwargs): + # type: (Union[str, FileProperties], Any) -> Dict[str, Any] """Abort an ongoing copy operation. This will leave a destination file with zero length and full metadata. @@ -409,6 +408,7 @@ async def abort_copy(self, copy_id, timeout=None, **kwargs): :type copy_id: str or ~azure.storage.file.FileProperties :rtype: None """ + timeout = kwargs.pop('timeout', None) try: copy_id = copy_id.copy.id except AttributeError: @@ -426,8 +426,6 @@ async def download_file( self, offset=None, # type: Optional[int] length=None, # type: Optional[int] - validate_content=False, # type: bool - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> Iterable[bytes] @@ -439,7 +437,7 @@ async def download_file( :param int length: Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance. - :param bool validate_content: + :keyword bool validate_content: If true, calculates an MD5 hash for each chunk of the file. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on @@ -448,7 +446,7 @@ async def download_file( file. Also note that if enabled, the memory-efficient upload algorithm will not be used, because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: A iterable data generator (stream) @@ -461,6 +459,8 @@ async def download_file( :dedent: 12 :caption: Download a file. """ + validate_content = kwargs.pop('validate_content', False) + timeout = kwargs.pop('timeout', None) if self.require_encryption or (self.key_encryption_key is not None): raise ValueError("Encryption not supported.") if length is not None and offset is None: @@ -483,12 +483,12 @@ async def download_file( return downloader @distributed_trace_async - async def delete_file(self, timeout=None, **kwargs): - # type: (Optional[int], Optional[Any]) -> None + async def delete_file(self, **kwargs): + # type: (Any) -> None """Marks the specified file for deletion. The file is later deleted during garbage collection. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -501,22 +501,24 @@ async def delete_file(self, timeout=None, **kwargs): :dedent: 12 :caption: Delete a file. """ + timeout = kwargs.pop('timeout', None) try: await self._client.file.delete(timeout=timeout, **kwargs) except StorageErrorException as error: process_storage_error(error) @distributed_trace_async - async def get_file_properties(self, timeout=None, **kwargs): - # type: (Optional[int], Any) -> FileProperties + async def get_file_properties(self, **kwargs): + # type: (Any) -> FileProperties """Returns all user-defined metadata, standard HTTP properties, and system properties for the file. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: FileProperties :rtype: ~azure.storage.file.FileProperties """ + timeout = kwargs.pop('timeout', None) try: file_props = await self._client.file.get_properties( sharesnapshot=self.snapshot, timeout=timeout, cls=deserialize_file_properties, **kwargs @@ -536,7 +538,6 @@ async def set_http_headers(self, content_settings, # type: ContentSettings file_last_write_time="preserve", # type: Union[str, datetime] file_permission=None, # type: Optional[str] permission_key=None, # type: Optional[str] - timeout=None, # type: Optional[int] **kwargs # Any ): # type: ignore # type: (ContentSettings, Optional[int], Optional[Any]) -> Dict[str, Any] @@ -544,8 +545,6 @@ async def set_http_headers(self, content_settings, # type: ContentSettings :param ~azure.storage.file.ContentSettings content_settings: ContentSettings object used to set file properties. - :param int timeout: - The timeout parameter is expressed in seconds. :param file_attributes: The file system attributes for files and directories. If not set, indicates preservation of existing values. @@ -568,9 +567,12 @@ async def set_http_headers(self, content_settings, # type: ContentSettings directory/file. Note: Only one of the x-ms-file-permission or x-ms-file-permission-key should be specified. :type permission_key: str + :keyword int timeout: + The timeout parameter is expressed in seconds. :returns: File-updated property dict (Etag and last modified). :rtype: dict(str, Any) """ + timeout = kwargs.pop('timeout', None) file_content_length = kwargs.pop("size", None) file_http_headers = FileHTTPHeaders( file_cache_control=content_settings.cache_control, @@ -598,8 +600,8 @@ async def set_http_headers(self, content_settings, # type: ContentSettings process_storage_error(error) @distributed_trace_async - async def set_file_metadata(self, metadata=None, timeout=None, **kwargs): # type: ignore - # type: (Optional[Dict[str, Any]], Optional[int], Optional[Any]) -> Dict[str, Any] + async def set_file_metadata(self, metadata=None, **kwargs): # type: ignore + # type: (Optional[Dict[str, Any]], Any) -> Dict[str, Any] """Sets user-defined metadata for the specified file as one or more name-value pairs. @@ -610,11 +612,12 @@ async def set_file_metadata(self, metadata=None, timeout=None, **kwargs): # typ :param metadata: Name-value pairs associated with the file as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: File-updated property dict (Etag and last modified). :rtype: dict(str, Any) """ + timeout = kwargs.pop('timeout', None) headers = kwargs.pop("headers", {}) headers.update(add_metadata_headers(metadata)) # type: ignore try: @@ -630,9 +633,6 @@ async def upload_range( # type: ignore data, # type: bytes start_range, # type: int end_range, # type: int - validate_content=False, # type: Optional[bool] - timeout=None, # type: Optional[int] - encoding="UTF-8", **kwargs ): # type: (...) -> Dict[str, Any] @@ -650,20 +650,23 @@ async def upload_range( # type: ignore The range can be up to 4 MB in size. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will upload first 512 bytes of file. - :param bool validate_content: + :keyword bool validate_content: If true, calculates an MD5 hash of the page content. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https as https (the default) will already validate. Note that this MD5 hash is not stored with the file. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. - :param str encoding: + :keyword str encoding: Defaults to UTF-8. :returns: File-updated property dict (Etag and last modified). :rtype: Dict[str, Any] """ + validate_content = kwargs.pop('validate_content', False) + timeout = kwargs.pop('timeout', None) + encoding = kwargs.pop('encoding', 'UTF-8') if self.require_encryption or (self.key_encryption_key is not None): raise ValueError("Encryption not supported.") if isinstance(data, six.text_type): @@ -719,7 +722,7 @@ async def upload_range_from_url(self, source_url, # type: str The range can be up to 4 MB in size. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of file. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. ''' @@ -740,7 +743,6 @@ async def get_ranges( # type: ignore self, start_range=None, # type: Optional[int] end_range=None, # type: Optional[int] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> List[dict[str, int]] @@ -754,11 +756,12 @@ async def get_ranges( # type: ignore Specifies the end offset of bytes over which to get ranges. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of file. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: A list of valid ranges. :rtype: List[dict[str, int]] """ + timeout = kwargs.pop('timeout', None) if self.require_encryption or (self.key_encryption_key is not None): raise ValueError("Unsupported method for encryption.") @@ -781,7 +784,6 @@ async def clear_range( # type: ignore self, start_range, # type: int end_range, # type: int - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> Dict[str, Any] @@ -798,11 +800,12 @@ async def clear_range( # type: ignore The range can be up to 4 MB in size. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of file. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: File-updated property dict (Etag and last modified). :rtype: Dict[str, Any] """ + timeout = kwargs.pop('timeout', None) if self.require_encryption or (self.key_encryption_key is not None): raise ValueError("Unsupported method for encryption.") @@ -824,17 +827,18 @@ async def clear_range( # type: ignore process_storage_error(error) @distributed_trace_async - async def resize_file(self, size, timeout=None, **kwargs): # type: ignore - # type: (int, Optional[int], Optional[Any]) -> Dict[str, Any] + async def resize_file(self, size, **kwargs): # type: ignore + # type: (int, Any) -> Dict[str, Any] """Resizes a file to the specified size. :param int size: Size to resize file to (in bytes) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: File-updated property dict (Etag and last modified). :rtype: Dict[str, Any] """ + timeout = kwargs.pop('timeout', None) try: return await self._client.file.set_http_headers( # type: ignore file_content_length=size, @@ -850,15 +854,16 @@ async def resize_file(self, size, timeout=None, **kwargs): # type: ignore process_storage_error(error) @distributed_trace - def list_handles(self, timeout=None, **kwargs): - # type: (Optional[int], Any) -> AsyncItemPaged + def list_handles(self, **kwargs): + # type: (Any) -> AsyncItemPaged """Lists handles for file. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: An auto-paging iterable of HandleItem :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.storage.file.HandleItem] """ + timeout = kwargs.pop('timeout', None) results_per_page = kwargs.pop("results_per_page", None) command = functools.partial( self._client.file.list_handles, @@ -873,7 +878,6 @@ def list_handles(self, timeout=None, **kwargs): async def close_handles( self, handle=None, # type: Union[str, HandleItem] - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> Any @@ -886,11 +890,12 @@ async def close_handles( Optionally, a specific handle to close. The default value is '*' which will attempt to close all open handles. :type handle: str or ~azure.storage.file.Handle - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: A long-running poller to get operation status. :rtype: ~azure.core.polling.LROPoller """ + timeout = kwargs.pop('timeout', None) try: handle_id = handle.id # type: ignore except AttributeError: 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 e4a863e46837..7afc9a12408c 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 @@ -77,11 +77,11 @@ class FileServiceClient(AsyncStorageAccountHostsMixin, FileServiceClientBase): def __init__( self, account_url, # type: str credential=None, # type: Optional[Any] - loop=None, # type: Any **kwargs # type: Any ): # type: (...) -> None kwargs['retry_policy'] = kwargs.get('retry_policy') or ExponentialRetry(**kwargs) + loop = kwargs.pop('loop', None) super(FileServiceClient, self).__init__( account_url, credential=credential, @@ -91,12 +91,12 @@ def __init__( self._loop = loop @distributed_trace_async - async def get_service_properties(self, timeout=None, **kwargs): - # type: (Optional[int], Any) -> Dict[str, Any] + async def get_service_properties(self, **kwargs): + # type: (Any) -> Dict[str, Any] """Gets the properties of a storage account's File service, including Azure Storage Analytics. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: ~azure.storage.file._generated.models.StorageServiceProperties @@ -109,6 +109,7 @@ async def get_service_properties(self, timeout=None, **kwargs): :dedent: 8 :caption: Get file service properties. """ + timeout = kwargs.pop('timeout', None) try: return await self._client.service.get_properties(timeout=timeout, **kwargs) except StorageErrorException as error: @@ -119,7 +120,6 @@ async def set_service_properties( self, hour_metrics=None, # type: Optional[Metrics] minute_metrics=None, # type: Optional[Metrics] cors=None, # type: Optional[List[CorsRule]] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> None @@ -140,7 +140,7 @@ async def set_service_properties( list. If an empty list is specified, all CORS rules will be deleted, and CORS will be disabled for the service. :type cors: list(:class:`~azure.storage.file.CorsRule`) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -153,6 +153,7 @@ async def set_service_properties( :dedent: 8 :caption: Sets file service properties. """ + timeout = kwargs.pop('timeout', None) props = StorageServiceProperties( hour_metrics=hour_metrics, minute_metrics=minute_metrics, @@ -168,7 +169,6 @@ def list_shares( self, name_starts_with=None, # type: Optional[str] include_metadata=False, # type: Optional[bool] include_snapshots=False, # type: Optional[bool] - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> AsyncItemPaged """Returns auto-paging iterable of dict-like ShareProperties under the specified account. @@ -182,7 +182,7 @@ def list_shares( Specifies that share metadata be returned in the response. :param bool include_snapshots: Specifies that share snapshot be returned in the response. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: An iterable (auto-paging) of ShareProperties. :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.storage.file.ShareProperties] @@ -196,6 +196,7 @@ def list_shares( :dedent: 12 :caption: List shares in the file service. """ + timeout = kwargs.pop('timeout', None) include = [] if include_metadata: include.append('metadata') @@ -214,9 +215,6 @@ def list_shares( @distributed_trace_async async def create_share( self, share_name, # type: str - metadata=None, # type: Optional[Dict[str, str]] - quota=None, # type: Optional[int] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> ShareClient @@ -225,13 +223,13 @@ async def create_share( which to interact with the newly created share. :param str share_name: The name of the share to create. - :param metadata: + :keyword metadata: A dict with name_value pairs to associate with the share as metadata. Example:{'Category':'test'} :type metadata: dict(str, str) - :param int quota: + :keyword int quota: Quota in bytes. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: ~azure.storage.file.aio.ShareClient @@ -244,6 +242,9 @@ async def create_share( :dedent: 8 :caption: Create a share in the file service. """ + metadata = kwargs.pop('metadata', None) + quota = kwargs.pop('quota', None) + timeout = kwargs.pop('timeout', None) share = self.get_share_client(share_name) kwargs.setdefault('merge_span', True) await share.create_share(metadata, quota, timeout, **kwargs) @@ -253,7 +254,6 @@ async def create_share( async def delete_share( self, share_name, # type: Union[ShareProperties, str] delete_snapshots=False, # type: Optional[bool] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> None @@ -266,7 +266,7 @@ async def delete_share( :type share_name: str or ~azure.storage.file.ShareProperties :param bool delete_snapshots: Indicates if snapshots are to be deleted. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -279,6 +279,7 @@ async def delete_share( :dedent: 12 :caption: Delete a share in the file service. """ + timeout = kwargs.pop('timeout', None) share = self.get_share_client(share_name) kwargs.setdefault('merge_span', True) await share.delete_share( 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 a188807eb7f5..d9057384d160 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 @@ -73,11 +73,11 @@ def __init__( # type: ignore share=None, # type: Optional[Union[str, ShareProperties]] snapshot=None, # type: Optional[Union[str, Dict[str, Any]]] credential=None, # type: Optional[Any] - loop=None, # type: Any **kwargs # type: Any ): # type: (...) -> None kwargs['retry_policy'] = kwargs.get('retry_policy') or ExponentialRetry(**kwargs) + loop = kwargs.pop('loop', None) super(ShareClient, self).__init__( share_url, share=share, @@ -118,22 +118,17 @@ def get_file_client(self, file_path): _configuration=self._config, _pipeline=self._pipeline, _location_mode=self._location_mode, loop=self._loop) @distributed_trace_async - async def create_share( # type: ignore - self, metadata=None, # type: Optional[Dict[str, str]] - quota=None, # type: Optional[int] - timeout=None, # type: Optional[int] - **kwargs # type: Optional[Any] - ): - # type: (...) -> Dict[str, Any] + async def create_share(self, **kwargs): # type: ignore + # type: (Any) -> Dict[str, Any] """Creates a new Share under the account. If a share with the same name already exists, the operation fails. - :param metadata: + :keyword metadata: Name-value pairs associated with the share as metadata. :type metadata: dict(str, str) - :param int quota: + :keyword int quota: The quota to be allotted. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Share-updated property dict (Etag and last modified). :rtype: dict(str, Any) @@ -147,6 +142,9 @@ async def create_share( # type: ignore :dedent: 8 :caption: Creates a file share. """ + metadata = kwargs.pop('metadata', None) + quota = kwargs.pop('quota', None) + timeout = kwargs.pop('timeout', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) # type: ignore @@ -163,8 +161,7 @@ async def create_share( # type: ignore @distributed_trace_async async def create_snapshot( # type: ignore - self, metadata=None, # type: Optional[Dict[str, str]] - timeout=None, # type: Optional[int] + self, **kwargs # type: Optional[Any] ): # type: (...) -> Dict[str, Any] @@ -178,10 +175,10 @@ async def create_snapshot( # type: ignore is taken, with a DateTime value appended to indicate the time at which the snapshot was taken. - :param metadata: + :keyword metadata: Name-value pairs associated with the share as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Share-updated property dict (Snapshot ID, Etag, and last modified). :rtype: dict[str, Any] @@ -195,6 +192,8 @@ async def create_snapshot( # type: ignore :dedent: 12 :caption: Creates a snapshot of the file share. """ + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) # type: ignore try: @@ -209,7 +208,6 @@ async def create_snapshot( # type: ignore @distributed_trace_async async def delete_share( self, delete_snapshots=False, # type: Optional[bool] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> None @@ -218,7 +216,7 @@ async def delete_share( :param bool delete_snapshots: Indicates if snapshots are to be deleted. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -231,6 +229,7 @@ async def delete_share( :dedent: 12 :caption: Deletes the share and any snapshots. """ + timeout = kwargs.pop('timeout', None) delete_include = None if delete_snapshots: delete_include = DeleteSnapshotsOptionType.include @@ -244,13 +243,13 @@ async def delete_share( process_storage_error(error) @distributed_trace_async - async def get_share_properties(self, timeout=None, **kwargs): - # type: (Optional[int], Any) -> ShareProperties + async def get_share_properties(self, **kwargs): + # type: (Any) -> ShareProperties """Returns all user-defined metadata and system properties for the specified share. The data returned does not include the shares's list of files or directories. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: The share properties. :rtype: ~azure.storage.file.ShareProperties @@ -264,6 +263,7 @@ async def get_share_properties(self, timeout=None, **kwargs): :dedent: 12 :caption: Gets the share properties. """ + timeout = kwargs.pop('timeout', None) try: props = await self._client.share.get_properties( timeout=timeout, @@ -277,14 +277,14 @@ async def get_share_properties(self, timeout=None, **kwargs): return props # type: ignore @distributed_trace_async - async def set_share_quota(self, quota, timeout=None, **kwargs): # type: ignore - # type: (int, Optional[int], Any) -> Dict[str, Any] + async def set_share_quota(self, quota, **kwargs): # type: ignore + # type: (int, Any) -> Dict[str, Any] """Sets the quota for the share. :param int quota: Specifies the maximum size of the share, in gigabytes. Must be greater than 0, and less than or equal to 5TB. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Share-updated property dict (Etag and last modified). :rtype: dict(str, Any) @@ -298,6 +298,7 @@ async def set_share_quota(self, quota, timeout=None, **kwargs): # type: ignore :dedent: 12 :caption: Sets the share quota. """ + timeout = kwargs.pop('timeout', None) try: return await self._client.share.set_quota( # type: ignore timeout=timeout, @@ -308,8 +309,8 @@ async def set_share_quota(self, quota, timeout=None, **kwargs): # type: ignore process_storage_error(error) @distributed_trace_async - async def set_share_metadata(self, metadata, timeout=None, **kwargs): # type: ignore - # type: (Dict[str, Any], Optional[int], Any) -> Dict[str, Any] + async def set_share_metadata(self, metadata, **kwargs): # type: ignore + # type: (Dict[str, Any], Any) -> Dict[str, Any] """Sets the metadata for the share. Each call to this operation replaces all existing metadata @@ -319,7 +320,7 @@ async def set_share_metadata(self, metadata, timeout=None, **kwargs): # type: ig :param metadata: Name-value pairs associated with the share as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Share-updated property dict (Etag and last modified). :rtype: dict(str, Any) @@ -333,6 +334,7 @@ async def set_share_metadata(self, metadata, timeout=None, **kwargs): # type: ig :dedent: 12 :caption: Sets the share metadata. """ + timeout = kwargs.pop('timeout', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) try: @@ -345,16 +347,17 @@ async def set_share_metadata(self, metadata, timeout=None, **kwargs): # type: ig process_storage_error(error) @distributed_trace_async - async def get_share_access_policy(self, timeout=None, **kwargs): - # type: (Optional[int], **Any) -> Dict[str, Any] + async def get_share_access_policy(self, **kwargs): + # type: (Any) -> Dict[str, Any] """Gets the permissions for the share. The permissions indicate whether files in a share may be accessed publicly. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Access policy information in a dict. :rtype: dict[str, str] """ + timeout = kwargs.pop('timeout', None) try: response, identifiers = await self._client.share.get_access_policy( timeout=timeout, @@ -368,8 +371,8 @@ async def get_share_access_policy(self, timeout=None, **kwargs): } @distributed_trace_async - async def set_share_access_policy(self, signed_identifiers, timeout=None, **kwargs): # type: ignore - # type: (Dict[str, AccessPolicy], Optional[int], **Any) -> Dict[str, str] + async def set_share_access_policy(self, signed_identifiers, **kwargs): # type: ignore + # type: (Dict[str, AccessPolicy], Any) -> Dict[str, str] """Sets the permissions for the share, or stored access policies that may be used with Shared Access Signatures. The permissions indicate whether files in a share may be accessed publicly. @@ -379,11 +382,12 @@ async def set_share_access_policy(self, signed_identifiers, timeout=None, **kwar dictionary may contain up to 5 elements. An empty dictionary will clear the access policies set on the service. :type signed_identifiers: dict(str, :class:`~azure.storage.file.AccessPolicy`) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Share-updated property dict (Etag and last modified). :rtype: dict(str, Any) """ + timeout = kwargs.pop('timeout', None) if len(signed_identifiers) > 5: raise ValueError( 'Too many access policies provided. The server does not support setting ' @@ -406,18 +410,19 @@ async def set_share_access_policy(self, signed_identifiers, timeout=None, **kwar process_storage_error(error) @distributed_trace_async - async def get_share_stats(self, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], **Any) -> int + async def get_share_stats(self, **kwargs): # type: ignore + # type: (Any) -> int """Gets the approximate size of the data stored on the share in bytes. Note that this value may not include all recently created or recently re-sized files. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :return: The approximate size of the data (in bytes) stored on the share. :rtype: int """ + timeout = kwargs.pop('timeout', None) try: stats = await self._client.share.get_statistics( timeout=timeout, @@ -431,7 +436,6 @@ def list_directories_and_files( # type: ignore self, directory_name=None, # type: Optional[str] name_starts_with=None, # type: Optional[str] marker=None, # type: Optional[str] - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> Iterable[dict[str,str]] @@ -446,7 +450,7 @@ def list_directories_and_files( # type: ignore An opaque continuation token. This value can be retrieved from the next_marker field of a previous generator object. If specified, this generator will begin returning results from this point. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: An auto-paging iterable of dict-like DirectoryProperties and FileProperties @@ -459,13 +463,13 @@ def list_directories_and_files( # type: ignore :dedent: 12 :caption: List directories and files in the share. """ + timeout = kwargs.pop('timeout', None) directory = self.get_directory_client(directory_name) return directory.list_directories_and_files( name_starts_with=name_starts_with, marker=marker, timeout=timeout, **kwargs) @distributed_trace_async async def create_permission_for_share(self, file_permission, # type: str - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> str @@ -477,11 +481,12 @@ async def create_permission_for_share(self, file_permission, # type: str :param str file_permission: File permission, a Portable SDDL - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: a file permission key :rtype: str """ + timeout = kwargs.pop('timeout', None) options = self._create_permission_for_share_options(file_permission, timeout=timeout, **kwargs) try: return await self._client.share.create_permission(**options) @@ -491,7 +496,6 @@ async def create_permission_for_share(self, file_permission, # type: str @distributed_trace_async async def get_permission_for_share( # type: ignore self, permission_key, # type: str - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> str @@ -501,11 +505,12 @@ async def get_permission_for_share( # type: ignore :param str permission_key: Key of the file permission to retrieve - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: a file permission(a portable SDDL) :rtype: str """ + timeout = kwargs.pop('timeout', None) try: return await self._client.share.get_permission( # type: ignore file_permission_key=permission_key, @@ -516,22 +521,24 @@ async def get_permission_for_share( # type: ignore process_storage_error(error) @distributed_trace_async - async def create_directory(self, directory_name, metadata=None, timeout=None, **kwargs): + async def create_directory(self, directory_name, **kwargs): # type: (str, Optional[Dict[str, Any]], Optional[int], Any) -> DirectoryClient """Creates a directory in the share and returns a client to interact with the directory. :param str directory_name: The name of the directory. - :param metadata: + :keyword metadata: Name-value pairs associated with the directory as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: DirectoryClient :rtype: ~azure.storage.file.aio.directory_client_async.DirectoryClient """ + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) directory = self.get_directory_client(directory_name) kwargs.setdefault('merge_span', True) - await directory.create_directory(metadata, timeout, **kwargs) + await directory.create_directory(metadata=metadata, timeout=timeout, **kwargs) return directory # type: ignore 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 d62fdc178d65..56e0c2f832c6 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 @@ -216,18 +216,14 @@ def get_subdirectory_client(self, directory_name, **kwargs): _location_mode=self._location_mode, **kwargs) @distributed_trace - def create_directory( # type: ignore - self, metadata=None, # type: Optional[Dict[str, str]] - timeout=None, # type: Optional[int] - **kwargs # type: Optional[Any] - ): - # type: (...) -> Dict[str, Any] + def create_directory(self, **kwargs): # type: ignore + # type: (Any) -> Dict[str, Any] """Creates a new directory under the directory referenced by the client. - :param metadata: + :keyword metadata: Name-value pairs associated with the directory as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Directory-updated property dict (Etag and last modified). :rtype: dict(str, Any) @@ -241,6 +237,8 @@ def create_directory( # type: ignore :dedent: 12 :caption: Creates a directory. """ + timeout = kwargs.pop('timeout', None) + metadata = kwargs.pop('metadata', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) # type: ignore try: @@ -253,12 +251,12 @@ def create_directory( # type: ignore process_storage_error(error) @distributed_trace - def delete_directory(self, timeout=None, **kwargs): + def delete_directory(self, **kwargs): # type: (Optional[int], **Any) -> None """Marks the directory for deletion. The directory is later deleted during garbage collection. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -271,20 +269,21 @@ def delete_directory(self, timeout=None, **kwargs): :dedent: 12 :caption: Deletes a directory. """ + timeout = kwargs.pop('timeout', None) try: self._client.directory.delete(timeout=timeout, **kwargs) except StorageErrorException as error: process_storage_error(error) @distributed_trace - def list_directories_and_files(self, name_starts_with=None, timeout=None, **kwargs): - # type: (Optional[str], Optional[int], **Any) -> ItemPaged + def list_directories_and_files(self, name_starts_with=None, **kwargs): + # type: (Optional[str], **Any) -> ItemPaged """Lists all the directories and files under the directory. :param str name_starts_with: Filters the results to return only entities whose names begin with the specified prefix. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: An auto-paging iterable of dict-like DirectoryProperties and FileProperties :rtype: ~azure.core.paging.ItemPaged[~azure.storage.file.DirectoryProperties] @@ -298,6 +297,7 @@ def list_directories_and_files(self, name_starts_with=None, timeout=None, **kwar :dedent: 12 :caption: List directories and files. """ + timeout = kwargs.pop('timeout', None) results_per_page = kwargs.pop('results_per_page', None) command = functools.partial( self._client.directory.list_files_and_directories_segment, @@ -309,18 +309,19 @@ 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): - # type: (bool, Optional[int], Any) -> ItemPaged + def list_handles(self, recursive=False, **kwargs): + # type: (bool, Any) -> ItemPaged """Lists opened handles on a directory or a file under the directory. :param bool recursive: Boolean that specifies if operation should apply to the directory specified by the client, its files, its subdirectories and their files. Default value is False. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: An auto-paging iterable of HandleItem :rtype: ~azure.core.paging.ItemPaged[~azure.storage.file.HandleItem] """ + timeout = kwargs.pop('timeout', None) results_per_page = kwargs.pop('results_per_page', None) command = functools.partial( self._client.directory.list_handles, @@ -336,7 +337,6 @@ def list_handles(self, recursive=False, timeout=None, **kwargs): def close_handles( self, handle=None, # type: Union[str, HandleItem] recursive=False, # type: bool - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> Any @@ -352,11 +352,12 @@ def close_handles( :param bool recursive: Boolean that specifies if operation should apply to the directory specified by the client, its files, its subdirectories and their files. Default value is False. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: A long-running poller to get operation status. :rtype: ~azure.core.polling.LROPoller """ + timeout = kwargs.pop('timeout', None) try: handle_id = handle.id # type: ignore except AttributeError: @@ -382,16 +383,17 @@ def close_handles( polling_method) @distributed_trace - def get_directory_properties(self, timeout=None, **kwargs): - # type: (Optional[int], Any) -> DirectoryProperties + def get_directory_properties(self, **kwargs): + # type: (Any) -> DirectoryProperties """Returns all user-defined metadata and system properties for the specified directory. The data returned does not include the directory's list of files. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: ~azure.storage.file.DirectoryProperties """ + timeout = kwargs.pop('timeout', None) try: response = self._client.directory.get_properties( timeout=timeout, @@ -402,8 +404,8 @@ def get_directory_properties(self, timeout=None, **kwargs): return response # type: ignore @distributed_trace - def set_directory_metadata(self, metadata, timeout=None, **kwargs): # type: ignore - # type: (Dict[str, Any], Optional[int], Any) -> Dict[str, Any] + def set_directory_metadata(self, metadata, **kwargs): # type: ignore + # type: (Dict[str, Any], Any) -> Dict[str, Any] """Sets the metadata for the directory. Each call to this operation replaces all existing metadata @@ -413,11 +415,12 @@ def set_directory_metadata(self, metadata, timeout=None, **kwargs): # type: igno :param metadata: Name-value pairs associated with the directory as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Directory-updated property dict (Etag and last modified). :rtype: dict(str, Any) """ + timeout = kwargs.pop('timeout', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) try: @@ -435,13 +438,10 @@ def set_http_headers(self, file_attributes="none", # type: Union[str, NTFSAttri file_last_write_time="preserve", # type: Union[str, datetime] file_permission=None, # type: Optional[str] permission_key=None, # type: Optional[str] - timeout=None, # type: Optional[int] **kwargs): # type: ignore # type: (...) -> Dict[str, Any] """Sets HTTP headers on the directory. - :param int timeout: - The timeout parameter is expressed in seconds. :param file_attributes: The file system attributes for files and directories. If not set, indicates preservation of existing values. @@ -464,9 +464,12 @@ def set_http_headers(self, file_attributes="none", # type: Union[str, NTFSAttri directory/file. Note: Only one of the x-ms-file-permission or x-ms-file-permission-key should be specified. :type permission_key: str + :keyword int timeout: + The timeout parameter is expressed in seconds. :returns: File-updated property dict (Etag and last modified). :rtype: dict(str, Any) """ + timeout = kwargs.pop('timeout', None) file_permission = _get_file_permission(file_permission, permission_key, 'preserve') try: return self._client.directory.set_properties( # type: ignore @@ -484,8 +487,6 @@ def set_http_headers(self, file_attributes="none", # type: Union[str, NTFSAttri @distributed_trace def create_subdirectory( self, directory_name, # type: str - metadata=None, # type: Optional[Dict[str, Any]] - timeout=None, # type: Optional[int] **kwargs): # type: (...) -> DirectoryClient """Creates a new subdirectory and returns a client to interact @@ -493,10 +494,10 @@ def create_subdirectory( :param str directory_name: The name of the subdirectory. - :param metadata: + :keyword metadata: Name-value pairs associated with the subdirectory as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: DirectoryClient :rtype: ~azure.storage.file.directory_client.DirectoryClient @@ -510,6 +511,8 @@ def create_subdirectory( :dedent: 12 :caption: Create a subdirectory. """ + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) subdir = self.get_subdirectory_client(directory_name) subdir.create_directory(metadata=metadata, timeout=timeout, **kwargs) return subdir # type: ignore @@ -517,7 +520,6 @@ def create_subdirectory( @distributed_trace def delete_subdirectory( self, directory_name, # type: str - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> None @@ -525,7 +527,7 @@ def delete_subdirectory( :param str directory_name: The name of the subdirectory. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -538,6 +540,7 @@ def delete_subdirectory( :dedent: 12 :caption: Delete a subdirectory. """ + timeout = kwargs.pop('timeout', None) subdir = self.get_subdirectory_client(directory_name) subdir.delete_directory(timeout=timeout, **kwargs) @@ -546,12 +549,6 @@ def upload_file( self, file_name, # type: str data, # type: Any length=None, # type: Optional[int] - metadata=None, # type: Optional[Dict[str, str]] - content_settings=None, # type: Optional[ContentSettings] - validate_content=False, # type: bool - max_concurrency=1, # type: Optional[int] - timeout=None, # type: Optional[int] - encoding='UTF-8', # type: str **kwargs # type: Any ): # type: (...) -> FileClient @@ -564,23 +561,23 @@ def upload_file( Content of the file. :param int length: Length of the file in bytes. Specify its maximum size, up to 1 TiB. - :param metadata: + :keyword metadata: Name-value pairs associated with the file as metadata. :type metadata: dict(str, str) - :param ~azure.storage.file.ContentSettings content_settings: + :keyword ~azure.storage.file.ContentSettings content_settings: ContentSettings object used to set file properties. - :param bool validate_content: + :keyword bool validate_content: If true, calculates an MD5 hash for each range of the file. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https as https (the default) will already validate. Note that this MD5 hash is not stored with the file. - :param int max_concurrency: + :keyword int max_concurrency: Maximum number of parallel connections to use. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. - :param str encoding: + :keyword str encoding: Defaults to UTF-8. :returns: FileClient :rtype: ~azure.storage.file.FileClient @@ -594,6 +591,12 @@ def upload_file( :dedent: 12 :caption: Upload a file to a directory. """ + metadata = kwargs.pop('metadata', None) + content_settings = kwargs.pop('content_settings', None) + validate_content = kwargs.pop('validate_content', False) + max_concurrency = kwargs.pop('max_concurrency', 1) + timeout = kwargs.pop('timeout', None) + encoding = kwargs.pop('encoding', 'UTF-8') file_client = self.get_file_client(file_name) file_client.upload_file( data, @@ -610,7 +613,6 @@ def upload_file( @distributed_trace def delete_file( self, file_name, # type: str - timeout=None, # type: Optional[int] **kwargs # type: Optional[Any] ): # type: (...) -> None @@ -619,7 +621,7 @@ def delete_file( :param str file_name: The name of the file to delete. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -632,5 +634,6 @@ def delete_file( :dedent: 12 :caption: Delete a file in a directory. """ + timeout = kwargs.pop('timeout', None) file_client = self.get_file_client(file_name) - file_client.delete_file(timeout, **kwargs) + file_client.delete_file(timeout=timeout, **kwargs) 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 f09cd06a39cd..ce150893ced1 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 @@ -244,12 +244,6 @@ def generate_shared_access_signature( 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: Optional[str] ): # type: (...) -> str """Generates a shared access signature for the file. @@ -288,26 +282,32 @@ def generate_shared_access_signature( or address range specified on the SAS token, the request is not authenticated. For example, specifying sip=168.1.5.65 or sip=168.1.5.60-168.1.5.70 on the SAS restricts the request to those IP addresses. - :param str protocol: + :keyword str protocol: Specifies the protocol permitted for a request made. The default value is https. - :param str cache_control: + :keyword str cache_control: Response header value for Cache-Control when resource is accessed using this shared access signature. - :param str content_disposition: + :keyword str content_disposition: Response header value for Content-Disposition when resource is accessed using this shared access signature. - :param str content_encoding: + :keyword str content_encoding: Response header value for Content-Encoding when resource is accessed using this shared access signature. - :param str content_language: + :keyword str content_language: Response header value for Content-Language when resource is accessed using this shared access signature. - :param str content_type: + :keyword str content_type: Response header value for Content-Type when resource is accessed using this shared access signature. :return: A Shared Access Signature (sas) token. :rtype: str """ + protocol = kwargs.pop('protocol', None) + cache_control = kwargs.pop('cache_control', None) + content_disposition = kwargs.pop('content_disposition', None) + content_encoding = kwargs.pop('content_encoding', None) + content_language = kwargs.pop('content_language', None) + content_type = kwargs.pop('content_type', None) if not hasattr(self.credential, 'account_key') or not self.credential.account_key: raise ValueError("No account SAS key available.") sas = FileSharedAccessSignature(self.credential.account_name, self.credential.account_key) @@ -334,14 +334,11 @@ def generate_shared_access_signature( @distributed_trace def create_file( # type: ignore self, size, # type: int - content_settings=None, # type: Optional[ContentSettings] - metadata=None, # type: Optional[Dict[str, str]] file_attributes="none", # type: Union[str, NTFSAttributes] file_creation_time="now", # type: Union[str, datetime] file_last_write_time="now", # type: Union[str, datetime] file_permission=None, # type: Optional[str] permission_key=None, # type: Optional[str] - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> Dict[str, Any] @@ -351,13 +348,6 @@ def create_file( # type: ignore :param int size: Specifies the maximum size for the file, up to 1 TB. - :param ~azure.storage.file.ContentSettings content_settings: - ContentSettings object used to set file properties. - :param metadata: - Name-value pairs associated with the file as metadata. - :type metadata: dict(str, str) - :param int timeout: - The timeout parameter is expressed in seconds. :param file_attributes: The file system attributes for files and directories. If not set, the default value would be "None" and the attributes will be set to "Archive". @@ -381,6 +371,13 @@ def create_file( # type: ignore directory/file. Note: Only one of the x-ms-file-permission or x-ms-file-permission-key should be specified. :type permission_key: str + :keyword ~azure.storage.file.ContentSettings content_settings: + ContentSettings object used to set file properties. + :keyword metadata: + Name-value pairs associated with the file as metadata. + :type metadata: dict(str, str) + :keyword int timeout: + The timeout parameter is expressed in seconds. :returns: File-updated property dict (Etag and last modified). :rtype: dict(str, Any) @@ -393,6 +390,9 @@ def create_file( # type: ignore :dedent: 12 :caption: Create a file. """ + content_settings = kwargs.pop('content_settings', None) + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) if self.require_encryption and not self.key_encryption_key: raise ValueError("Encryption required but no key was provided.") @@ -430,17 +430,11 @@ def create_file( # type: ignore def upload_file( self, data, # type: Any length=None, # type: Optional[int] - metadata=None, # type: Optional[Dict[str, str]] - content_settings=None, # type: Optional[ContentSettings] - validate_content=False, # type: bool - max_concurrency=1, # type: Optional[int] file_attributes="none", # type: Union[str, NTFSAttributes] file_creation_time="now", # type: Union[str, datetime] file_last_write_time="now", # type: Union[str, datetime] file_permission=None, # type: Optional[str] permission_key=None, # type: Optional[str] - encoding="UTF-8", # type: str - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> Dict[str, Any] @@ -450,24 +444,6 @@ def upload_file( Content of the file. :param int length: Length of the file in bytes. Specify its maximum size, up to 1 TiB. - :param metadata: - Name-value pairs associated with the file as metadata. - :type metadata: dict(str, str) - :param ~azure.storage.file.ContentSettings content_settings: - ContentSettings object used to set file properties. - :param bool validate_content: - If true, calculates an MD5 hash for each range of the file. The storage - service checks the hash of the content that has arrived with the hash - that was sent. This is primarily valuable for detecting bitflips on - the wire if using http instead of https as https (the default) will - already validate. Note that this MD5 hash is not stored with the - file. - :param int max_concurrency: - Maximum number of parallel connections to use. - :param int timeout: - The timeout parameter is expressed in seconds. - :param str encoding: - Defaults to UTF-8. :param file_attributes: The file system attributes for files and directories. If not set, the default value would be "None" and the attributes will be set to "Archive". @@ -491,6 +467,24 @@ def upload_file( directory/file. Note: Only one of the x-ms-file-permission or x-ms-file-permission-key should be specified. :type permission_key: str + :keyword metadata: + Name-value pairs associated with the file as metadata. + :type metadata: dict(str, str) + :keyword ~azure.storage.file.ContentSettings content_settings: + ContentSettings object used to set file properties. + :keyword bool validate_content: + If true, calculates an MD5 hash for each range of the file. The storage + service checks the hash of the content that has arrived with the hash + that was sent. This is primarily valuable for detecting bitflips on + the wire if using http instead of https as https (the default) will + already validate. Note that this MD5 hash is not stored with the + file. + :keyword int max_concurrency: + Maximum number of parallel connections to use. + :keyword int timeout: + The timeout parameter is expressed in seconds. + :keyword str encoding: + Defaults to UTF-8. :returns: File-updated property dict (Etag and last modified). :rtype: dict(str, Any) @@ -503,6 +497,12 @@ def upload_file( :dedent: 12 :caption: Upload a file. """ + metadata = kwargs.pop('metadata', None) + content_settings = kwargs.pop('content_settings', None) + max_concurrency = kwargs.pop('max_concurrency', 1) + validate_content = kwargs.pop('validate_content', False) + timeout = kwargs.pop('timeout', None) + encoding = kwargs.pop('encoding', 'UTF-8') if self.require_encryption or (self.key_encryption_key is not None): raise ValueError("Encryption not supported.") @@ -541,8 +541,6 @@ def upload_file( @distributed_trace def start_copy_from_url( self, source_url, # type: str - metadata=None, # type: Optional[Dict[str, str]] - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> Any @@ -554,10 +552,10 @@ def start_copy_from_url( :param str source_url: Specifies the URL of the source file. - :param metadata: + :keyword metadata: Name-value pairs associated with the file as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: dict(str, Any) @@ -570,6 +568,8 @@ def start_copy_from_url( :dedent: 12 :caption: Copy a file from a URL """ + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) @@ -584,8 +584,8 @@ def start_copy_from_url( except StorageErrorException as error: process_storage_error(error) - def abort_copy(self, copy_id, timeout=None, **kwargs): - # type: (Union[str, FileProperties], Optional[int], Any) -> Dict[str, Any] + def abort_copy(self, copy_id, **kwargs): + # type: (Union[str, FileProperties], Any) -> Dict[str, Any] """Abort an ongoing copy operation. This will leave a destination file with zero length and full metadata. @@ -595,8 +595,11 @@ def abort_copy(self, copy_id, timeout=None, **kwargs): The copy operation to abort. This can be either an ID, or an instance of FileProperties. :type copy_id: str or ~azure.storage.file.FileProperties + :keyword int timeout: + The timeout parameter is expressed in seconds. :rtype: None """ + timeout = kwargs.pop('timeout', None) try: copy_id = copy_id.copy.id except AttributeError: @@ -613,8 +616,6 @@ def abort_copy(self, copy_id, timeout=None, **kwargs): def download_file( self, offset=None, # type: Optional[int] length=None, # type: Optional[int] - validate_content=False, # type: bool - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> Iterable[bytes] @@ -626,7 +627,7 @@ def download_file( :param int length: Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance. - :param bool validate_content: + :keyword bool validate_content: If true, calculates an MD5 hash for each chunk of the file. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on @@ -635,7 +636,7 @@ def download_file( file. Also note that if enabled, the memory-efficient upload algorithm will not be used, because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: A iterable data generator (stream) @@ -648,6 +649,8 @@ def download_file( :dedent: 12 :caption: Download a file. """ + validate_content = kwargs.pop('validate_content', False) + timeout = kwargs.pop('timeout', None) if self.require_encryption or (self.key_encryption_key is not None): raise ValueError("Encryption not supported.") if length is not None and offset is None: @@ -670,12 +673,12 @@ def download_file( **kwargs) @distributed_trace - def delete_file(self, timeout=None, **kwargs): - # type: (Optional[int], Optional[Any]) -> None + def delete_file(self, **kwargs): + # type: (Any) -> None """Marks the specified file for deletion. The file is later deleted during garbage collection. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -688,21 +691,23 @@ def delete_file(self, timeout=None, **kwargs): :dedent: 12 :caption: Delete a file. """ + timeout = kwargs.pop('timeout', None) try: self._client.file.delete(timeout=timeout, **kwargs) except StorageErrorException as error: process_storage_error(error) @distributed_trace - def get_file_properties(self, timeout=None, **kwargs): - # type: (Optional[int], Any) -> FileProperties + def get_file_properties(self, **kwargs): + # type: (Any) -> FileProperties """Returns all user-defined metadata, standard HTTP properties, and system properties for the file. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: ~azure.storage.file.FileProperties """ + timeout = kwargs.pop('timeout', None) try: file_props = self._client.file.get_properties( sharesnapshot=self.snapshot, @@ -724,7 +729,6 @@ def set_http_headers(self, content_settings, # type: ContentSettings file_last_write_time="preserve", # type: Union[str, datetime] file_permission=None, # type: Optional[str] permission_key=None, # type: Optional[str] - timeout=None, # type: Optional[int] **kwargs # Any ): # type: ignore # type: (ContentSettings, Optional[int], Optional[Any]) -> Dict[str, Any] @@ -732,7 +736,7 @@ def set_http_headers(self, content_settings, # type: ContentSettings :param ~azure.storage.file.ContentSettings content_settings: ContentSettings object used to set file properties. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :param file_attributes: The file system attributes for files and directories. @@ -759,6 +763,7 @@ def set_http_headers(self, content_settings, # type: ContentSettings :returns: File-updated property dict (Etag and last modified). :rtype: dict(str, Any) """ + timeout = kwargs.pop('timeout', None) file_content_length = kwargs.pop('size', None) file_http_headers = FileHTTPHeaders( file_cache_control=content_settings.cache_control, @@ -785,8 +790,8 @@ def set_http_headers(self, content_settings, # type: ContentSettings process_storage_error(error) @distributed_trace - def set_file_metadata(self, metadata=None, timeout=None, **kwargs): # type: ignore - #type: (Optional[Dict[str, Any]], Optional[int], Optional[Any]) -> Dict[str, Any] + def set_file_metadata(self, metadata=None, **kwargs): # type: ignore + #type: (Optional[Dict[str, Any]], Any) -> Dict[str, Any] """Sets user-defined metadata for the specified file as one or more name-value pairs. @@ -797,11 +802,12 @@ def set_file_metadata(self, metadata=None, timeout=None, **kwargs): # type: igno :param metadata: Name-value pairs associated with the file as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: File-updated property dict (Etag and last modified). :rtype: dict(str, Any) """ + timeout = kwargs.pop('timeout', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) # type: ignore try: @@ -819,9 +825,6 @@ def upload_range( # type: ignore self, data, # type: bytes start_range, # type: int end_range, # type: int - validate_content=False, # type: Optional[bool] - timeout=None, # type: Optional[int] - encoding='UTF-8', **kwargs ): # type: (...) -> Dict[str, Any] @@ -839,20 +842,23 @@ def upload_range( # type: ignore The range can be up to 4 MB in size. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will upload first 512 bytes of file. - :param bool validate_content: + :keyword bool validate_content: If true, calculates an MD5 hash of the page content. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https as https (the default) will already validate. Note that this MD5 hash is not stored with the file. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. - :param str encoding: + :keyword str encoding: Defaults to UTF-8. :returns: File-updated property dict (Etag and last modified). :rtype: Dict[str, Any] """ + validate_content = kwargs.pop('validate_content', False) + timeout = kwargs.pop('timeout', None) + encoding = kwargs.pop('encoding', 'UTF-8') if self.require_encryption or (self.key_encryption_key is not None): raise ValueError("Encryption not supported.") if isinstance(data, six.text_type): @@ -933,10 +939,10 @@ def upload_range_from_url(self, source_url, # type: str The range can be up to 4 MB in size. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of file. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. ''' - + timeout = kwargs.pop('timeout', None) options = self._upload_range_from_url_options( source_url=source_url, range_start=range_start, @@ -953,7 +959,6 @@ def upload_range_from_url(self, source_url, # type: str def get_ranges( # type: ignore self, start_range=None, # type: Optional[int] end_range=None, # type: Optional[int] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> List[dict[str, int]] @@ -967,11 +972,12 @@ def get_ranges( # type: ignore Specifies the end offset of bytes over which to get ranges. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of file. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: A list of valid ranges. :rtype: List[dict[str, int]] """ + timeout = kwargs.pop('timeout', None) if self.require_encryption or (self.key_encryption_key is not None): raise ValueError("Unsupported method for encryption.") @@ -995,7 +1001,6 @@ def get_ranges( # type: ignore def clear_range( # type: ignore self, start_range, # type: int end_range, # type: int - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> Dict[str, Any] @@ -1012,11 +1017,12 @@ def clear_range( # type: ignore The range can be up to 4 MB in size. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of file. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: File-updated property dict (Etag and last modified). :rtype: Dict[str, Any] """ + timeout = kwargs.pop('timeout', None) if self.require_encryption or (self.key_encryption_key is not None): raise ValueError("Unsupported method for encryption.") @@ -1037,17 +1043,18 @@ def clear_range( # type: ignore process_storage_error(error) @distributed_trace - def resize_file(self, size, timeout=None, **kwargs): # type: ignore - # type: (int, Optional[int], Optional[Any]) -> Dict[str, Any] + def resize_file(self, size, **kwargs): # type: ignore + # type: (int, Any) -> Dict[str, Any] """Resizes a file to the specified size. :param int size: Size to resize file to (in bytes) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: File-updated property dict (Etag and last modified). :rtype: Dict[str, Any] """ + timeout = kwargs.pop('timeout', None) try: return self._client.file.set_http_headers( # type: ignore file_content_length=size, @@ -1062,15 +1069,16 @@ def resize_file(self, size, timeout=None, **kwargs): # type: ignore process_storage_error(error) @distributed_trace - def list_handles(self, timeout=None, **kwargs): + def list_handles(self, **kwargs): # type: (int, Any) -> ItemPaged[Handle] """Lists handles for file. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: An auto-paging iterable of HandleItem :rtype: ~azure.core.paging.ItemPaged[~azure.storage.file.HandleItem] """ + timeout = kwargs.pop('timeout', None) results_per_page = kwargs.pop('results_per_page', None) command = functools.partial( self._client.file.list_handles, @@ -1084,7 +1092,6 @@ def list_handles(self, timeout=None, **kwargs): @distributed_trace def close_handles( self, handle=None, # type: Union[str, HandleItem] - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> Any @@ -1097,11 +1104,12 @@ def close_handles( Optionally, a specific handle to close. The default value is '*' which will attempt to close all open handles. :type handle: str or ~azure.storage.file.Handle - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: A long-running poller to get operation status. :rtype: ~azure.core.polling.LROPoller """ + timeout = kwargs.pop('timeout', None) try: handle_id = handle.id # type: ignore except AttributeError: 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 f2d6ee41666a..b81a9fe788b6 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 @@ -208,12 +208,12 @@ def generate_shared_access_signature( ) # type: ignore @distributed_trace - def get_service_properties(self, timeout=None, **kwargs): - # type: (Optional[int], Any) -> Dict[str, Any] + def get_service_properties(self, **kwargs): + # type: (Any) -> Dict[str, Any] """Gets the properties of a storage account's File service, including Azure Storage Analytics. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: ~azure.storage.file._generated.models.StorageServiceProperties @@ -226,6 +226,7 @@ def get_service_properties(self, timeout=None, **kwargs): :dedent: 8 :caption: Get file service properties. """ + timeout = kwargs.pop('timeout', None) try: return self._client.service.get_properties(timeout=timeout, **kwargs) except StorageErrorException as error: @@ -236,7 +237,6 @@ def set_service_properties( self, hour_metrics=None, # type: Optional[Metrics] minute_metrics=None, # type: Optional[Metrics] cors=None, # type: Optional[List[CorsRule]] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> None @@ -257,7 +257,7 @@ def set_service_properties( list. If an empty list is specified, all CORS rules will be deleted, and CORS will be disabled for the service. :type cors: list(:class:`~azure.storage.file.CorsRule`) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -270,6 +270,7 @@ def set_service_properties( :dedent: 8 :caption: Sets file service properties. """ + timeout = kwargs.pop('timeout', None) props = StorageServiceProperties( hour_metrics=hour_metrics, minute_metrics=minute_metrics, @@ -285,7 +286,6 @@ def list_shares( self, name_starts_with=None, # type: Optional[str] include_metadata=False, # type: Optional[bool] include_snapshots=False, # type: Optional[bool] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> ItemPaged[ShareProperties] @@ -300,7 +300,7 @@ def list_shares( Specifies that share metadata be returned in the response. :param bool include_snapshots: Specifies that share snapshot be returned in the response. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: An iterable (auto-paging) of ShareProperties. :rtype: ~azure.core.paging.ItemPaged[~azure.storage.file.ShareProperties] @@ -314,6 +314,7 @@ def list_shares( :dedent: 12 :caption: List shares in the file service. """ + timeout = kwargs.pop('timeout', None) include = [] if include_metadata: include.append('metadata') @@ -332,9 +333,6 @@ def list_shares( @distributed_trace def create_share( self, share_name, # type: str - metadata=None, # type: Optional[Dict[str, str]] - quota=None, # type: Optional[int] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> ShareClient @@ -343,13 +341,13 @@ def create_share( which to interact with the newly created share. :param str share_name: The name of the share to create. - :param metadata: + :keyword metadata: A dict with name_value pairs to associate with the share as metadata. Example:{'Category':'test'} :type metadata: dict(str, str) - :param int quota: + :keyword int quota: Quota in bytes. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: ~azure.storage.file.ShareClient @@ -362,6 +360,9 @@ def create_share( :dedent: 8 :caption: Create a share in the file service. """ + metadata = kwargs.pop('metadata', None) + quota = kwargs.pop('quota', None) + timeout = kwargs.pop('timeout', None) share = self.get_share_client(share_name) kwargs.setdefault('merge_span', True) share.create_share(metadata, quota=quota, timeout=timeout, **kwargs) @@ -371,7 +372,6 @@ def create_share( def delete_share( self, share_name, # type: Union[ShareProperties, str] delete_snapshots=False, # type: Optional[bool] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> None @@ -384,7 +384,7 @@ def delete_share( :type share_name: str or ~azure.storage.file.ShareProperties :param bool delete_snapshots: Indicates if snapshots are to be deleted. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -397,6 +397,7 @@ def delete_share( :dedent: 12 :caption: Delete a share in the file service. """ + timeout = kwargs.pop('timeout', None) share = self.get_share_client(share_name) kwargs.setdefault('merge_span', True) share.delete_share( 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 dc19e6b9aaa6..ce1dbf396e65 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 @@ -174,12 +174,7 @@ def generate_shared_access_signature( 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 + **kwargs # type: Any ): # type: (...) -> str """Generates a shared access signature for the share. Use the returned signature with the credential parameter of any FileServiceClient, @@ -216,28 +211,34 @@ def generate_shared_access_signature( or address range specified on the SAS token, the request is not authenticated. For example, specifying sip=168.1.5.65 or sip=168.1.5.60-168.1.5.70 on the SAS restricts the request to those IP addresses. - :param str protocol: + :keyword str protocol: Specifies the protocol permitted for a request made. Possible values are both HTTPS and HTTP (https,http) or HTTPS only (https). The default value is https,http. Note that HTTP only is not a permitted value. - :param str cache_control: + :keyword str cache_control: Response header value for Cache-Control when resource is accessed using this shared access signature. - :param str content_disposition: + :keyword str content_disposition: Response header value for Content-Disposition when resource is accessed using this shared access signature. - :param str content_encoding: + :keyword str content_encoding: Response header value for Content-Encoding when resource is accessed using this shared access signature. - :param str content_language: + :keyword str content_language: Response header value for Content-Language when resource is accessed using this shared access signature. - :param str content_type: + :keyword str content_type: Response header value for Content-Type when resource is accessed using this shared access signature. :return: A Shared Access Signature (sas) token. :rtype: str """ + protocol = kwargs.pop('protocol', None) + cache_control = kwargs.pop('cache_control', None) + content_disposition = kwargs.pop('content_disposition', None) + content_encoding = kwargs.pop('content_encoding', None) + content_language = kwargs.pop('content_language', None) + content_type = kwargs.pop('content_type', None) if not hasattr(self.credential, 'account_key') or not self.credential.account_key: raise ValueError("No account SAS key available.") sas = FileSharedAccessSignature(self.credential.account_name, self.credential.account_key) @@ -286,22 +287,17 @@ def get_file_client(self, file_path): _configuration=self._config, _pipeline=self._pipeline, _location_mode=self._location_mode) @distributed_trace - def create_share( # type: ignore - self, metadata=None, # type: Optional[Dict[str, str]] - quota=None, # type: Optional[int] - timeout=None, # type: Optional[int] - **kwargs # type: Optional[Any] - ): - # type: (...) -> Dict[str, Any] + def create_share(self, **kwargs): # type: ignore + # type: (Any) -> Dict[str, Any] """Creates a new Share under the account. If a share with the same name already exists, the operation fails. - :param metadata: + :keyword metadata: Name-value pairs associated with the share as metadata. :type metadata: dict(str, str) - :param int quota: + :keyword int quota: The quota to be allotted. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Share-updated property dict (Etag and last modified). :rtype: dict(str, Any) @@ -315,6 +311,9 @@ def create_share( # type: ignore :dedent: 8 :caption: Creates a file share. """ + metadata = kwargs.pop('metadata', None) + quota = kwargs.pop('quota', None) + timeout = kwargs.pop('timeout', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) # type: ignore @@ -331,8 +330,7 @@ def create_share( # type: ignore @distributed_trace def create_snapshot( # type: ignore - self, metadata=None, # type: Optional[Dict[str, str]] - timeout=None, # type: Optional[int] + self, **kwargs # type: Optional[Any] ): # type: (...) -> Dict[str, Any] @@ -346,10 +344,10 @@ def create_snapshot( # type: ignore is taken, with a DateTime value appended to indicate the time at which the snapshot was taken. - :param metadata: + :keyword metadata: Name-value pairs associated with the share as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Share-updated property dict (Snapshot ID, Etag, and last modified). :rtype: dict[str, Any] @@ -363,6 +361,8 @@ def create_snapshot( # type: ignore :dedent: 12 :caption: Creates a snapshot of the file share. """ + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) # type: ignore try: @@ -377,7 +377,6 @@ def create_snapshot( # type: ignore @distributed_trace def delete_share( self, delete_snapshots=False, # type: Optional[bool] - timeout=None, # type: Optional[int] **kwargs ): # type: (...) -> None @@ -386,7 +385,7 @@ def delete_share( :param bool delete_snapshots: Indicates if snapshots are to be deleted. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :rtype: None @@ -399,6 +398,7 @@ def delete_share( :dedent: 12 :caption: Deletes the share and any snapshots. """ + timeout = kwargs.pop('timeout', None) delete_include = None if delete_snapshots: delete_include = DeleteSnapshotsOptionType.include @@ -412,13 +412,13 @@ def delete_share( process_storage_error(error) @distributed_trace - def get_share_properties(self, timeout=None, **kwargs): - # type: (Optional[int], Any) -> ShareProperties + def get_share_properties(self, **kwargs): + # type: (Any) -> ShareProperties """Returns all user-defined metadata and system properties for the specified share. The data returned does not include the shares's list of files or directories. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: The share properties. :rtype: ~azure.storage.file.ShareProperties @@ -432,6 +432,7 @@ def get_share_properties(self, timeout=None, **kwargs): :dedent: 12 :caption: Gets the share properties. """ + timeout = kwargs.pop('timeout', None) try: props = self._client.share.get_properties( timeout=timeout, @@ -445,14 +446,14 @@ def get_share_properties(self, timeout=None, **kwargs): return props # type: ignore @distributed_trace - def set_share_quota(self, quota, timeout=None, **kwargs): # type: ignore - # type: (int, Optional[int], Any) -> Dict[str, Any] + def set_share_quota(self, quota, **kwargs): # type: ignore + # type: (int, Any) -> Dict[str, Any] """Sets the quota for the share. :param int quota: Specifies the maximum size of the share, in gigabytes. Must be greater than 0, and less than or equal to 5TB. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Share-updated property dict (Etag and last modified). :rtype: dict(str, Any) @@ -466,6 +467,7 @@ def set_share_quota(self, quota, timeout=None, **kwargs): # type: ignore :dedent: 12 :caption: Sets the share quota. """ + timeout = kwargs.pop('timeout', None) try: return self._client.share.set_quota( # type: ignore timeout=timeout, @@ -476,8 +478,8 @@ def set_share_quota(self, quota, timeout=None, **kwargs): # type: ignore process_storage_error(error) @distributed_trace - def set_share_metadata(self, metadata, timeout=None, **kwargs): # type: ignore - # type: (Dict[str, Any], Optional[int], Any) -> Dict[str, Any] + def set_share_metadata(self, metadata, **kwargs): # type: ignore + # type: (Dict[str, Any], Any) -> Dict[str, Any] """Sets the metadata for the share. Each call to this operation replaces all existing metadata @@ -487,7 +489,7 @@ def set_share_metadata(self, metadata, timeout=None, **kwargs): # type: ignore :param metadata: Name-value pairs associated with the share as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Share-updated property dict (Etag and last modified). :rtype: dict(str, Any) @@ -501,6 +503,7 @@ def set_share_metadata(self, metadata, timeout=None, **kwargs): # type: ignore :dedent: 12 :caption: Sets the share metadata. """ + timeout = kwargs.pop('timeout', None) headers = kwargs.pop('headers', {}) headers.update(add_metadata_headers(metadata)) try: @@ -513,16 +516,17 @@ def set_share_metadata(self, metadata, timeout=None, **kwargs): # type: ignore process_storage_error(error) @distributed_trace - def get_share_access_policy(self, timeout=None, **kwargs): - # type: (Optional[int], **Any) -> Dict[str, Any] + def get_share_access_policy(self, **kwargs): + # type: (Any) -> Dict[str, Any] """Gets the permissions for the share. The permissions indicate whether files in a share may be accessed publicly. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Access policy information in a dict. :rtype: dict[str, str] """ + timeout = kwargs.pop('timeout', None) try: response, identifiers = self._client.share.get_access_policy( timeout=timeout, @@ -536,8 +540,8 @@ def get_share_access_policy(self, timeout=None, **kwargs): } @distributed_trace - def set_share_access_policy(self, signed_identifiers, timeout=None, **kwargs): # type: ignore - # type: (Dict[str, AccessPolicy], Optional[int], **Any) -> Dict[str, str] + def set_share_access_policy(self, signed_identifiers, **kwargs): # type: ignore + # type: (Dict[str, AccessPolicy], Any) -> Dict[str, str] """Sets the permissions for the share, or stored access policies that may be used with Shared Access Signatures. The permissions indicate whether files in a share may be accessed publicly. @@ -547,11 +551,12 @@ def set_share_access_policy(self, signed_identifiers, timeout=None, **kwargs): # dictionary may contain up to 5 elements. An empty dictionary will clear the access policies set on the service. :type signed_identifiers: dict(str, :class:`~azure.storage.file.AccessPolicy`) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: Share-updated property dict (Etag and last modified). :rtype: dict(str, Any) """ + timeout = kwargs.pop('timeout', None) if len(signed_identifiers) > 5: raise ValueError( 'Too many access policies provided. The server does not support setting ' @@ -573,18 +578,19 @@ def set_share_access_policy(self, signed_identifiers, timeout=None, **kwargs): # process_storage_error(error) @distributed_trace - def get_share_stats(self, timeout=None, **kwargs): # type: ignore - # type: (Optional[int], **Any) -> int + def get_share_stats(self, **kwargs): # type: ignore + # type: (Any) -> int """Gets the approximate size of the data stored on the share in bytes. Note that this value may not include all recently created or recently re-sized files. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :return: The approximate size of the data (in bytes) stored on the share. :rtype: int """ + timeout = kwargs.pop('timeout', None) try: stats = self._client.share.get_statistics( timeout=timeout, @@ -598,7 +604,6 @@ def list_directories_and_files( # type: ignore self, directory_name=None, # type: Optional[str] name_starts_with=None, # type: Optional[str] marker=None, # type: Optional[str] - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> Iterable[dict[str,str]] @@ -613,7 +618,7 @@ def list_directories_and_files( # type: ignore An opaque continuation token. This value can be retrieved from the next_marker field of a previous generator object. If specified, this generator will begin returning results from this point. - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: An auto-paging iterable of dict-like DirectoryProperties and FileProperties @@ -626,6 +631,7 @@ def list_directories_and_files( # type: ignore :dedent: 12 :caption: List directories and files in the share. """ + timeout = kwargs.pop('timeout', None) directory = self.get_directory_client(directory_name) kwargs.setdefault('merge_span', True) return directory.list_directories_and_files( @@ -644,7 +650,6 @@ def _create_permission_for_share_options(file_permission, # type: str @distributed_trace def create_permission_for_share(self, file_permission, # type: str - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> str @@ -656,11 +661,12 @@ def create_permission_for_share(self, file_permission, # type: str :param str file_permission: File permission, a Portable SDDL - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: a file permission key :rtype: str """ + timeout = kwargs.pop('timeout', None) options = self._create_permission_for_share_options(file_permission, timeout=timeout, **kwargs) try: return self._client.share.create_permission(**options) @@ -670,7 +676,6 @@ def create_permission_for_share(self, file_permission, # type: str @distributed_trace def get_permission_for_share( # type: ignore self, permission_key, # type: str - timeout=None, # type: Optional[int] **kwargs # type: Any ): # type: (...) -> str @@ -680,11 +685,12 @@ def get_permission_for_share( # type: ignore :param str permission_key: Key of the file permission to retrieve - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: a file permission(a portable SDDL) :rtype: str """ + timeout = kwargs.pop('timeout', None) try: return self._client.share.get_permission( # type: ignore file_permission_key=permission_key, @@ -695,22 +701,24 @@ def get_permission_for_share( # type: ignore process_storage_error(error) @distributed_trace - def create_directory(self, directory_name, metadata=None, timeout=None, **kwargs): - # type: (str, Optional[Dict[str, Any]], Optional[int], Any) -> DirectoryClient + def create_directory(self, directory_name, **kwargs): + # type: (str, Any) -> DirectoryClient """Creates a directory in the share and returns a client to interact with the directory. :param str directory_name: The name of the directory. - :param metadata: + :keyword metadata: Name-value pairs associated with the directory as metadata. :type metadata: dict(str, str) - :param int timeout: + :keyword int timeout: The timeout parameter is expressed in seconds. :returns: DirectoryClient :rtype: ~azure.storage.file.directory_client.DirectoryClient """ + metadata = kwargs.pop('metadata', None) + timeout = kwargs.pop('timeout', None) directory = self.get_directory_client(directory_name) kwargs.setdefault('merge_span', True) - directory.create_directory(metadata, timeout, **kwargs) + directory.create_directory(metadata=metadata, timeout=timeout, **kwargs) return directory # type: ignore diff --git a/sdk/storage/azure-storage-file/tests/test_share.py b/sdk/storage/azure-storage-file/tests/test_share.py index b38591c0f4f8..bdf2767121c0 100644 --- a/sdk/storage/azure-storage-file/tests/test_share.py +++ b/sdk/storage/azure-storage-file/tests/test_share.py @@ -198,7 +198,7 @@ def test_create_share_with_metadata(self): # Act client = self._get_share_reference() - created = client.create_share(metadata) + created = client.create_share(metadata=metadata) # Assert self.assertTrue(created) @@ -342,7 +342,7 @@ def test_list_shares_with_include_metadata(self): # Arrange metadata = {'hello': 'world', 'number': '42'} share = self._get_share_reference() - share.create_share(metadata) + share.create_share(metadata=metadata) # Act @@ -406,7 +406,7 @@ def test_get_share_metadata(self): # Act client = self._get_share_reference() - created = client.create_share(metadata) + created = client.create_share(metadata=metadata) # Assert self.assertTrue(created) @@ -421,7 +421,7 @@ def test_get_share_metadata_with_snapshot(self): # Act client = self._get_share_reference() - created = client.create_share(metadata) + created = client.create_share(metadata=metadata) snapshot = client.create_snapshot() snapshot_client = self.fsc.get_share_client(client.share_name, snapshot=snapshot) diff --git a/sdk/storage/azure-storage-file/tests/test_share_async.py b/sdk/storage/azure-storage-file/tests/test_share_async.py index b29aef333a05..9025070616b3 100644 --- a/sdk/storage/azure-storage-file/tests/test_share_async.py +++ b/sdk/storage/azure-storage-file/tests/test_share_async.py @@ -231,7 +231,7 @@ async def _test_create_share_with_metadata_async(self): # Act client = self._get_share_reference() - created = await client.create_share(metadata) + created = await client.create_share(metadata=metadata) # Assert self.assertTrue(created) @@ -410,7 +410,7 @@ async def _test_list_shares_with_include_metadata_async(self): # Arrange metadata = {'hello': 'world', 'number': '42'} share = self._get_share_reference() - await share.create_share(metadata) + await share.create_share(metadata=metadata) # Act shares = [] @@ -489,7 +489,7 @@ async def _test_get_share_metadata_async(self): # Act client = self._get_share_reference() - created = await client.create_share(metadata) + created = await client.create_share(metadata=metadata) # Assert self.assertTrue(created) @@ -507,7 +507,7 @@ async def _test_get_share_metadata_with_snapshot_async(self): # Act client = self._get_share_reference() - created = await client.create_share(metadata) + created = await client.create_share(metadata=metadata) snapshot = await client.create_snapshot() snapshot_client = self.fsc.get_share_client(client.share_name, snapshot=snapshot) From efeebdd83c2f6a98c3ee0b6742fd913cf1b0ca62 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 15 Oct 2019 09:19:17 -0700 Subject: [PATCH 3/7] small fix --- sdk/storage/azure-storage-file/azure/storage/file/file_client.py | 1 + 1 file changed, 1 insertion(+) 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 ce150893ced1..87d87b2585c6 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 @@ -244,6 +244,7 @@ def generate_shared_access_signature( start=None, # type: Optional[Union[datetime, str]] policy_id=None, # type: Optional[str] ip=None, # type: Optional[str] + **kwargs # type: Any ): # type: (...) -> str """Generates a shared access signature for the file. From 6bc6c2bcfa2ee79016fea774dab4352a2569f470 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 15 Oct 2019 09:47:00 -0700 Subject: [PATCH 4/7] minor fix --- .../azure/storage/file/aio/file_service_client_async.py | 2 +- .../azure/storage/file/file_service_client.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 7afc9a12408c..cd73b57231f1 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 @@ -247,7 +247,7 @@ async def create_share( timeout = kwargs.pop('timeout', None) share = self.get_share_client(share_name) kwargs.setdefault('merge_span', True) - await share.create_share(metadata, quota, timeout, **kwargs) + await share.create_share(metadata=metadata, quota=quota, timeout=timeout, **kwargs) return share @distributed_trace_async 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 b81a9fe788b6..7ee62c380d6b 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 @@ -365,7 +365,7 @@ def create_share( timeout = kwargs.pop('timeout', None) share = self.get_share_client(share_name) kwargs.setdefault('merge_span', True) - share.create_share(metadata, quota=quota, timeout=timeout, **kwargs) + share.create_share(metadata=metadata, quota=quota, timeout=timeout, **kwargs) return share @distributed_trace From 954e3c5c2acf52fa4b188b1a30afc124dd01b7fe Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 15 Oct 2019 10:53:27 -0700 Subject: [PATCH 5/7] comments + lint --- .../file/aio/directory_client_async.py | 20 ++++++++++--------- .../storage/file/aio/file_client_async.py | 2 ++ .../file/aio/file_service_client_async.py | 2 ++ .../storage/file/aio/share_client_async.py | 4 +++- .../azure/storage/file/file_client.py | 1 - 5 files changed, 18 insertions(+), 11 deletions(-) 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 ba4c0e9faecd..7cd780ee1867 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 @@ -74,6 +74,8 @@ class DirectoryClient(AsyncStorageAccountHostsMixin, DirectoryClientBase): The credential with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string or an account shared access key. + :keyword loop: + The event loop to run the asynchronous tasks. """ def __init__( # type: ignore self, directory_url, # type: str @@ -142,7 +144,7 @@ def get_subdirectory_client(self, directory_name, **kwargs): _location_mode=self._location_mode, loop=self._loop, **kwargs) @distributed_trace_async - async def create_directory( self, **kwargs): # type: ignore + async def create_directory(self, **kwargs): # type: ignore # type: (Any) -> Dict[str, Any] """Creates a new directory under the directory referenced by the client. @@ -236,7 +238,7 @@ def list_directories_and_files(self, name_starts_with=None, **kwargs): @distributed_trace def list_handles(self, recursive=False, **kwargs): - # type: (bool, Optional[int], Any) -> AsyncItemPaged + # type: (bool, Any) -> AsyncItemPaged """Lists opened handles on a directory or a file under the directory. :param bool recursive: @@ -332,7 +334,7 @@ async def get_directory_properties(self, **kwargs): @distributed_trace_async async def set_directory_metadata(self, metadata, **kwargs): # type: ignore - # type: (Dict[str, Any], Optional[int], Any) -> Dict[str, Any] + # type: (Dict[str, Any], Any) -> Dict[str, Any] """Sets the metadata for the directory. Each call to this operation replaces all existing metadata @@ -489,23 +491,23 @@ async def upload_file( Content of the file. :param int length: Length of the file in bytes. Specify its maximum size, up to 1 TiB. - :param metadata: + :keyword metadata: Name-value pairs associated with the file as metadata. :type metadata: dict(str, str) - :param ~azure.storage.file.ContentSettings content_settings: + :keyword ~azure.storage.file.ContentSettings content_settings: ContentSettings object used to set file properties. - :param bool validate_content: + :keyword bool validate_content: If true, calculates an MD5 hash for each range of the file. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https as https (the default) will already validate. Note that this MD5 hash is not stored with the file. - :param int max_concurrency: + :keyword int max_concurrency: Maximum number of parallel connections to use. :keyword int timeout: The timeout parameter is expressed in seconds. - :param str encoding: + :keyword str encoding: Defaults to UTF-8. :returns: FileClient :rtype: ~azure.storage.file.aio.file_client_async.FileClient @@ -541,7 +543,6 @@ async def upload_file( @distributed_trace_async async def delete_file( self, file_name, # type: str - timeout=None, # type: Optional[int] **kwargs # type: Optional[Any] ): # type: (...) -> None @@ -563,5 +564,6 @@ async def delete_file( :dedent: 12 :caption: Delete a file in a directory. """ + timeout = kwargs.pop('timeout', None) file_client = self.get_file_client(file_name) await file_client.delete_file(timeout=timeout, **kwargs) 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 945f64e73e06..256cfa447bc6 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 @@ -121,6 +121,8 @@ class FileClient(AsyncStorageAccountHostsMixin, FileClientBase): The credential with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string or an account shared access key. + :keyword loop: + The event loop to run the asynchronous tasks. """ def __init__( # type: ignore 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 cd73b57231f1..1d1d7cabafd3 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 @@ -64,6 +64,8 @@ class FileServiceClient(AsyncStorageAccountHostsMixin, FileServiceClientBase): The credential with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string or an account shared access key. + :keyword loop: + The event loop to run the asynchronous tasks. .. admonition:: Example: 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 d9057384d160..5cc934476906 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 @@ -67,6 +67,8 @@ class ShareClient(AsyncStorageAccountHostsMixin, ShareClientBase): The credential with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string or an account shared access key. + :keyword loop: + The event loop to run the asynchronous tasks. """ def __init__( # type: ignore self, share_url, # type: str @@ -522,7 +524,7 @@ async def get_permission_for_share( # type: ignore @distributed_trace_async async def create_directory(self, directory_name, **kwargs): - # type: (str, Optional[Dict[str, Any]], Optional[int], Any) -> DirectoryClient + # type: (str, Any) -> DirectoryClient """Creates a directory in the share and returns a client to interact with the directory. 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 87d87b2585c6..35bd3d31eca6 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 @@ -943,7 +943,6 @@ def upload_range_from_url(self, source_url, # type: str :keyword int timeout: The timeout parameter is expressed in seconds. ''' - timeout = kwargs.pop('timeout', None) options = self._upload_range_from_url_options( source_url=source_url, range_start=range_start, From e76ff0e01e8d3e4ff3bd2d16c038068f4aac22b3 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 15 Oct 2019 12:27:48 -0700 Subject: [PATCH 6/7] some changes --- sdk/storage/azure-storage-file/HISTORY.md | 7 ++++++- .../storage/file/aio/directory_client_async.py | 15 +-------------- .../azure/storage/file/aio/share_client_async.py | 4 +--- .../azure/storage/file/directory_client.py | 14 +------------- .../azure/storage/file/share_client.py | 4 +--- sdk/storage/azure-storage-queue/HISTORY.md | 7 ++++++- 6 files changed, 16 insertions(+), 35 deletions(-) diff --git a/sdk/storage/azure-storage-file/HISTORY.md b/sdk/storage/azure-storage-file/HISTORY.md index f9e14c5c185c..ea34318d161d 100644 --- a/sdk/storage/azure-storage-file/HISTORY.md +++ b/sdk/storage/azure-storage-file/HISTORY.md @@ -12,7 +12,12 @@ To use a directory_url, the method `from_directory_url` must be used. `file_path`. To use a file_url, the method `from_file_url` must be used. - `file_permission_key` parameter has been renamed to `permission_key` - `set_share_access_policy` has required parameter `signed_identifiers`. -- NoRetry policy has been removed. Use keyword argument `retry_total=0` for no retries. +- NoRetry policy has been removed. Use keyword argument `retry_total=0` for no retries. +- Some parameters have become keyword only, rather than positional. Some examples include: + - `loop` + - `max_concurrency` + - `validate_content` + - `timeout` etc. **New features** 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 7fff76f2833e..63021bca89bc 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 @@ -518,22 +518,10 @@ async def upload_file( :dedent: 12 :caption: Upload a file to a directory. """ - metadata = kwargs.pop('metadata', None) - content_settings = kwargs.pop('content_settings', None) - validate_content = kwargs.pop('validate_content', False) - max_concurrency = kwargs.pop('max_concurrency', 1) - timeout = kwargs.pop('timeout', None) - encoding = kwargs.pop('encoding', 'UTF-8') file_client = self.get_file_client(file_name) await file_client.upload_file( data, length=length, - metadata=metadata, - content_settings=content_settings, - validate_content=validate_content, - max_concurrency=max_concurrency, - timeout=timeout, - encoding=encoding, **kwargs) return file_client # type: ignore @@ -561,6 +549,5 @@ async def delete_file( :dedent: 12 :caption: Delete a file in a directory. """ - timeout = kwargs.pop('timeout', None) file_client = self.get_file_client(file_name) - await file_client.delete_file(timeout=timeout, **kwargs) + await file_client.delete_file(**kwargs) 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 8a330a090c88..b5e5ce453024 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 @@ -541,9 +541,7 @@ async def create_directory(self, directory_name, **kwargs): :returns: DirectoryClient :rtype: ~azure.storage.file.aio.directory_client_async.DirectoryClient """ - metadata = kwargs.pop('metadata', None) - timeout = kwargs.pop('timeout', None) directory = self.get_directory_client(directory_name) kwargs.setdefault('merge_span', True) - await directory.create_directory(metadata=metadata, timeout=timeout, **kwargs) + await directory.create_directory(**kwargs) return directory # type: ignore 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 dc366de0f3d0..9d203ff7644b 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 @@ -624,22 +624,10 @@ def upload_file( :dedent: 12 :caption: Upload a file to a directory. """ - metadata = kwargs.pop('metadata', None) - content_settings = kwargs.pop('content_settings', None) - validate_content = kwargs.pop('validate_content', False) - max_concurrency = kwargs.pop('max_concurrency', 1) - timeout = kwargs.pop('timeout', None) - encoding = kwargs.pop('encoding', 'UTF-8') file_client = self.get_file_client(file_name) file_client.upload_file( data, length=length, - metadata=metadata, - content_settings=content_settings, - validate_content=validate_content, - max_concurrency=max_concurrency, - timeout=timeout, - encoding=encoding, **kwargs) return file_client # type: ignore @@ -669,4 +657,4 @@ def delete_file( """ timeout = kwargs.pop('timeout', None) file_client = self.get_file_client(file_name) - file_client.delete_file(timeout=timeout, **kwargs) + file_client.delete_file(**kwargs) 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 42462e7a52a4..fbaedb3e7f04 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 @@ -745,9 +745,7 @@ def create_directory(self, directory_name, **kwargs): :returns: DirectoryClient :rtype: ~azure.storage.file.directory_client.DirectoryClient """ - metadata = kwargs.pop('metadata', None) - timeout = kwargs.pop('timeout', None) directory = self.get_directory_client(directory_name) kwargs.setdefault('merge_span', True) - directory.create_directory(metadata=metadata, timeout=timeout, **kwargs) + directory.create_directory(**kwargs) return directory # type: ignore diff --git a/sdk/storage/azure-storage-queue/HISTORY.md b/sdk/storage/azure-storage-queue/HISTORY.md index 108783ff09d0..06d652a83c86 100644 --- a/sdk/storage/azure-storage-queue/HISTORY.md +++ b/sdk/storage/azure-storage-queue/HISTORY.md @@ -7,7 +7,12 @@ - `QueueClient` now accepts only `account_url` with mandatory a string param `queue_name`. To use a queue_url, the method `from_queue_url` must be used. - `set_queue_access_policy` has required parameter `signed_identifiers`. -- NoRetry policy has been removed. Use keyword argument `retry_total=0` for no retries. +- NoRetry policy has been removed. Use keyword argument `retry_total=0` for no retries. +- Some parameters have become keyword only, rather than positional. Some examples include: + - `loop` + - `max_concurrency` + - `validate_content` + - `timeout` etc. **New features** From a9d9b645ece9e85479a78128f313844a16f05d47 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 15 Oct 2019 14:45:59 -0700 Subject: [PATCH 7/7] pylint --- .../azure-storage-file/azure/storage/file/directory_client.py | 1 - 1 file changed, 1 deletion(-) 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 9d203ff7644b..8b0e73b3c004 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 @@ -655,6 +655,5 @@ def delete_file( :dedent: 12 :caption: Delete a file in a directory. """ - timeout = kwargs.pop('timeout', None) file_client = self.get_file_client(file_name) file_client.delete_file(**kwargs)