From 9d2a3ebee6b68a1be24c1a9dcb0daa2f59b5bd83 Mon Sep 17 00:00:00 2001 From: Tamer Sherif Date: Thu, 28 Jan 2021 09:57:59 -0800 Subject: [PATCH 1/5] Added support for PurePosixPath --- .../_data_lake_directory_client.py | 24 ++++++++++++------- .../filedatalake/_file_system_client.py | 23 +++++++++++------- .../aio/_data_lake_directory_client_async.py | 24 ++++++++++++------- .../aio/_file_system_client_async.py | 23 +++++++++++------- 4 files changed, 62 insertions(+), 32 deletions(-) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py index d23f24552dbe..337f334c63dd 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py @@ -3,6 +3,8 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- +from pathlib import PurePosixPath + try: from urllib.parse import quote, unquote except ImportError: @@ -504,10 +506,13 @@ def get_file_client(self, file # type: Union[FileProperties, str] :returns: A DataLakeFileClient. :rtype: ~azure.storage.filedatalake..DataLakeFileClient """ - try: - file_path = file.name - except AttributeError: - file_path = self.path_name + '/' + file + if isinstance(file, PurePosixPath): + file_path = str(file) + else: + try: + file_path = file.name + except AttributeError: + file_path = self.path_name + '/' + file _pipeline = Pipeline( transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access @@ -534,10 +539,13 @@ def get_sub_directory_client(self, sub_directory # type: Union[DirectoryPropert :returns: A DataLakeDirectoryClient. :rtype: ~azure.storage.filedatalake.DataLakeDirectoryClient """ - try: - subdir_path = sub_directory.name - except AttributeError: - subdir_path = self.path_name + '/' + sub_directory + if isinstance(sub_directory, PurePosixPath): + subdir_path = str(sub_directory) + else: + try: + subdir_path = sub_directory.name + except AttributeError: + subdir_path = self.path_name + '/' + sub_directory _pipeline = Pipeline( transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py index ba01aaf8a16e..036837da1c38 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py @@ -4,6 +4,7 @@ # license information. # -------------------------------------------------------------------------- import functools +from pathlib import PurePosixPath try: from urllib.parse import urlparse, quote @@ -737,10 +738,13 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str :dedent: 8 :caption: Getting the directory client to interact with a specific directory. """ - try: - directory_name = directory.name - except AttributeError: - directory_name = directory + if isinstance(directory, PurePosixPath): + directory_name = str(directory) + else: + try: + directory_name = directory.name + except AttributeError: + directory_name = directory _pipeline = Pipeline( transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access policies=self._pipeline._impl_policies # pylint: disable = protected-access @@ -777,10 +781,13 @@ def get_file_client(self, file_path # type: Union[FileProperties, str] :dedent: 8 :caption: Getting the file client to interact with a specific file. """ - try: - file_path = file_path.name - except AttributeError: - pass + if isinstance(file_path, PurePosixPath): + file_path = str(file_path) + else: + try: + file_path = file_path.name + except AttributeError: + pass _pipeline = Pipeline( transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access policies=self._pipeline._impl_policies # pylint: disable = protected-access diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py index 3b399d6fd37b..216322a32ee8 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py @@ -4,6 +4,8 @@ # license information. # -------------------------------------------------------------------------- # pylint: disable=invalid-overridden-method +from pathlib import PurePosixPath + try: from urllib.parse import quote, unquote except ImportError: @@ -482,10 +484,13 @@ def get_file_client(self, file # type: Union[FileProperties, str] :dedent: 12 :caption: Getting the file client to interact with a specific file. """ - try: - file_path = file.name - except AttributeError: - file_path = self.path_name + '/' + file + if isinstance(file, PurePosixPath): + file_path = str(file) + else: + try: + file_path = file.name + except AttributeError: + file_path = self.path_name + '/' + file _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access @@ -521,10 +526,13 @@ def get_sub_directory_client(self, sub_directory # type: Union[DirectoryPropert :dedent: 12 :caption: Getting the directory client to interact with a specific directory. """ - try: - subdir_path = sub_directory.name - except AttributeError: - subdir_path = self.path_name + '/' + sub_directory + if isinstance(sub_directory, PurePosixPath): + subdir_path = str(sub_directory) + else: + try: + subdir_path = sub_directory.name + except AttributeError: + subdir_path = self.path_name + '/' + sub_directory _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py index be90fb2a92f1..2f0a695a8eef 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py @@ -7,6 +7,7 @@ # pylint: disable=invalid-overridden-method import functools +from pathlib import PurePosixPath from typing import ( # pylint: disable=unused-import Union, Optional, Any, Dict, TYPE_CHECKING ) @@ -697,10 +698,13 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str :dedent: 12 :caption: Getting the directory client to interact with a specific directory. """ - try: - directory_name = directory.name - except AttributeError: - directory_name = directory + if isinstance(directory, PurePosixPath): + directory_name = str(directory) + else: + try: + directory_name = directory.name + except AttributeError: + directory_name = directory _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access policies=self._pipeline._impl_policies # pylint: disable = protected-access @@ -738,10 +742,13 @@ def get_file_client(self, file_path # type: Union[FileProperties, str] :dedent: 12 :caption: Getting the file client to interact with a specific file. """ - try: - file_path = file_path.name - except AttributeError: - pass + if isinstance(file_path, PurePosixPath): + file_path = str(file_path) + else: + try: + file_path = file_path.name + except AttributeError: + pass _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access policies=self._pipeline._impl_policies # pylint: disable = protected-access From 08a55a6fbde57c6b35fbc051358d6f2312370315 Mon Sep 17 00:00:00 2001 From: Tamer Sherif Date: Thu, 28 Jan 2021 12:34:22 -0800 Subject: [PATCH 2/5] removed posix lib from imports --- .../storage/filedatalake/_data_lake_directory_client.py | 8 +++----- .../azure/storage/filedatalake/_file_system_client.py | 5 ++--- .../filedatalake/aio/_data_lake_directory_client_async.py | 8 +++----- .../storage/filedatalake/aio/_file_system_client_async.py | 7 +++---- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py index 337f334c63dd..1e914ce7f39c 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py @@ -3,8 +3,6 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -from pathlib import PurePosixPath - try: from urllib.parse import quote, unquote except ImportError: @@ -13,7 +11,7 @@ from ._deserialize import deserialize_dir_properties from ._shared.base_client import TransportWrapper, parse_connection_str from ._data_lake_file_client import DataLakeFileClient -from ._models import DirectoryProperties +from ._models import DirectoryProperties, FileProperties from ._path_client import PathClient @@ -506,7 +504,7 @@ def get_file_client(self, file # type: Union[FileProperties, str] :returns: A DataLakeFileClient. :rtype: ~azure.storage.filedatalake..DataLakeFileClient """ - if isinstance(file, PurePosixPath): + if not isinstance(file, FileProperties) and hasattr(file, "name"): file_path = str(file) else: try: @@ -539,7 +537,7 @@ def get_sub_directory_client(self, sub_directory # type: Union[DirectoryPropert :returns: A DataLakeDirectoryClient. :rtype: ~azure.storage.filedatalake.DataLakeDirectoryClient """ - if isinstance(sub_directory, PurePosixPath): + if not isinstance(sub_directory, DirectoryProperties) and hasattr(sub_directory, "name"): subdir_path = str(sub_directory) else: try: diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py index 036837da1c38..eaa0a3f6fa61 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py @@ -4,7 +4,6 @@ # license information. # -------------------------------------------------------------------------- import functools -from pathlib import PurePosixPath try: from urllib.parse import urlparse, quote @@ -18,7 +17,7 @@ from azure.storage.blob import ContainerClient from ._shared.base_client import TransportWrapper, StorageAccountHostsMixin, parse_query, parse_connection_str from ._serialize import convert_dfs_url_to_blob_url -from ._models import LocationMode, FileSystemProperties, PublicAccess +from ._models import LocationMode, FileSystemProperties, PublicAccess, FileProperties from ._list_paths_helper import PathPropertiesPaged from ._data_lake_file_client import DataLakeFileClient from ._data_lake_directory_client import DataLakeDirectoryClient @@ -781,7 +780,7 @@ def get_file_client(self, file_path # type: Union[FileProperties, str] :dedent: 8 :caption: Getting the file client to interact with a specific file. """ - if isinstance(file_path, PurePosixPath): + if not isinstance(file_path, FileProperties) and hasattr(file_path, "name"): file_path = str(file_path) else: try: diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py index 216322a32ee8..cf678375dcfe 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py @@ -4,8 +4,6 @@ # license information. # -------------------------------------------------------------------------- # pylint: disable=invalid-overridden-method -from pathlib import PurePosixPath - try: from urllib.parse import quote, unquote except ImportError: @@ -13,7 +11,7 @@ from azure.core.pipeline import AsyncPipeline from ._data_lake_file_client_async import DataLakeFileClient from .._data_lake_directory_client import DataLakeDirectoryClient as DataLakeDirectoryClientBase -from .._models import DirectoryProperties +from .._models import DirectoryProperties, FileProperties from .._deserialize import deserialize_dir_properties from ._path_client_async import PathClient from .._shared.base_client_async import AsyncTransportWrapper @@ -484,7 +482,7 @@ def get_file_client(self, file # type: Union[FileProperties, str] :dedent: 12 :caption: Getting the file client to interact with a specific file. """ - if isinstance(file, PurePosixPath): + if not isinstance(file, FileProperties) and hasattr(file, "name"): file_path = str(file) else: try: @@ -526,7 +524,7 @@ def get_sub_directory_client(self, sub_directory # type: Union[DirectoryPropert :dedent: 12 :caption: Getting the directory client to interact with a specific directory. """ - if isinstance(sub_directory, PurePosixPath): + if not isinstance(sub_directory, DirectoryProperties) and hasattr(sub_directory, "name"): subdir_path = str(sub_directory) else: try: diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py index 2f0a695a8eef..a4ad0cf111f4 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py @@ -7,7 +7,6 @@ # pylint: disable=invalid-overridden-method import functools -from pathlib import PurePosixPath from typing import ( # pylint: disable=unused-import Union, Optional, Any, Dict, TYPE_CHECKING ) @@ -28,7 +27,7 @@ from .._generated.aio import AzureDataLakeStorageRESTAPI from .._shared.base_client_async import AsyncTransportWrapper, AsyncStorageAccountHostsMixin from .._shared.policies_async import ExponentialRetry -from .._models import FileSystemProperties, PublicAccess +from .._models import FileSystemProperties, PublicAccess, DirectoryProperties, FileProperties if TYPE_CHECKING: from datetime import datetime @@ -698,7 +697,7 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str :dedent: 12 :caption: Getting the directory client to interact with a specific directory. """ - if isinstance(directory, PurePosixPath): + if not isinstance(directory, DirectoryProperties) and hasattr(directory, "name"): directory_name = str(directory) else: try: @@ -742,7 +741,7 @@ def get_file_client(self, file_path # type: Union[FileProperties, str] :dedent: 12 :caption: Getting the file client to interact with a specific file. """ - if isinstance(file_path, PurePosixPath): + if not isinstance(file_path, FileProperties) and hasattr(file_path, "name"): file_path = str(file_path) else: try: From 0fbce3eaf27de2014c01d218141050f9850cab61 Mon Sep 17 00:00:00 2001 From: Tamer Sherif Date: Thu, 28 Jan 2021 13:40:02 -0800 Subject: [PATCH 3/5] removed posix lib from imports --- .../azure/storage/filedatalake/_file_system_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py index eaa0a3f6fa61..e9ccddaa1e44 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py @@ -17,7 +17,7 @@ from azure.storage.blob import ContainerClient from ._shared.base_client import TransportWrapper, StorageAccountHostsMixin, parse_query, parse_connection_str from ._serialize import convert_dfs_url_to_blob_url -from ._models import LocationMode, FileSystemProperties, PublicAccess, FileProperties +from ._models import LocationMode, FileSystemProperties, PublicAccess, FileProperties, DirectoryProperties from ._list_paths_helper import PathPropertiesPaged from ._data_lake_file_client import DataLakeFileClient from ._data_lake_directory_client import DataLakeDirectoryClient @@ -737,7 +737,7 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str :dedent: 8 :caption: Getting the directory client to interact with a specific directory. """ - if isinstance(directory, PurePosixPath): + if not isinstance(directory, DirectoryProperties) and hasattr(directory, "name"): directory_name = str(directory) else: try: From a646c45327684dd4f1f4c00b539b064288bcaa4c Mon Sep 17 00:00:00 2001 From: Tamer Sherif Date: Thu, 28 Jan 2021 13:50:04 -0800 Subject: [PATCH 4/5] added type annotations --- .../storage/filedatalake/_data_lake_directory_client.py | 8 ++++---- .../azure/storage/filedatalake/_file_system_client.py | 8 ++++---- .../filedatalake/aio/_data_lake_directory_client_async.py | 8 ++++---- .../storage/filedatalake/aio/_file_system_client_async.py | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py index 1e914ce7f39c..2c55cfe51027 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py @@ -490,7 +490,7 @@ def create_file(self, file, # type: Union[FileProperties, str] file_client.create_file(**kwargs) return file_client - def get_file_client(self, file # type: Union[FileProperties, str] + def get_file_client(self, file # type: Union[FileProperties, str, PurePosixPath] ): # type: (...) -> DataLakeFileClient """Get a client to interact with the specified file. @@ -500,7 +500,7 @@ def get_file_client(self, file # type: Union[FileProperties, str] :param file: The file with which to interact. This can either be the name of the file, or an instance of FileProperties. eg. directory/subdirectory/file - :type file: str or ~azure.storage.filedatalake.FileProperties + :type file: str or ~azure.storage.filedatalake.FileProperties or a PurePosixPath :returns: A DataLakeFileClient. :rtype: ~azure.storage.filedatalake..DataLakeFileClient """ @@ -523,7 +523,7 @@ def get_file_client(self, file # type: Union[FileProperties, str] key_encryption_key=self.key_encryption_key, key_resolver_function=self.key_resolver_function) - def get_sub_directory_client(self, sub_directory # type: Union[DirectoryProperties, str] + def get_sub_directory_client(self, sub_directory # type: Union[DirectoryProperties, str, PurePosixPath] ): # type: (...) -> DataLakeDirectoryClient """Get a client to interact with the specified subdirectory of the current directory. @@ -533,7 +533,7 @@ def get_sub_directory_client(self, sub_directory # type: Union[DirectoryPropert :param sub_directory: The directory with which to interact. This can either be the name of the directory, or an instance of DirectoryProperties. - :type sub_directory: str or ~azure.storage.filedatalake.DirectoryProperties + :type sub_directory: str or ~azure.storage.filedatalake.DirectoryProperties or a PurePosixPath :returns: A DataLakeDirectoryClient. :rtype: ~azure.storage.filedatalake.DataLakeDirectoryClient """ diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py index e9ccddaa1e44..e6838dd7fd54 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py @@ -714,7 +714,7 @@ def _get_root_directory_client(self): """ return self.get_directory_client('/') - def get_directory_client(self, directory # type: Union[DirectoryProperties, str] + def get_directory_client(self, directory # type: Union[DirectoryProperties, str, PurePosixPath] ): # type: (...) -> DataLakeDirectoryClient """Get a client to interact with the specified directory. @@ -723,7 +723,7 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str :param directory: The directory with which to interact. This can either be the name of the directory, - or an instance of DirectoryProperties. + or an instance of DirectoryProperties or a PurePosixPath. :type directory: str or ~azure.storage.filedatalake.DirectoryProperties :returns: A DataLakeDirectoryClient. :rtype: ~azure.storage.filedatalake.DataLakeDirectoryClient @@ -757,7 +757,7 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str key_resolver_function=self.key_resolver_function ) - def get_file_client(self, file_path # type: Union[FileProperties, str] + def get_file_client(self, file_path # type: Union[FileProperties, str, PurePosixPath] ): # type: (...) -> DataLakeFileClient """Get a client to interact with the specified file. @@ -767,7 +767,7 @@ def get_file_client(self, file_path # type: Union[FileProperties, str] :param file_path: The file with which to interact. This can either be the path of the file(from root directory), or an instance of FileProperties. eg. directory/subdirectory/file - :type file_path: str or ~azure.storage.filedatalake.FileProperties + :type file_path: str or ~azure.storage.filedatalake.FileProperties or a PurePosixPath :returns: A DataLakeFileClient. :rtype: ~azure.storage.filedatalake..DataLakeFileClient diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py index cf678375dcfe..b1aa3975285c 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py @@ -459,7 +459,7 @@ async def create_file(self, file, # type: Union[FileProperties, str] await file_client.create_file(**kwargs) return file_client - def get_file_client(self, file # type: Union[FileProperties, str] + def get_file_client(self, file # type: Union[FileProperties, str, PurePosixPath] ): # type: (...) -> DataLakeFileClient """Get a client to interact with the specified file. @@ -469,7 +469,7 @@ def get_file_client(self, file # type: Union[FileProperties, str] :param file: The file with which to interact. This can either be the name of the file, or an instance of FileProperties. eg. directory/subdirectory/file - :type file: str or ~azure.storage.filedatalake.FileProperties + :type file: str or ~azure.storage.filedatalake.FileProperties or PurePosixPath :returns: A DataLakeFileClient. :rtype: ~azure.storage.filedatalake.aio.DataLakeFileClient @@ -501,7 +501,7 @@ def get_file_client(self, file # type: Union[FileProperties, str] key_encryption_key=self.key_encryption_key, key_resolver_function=self.key_resolver_function) - def get_sub_directory_client(self, sub_directory # type: Union[DirectoryProperties, str] + def get_sub_directory_client(self, sub_directory # type: Union[DirectoryProperties, str, PurePosixPath] ): # type: (...) -> DataLakeDirectoryClient """Get a client to interact with the specified subdirectory of the current directory. @@ -511,7 +511,7 @@ def get_sub_directory_client(self, sub_directory # type: Union[DirectoryPropert :param sub_directory: The directory with which to interact. This can either be the name of the directory, or an instance of DirectoryProperties. - :type sub_directory: str or ~azure.storage.filedatalake.DirectoryProperties + :type sub_directory: str or ~azure.storage.filedatalake.DirectoryProperties or a PurePosixPath :returns: A DataLakeDirectoryClient. :rtype: ~azure.storage.filedatalake.aio.DataLakeDirectoryClient diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py index a4ad0cf111f4..d5a955b807c6 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py @@ -674,7 +674,7 @@ def _get_root_directory_client(self): """ return self.get_directory_client('/') - def get_directory_client(self, directory # type: Union[DirectoryProperties, str] + def get_directory_client(self, directory # type: Union[DirectoryProperties, str, PurePosixPath] ): # type: (...) -> DataLakeDirectoryClient """Get a client to interact with the specified directory. @@ -684,7 +684,7 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str :param directory: The directory with which to interact. This can either be the name of the directory, or an instance of DirectoryProperties. - :type directory: str or ~azure.storage.filedatalake.DirectoryProperties + :type directory: str or ~azure.storage.filedatalake.DirectoryProperties or a PurePosixPath :returns: A DataLakeDirectoryClient. :rtype: ~azure.storage.filedatalake.aio.DataLakeDirectoryClient @@ -718,7 +718,7 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str loop=self._loop ) - def get_file_client(self, file_path # type: Union[FileProperties, str] + def get_file_client(self, file_path # type: Union[FileProperties, str, PurePosixPath] ): # type: (...) -> DataLakeFileClient """Get a client to interact with the specified file. @@ -728,7 +728,7 @@ def get_file_client(self, file_path # type: Union[FileProperties, str] :param file_path: The file with which to interact. This can either be the path of the file(from root directory), or an instance of FileProperties. eg. directory/subdirectory/file - :type file_path: str or ~azure.storage.filedatalake.FileProperties + :type file_path: str or ~azure.storage.filedatalake.FileProperties or a PurePosixPath :returns: A DataLakeFileClient. :rtype: ~azure.storage.filedatalake.aio.DataLakeFileClient From 7b2214535ee0a173d2c50096faf05596d89a7b53 Mon Sep 17 00:00:00 2001 From: Tamer Sherif Date: Mon, 1 Feb 2021 09:49:30 -0800 Subject: [PATCH 5/5] cleaned up changes --- .../_data_lake_directory_client.py | 32 ++++++++----------- .../filedatalake/_file_system_client.py | 26 ++++++--------- .../aio/_data_lake_directory_client_async.py | 30 +++++++---------- .../aio/_file_system_client_async.py | 26 ++++++--------- 4 files changed, 45 insertions(+), 69 deletions(-) diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py index 2c55cfe51027..b46c43d761b4 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py @@ -490,7 +490,7 @@ def create_file(self, file, # type: Union[FileProperties, str] file_client.create_file(**kwargs) return file_client - def get_file_client(self, file # type: Union[FileProperties, str, PurePosixPath] + def get_file_client(self, file # type: Union[FileProperties, str] ): # type: (...) -> DataLakeFileClient """Get a client to interact with the specified file. @@ -500,17 +500,14 @@ def get_file_client(self, file # type: Union[FileProperties, str, PurePosixPath :param file: The file with which to interact. This can either be the name of the file, or an instance of FileProperties. eg. directory/subdirectory/file - :type file: str or ~azure.storage.filedatalake.FileProperties or a PurePosixPath + :type file: str or ~azure.storage.filedatalake.FileProperties :returns: A DataLakeFileClient. - :rtype: ~azure.storage.filedatalake..DataLakeFileClient + :rtype: ~azure.storage.filedatalake.DataLakeFileClient """ - if not isinstance(file, FileProperties) and hasattr(file, "name"): - file_path = str(file) - else: - try: - file_path = file.name - except AttributeError: - file_path = self.path_name + '/' + file + try: + file_path = file.get('name') + except AttributeError: + file_path = self.path_name + '/' + str(file) _pipeline = Pipeline( transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access @@ -523,7 +520,7 @@ def get_file_client(self, file # type: Union[FileProperties, str, PurePosixPath key_encryption_key=self.key_encryption_key, key_resolver_function=self.key_resolver_function) - def get_sub_directory_client(self, sub_directory # type: Union[DirectoryProperties, str, PurePosixPath] + def get_sub_directory_client(self, sub_directory # type: Union[DirectoryProperties, str] ): # type: (...) -> DataLakeDirectoryClient """Get a client to interact with the specified subdirectory of the current directory. @@ -533,17 +530,14 @@ def get_sub_directory_client(self, sub_directory # type: Union[DirectoryPropert :param sub_directory: The directory with which to interact. This can either be the name of the directory, or an instance of DirectoryProperties. - :type sub_directory: str or ~azure.storage.filedatalake.DirectoryProperties or a PurePosixPath + :type sub_directory: str or ~azure.storage.filedatalake.DirectoryProperties :returns: A DataLakeDirectoryClient. :rtype: ~azure.storage.filedatalake.DataLakeDirectoryClient """ - if not isinstance(sub_directory, DirectoryProperties) and hasattr(sub_directory, "name"): - subdir_path = str(sub_directory) - else: - try: - subdir_path = sub_directory.name - except AttributeError: - subdir_path = self.path_name + '/' + sub_directory + try: + subdir_path = sub_directory.get('name') + except AttributeError: + subdir_path = self.path_name + '/' + str(sub_directory) _pipeline = Pipeline( transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py index e6838dd7fd54..e559ccadb2a0 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py @@ -714,7 +714,7 @@ def _get_root_directory_client(self): """ return self.get_directory_client('/') - def get_directory_client(self, directory # type: Union[DirectoryProperties, str, PurePosixPath] + def get_directory_client(self, directory # type: Union[DirectoryProperties, str] ): # type: (...) -> DataLakeDirectoryClient """Get a client to interact with the specified directory. @@ -723,7 +723,7 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str :param directory: The directory with which to interact. This can either be the name of the directory, - or an instance of DirectoryProperties or a PurePosixPath. + or an instance of DirectoryProperties. :type directory: str or ~azure.storage.filedatalake.DirectoryProperties :returns: A DataLakeDirectoryClient. :rtype: ~azure.storage.filedatalake.DataLakeDirectoryClient @@ -737,13 +737,10 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str :dedent: 8 :caption: Getting the directory client to interact with a specific directory. """ - if not isinstance(directory, DirectoryProperties) and hasattr(directory, "name"): + try: + directory_name = directory.get('name') + except AttributeError: directory_name = str(directory) - else: - try: - directory_name = directory.name - except AttributeError: - directory_name = directory _pipeline = Pipeline( transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access policies=self._pipeline._impl_policies # pylint: disable = protected-access @@ -757,7 +754,7 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str key_resolver_function=self.key_resolver_function ) - def get_file_client(self, file_path # type: Union[FileProperties, str, PurePosixPath] + def get_file_client(self, file_path # type: Union[FileProperties, str] ): # type: (...) -> DataLakeFileClient """Get a client to interact with the specified file. @@ -767,7 +764,7 @@ def get_file_client(self, file_path # type: Union[FileProperties, str, PurePosi :param file_path: The file with which to interact. This can either be the path of the file(from root directory), or an instance of FileProperties. eg. directory/subdirectory/file - :type file_path: str or ~azure.storage.filedatalake.FileProperties or a PurePosixPath + :type file_path: str or ~azure.storage.filedatalake.FileProperties :returns: A DataLakeFileClient. :rtype: ~azure.storage.filedatalake..DataLakeFileClient @@ -780,13 +777,10 @@ def get_file_client(self, file_path # type: Union[FileProperties, str, PurePosi :dedent: 8 :caption: Getting the file client to interact with a specific file. """ - if not isinstance(file_path, FileProperties) and hasattr(file_path, "name"): + try: + file_path = file_path.get('name') + except AttributeError: file_path = str(file_path) - else: - try: - file_path = file_path.name - except AttributeError: - pass _pipeline = Pipeline( transport=TransportWrapper(self._pipeline._transport), # pylint: disable = protected-access policies=self._pipeline._impl_policies # pylint: disable = protected-access diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py index b1aa3975285c..23b26feea82c 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py @@ -459,7 +459,7 @@ async def create_file(self, file, # type: Union[FileProperties, str] await file_client.create_file(**kwargs) return file_client - def get_file_client(self, file # type: Union[FileProperties, str, PurePosixPath] + def get_file_client(self, file # type: Union[FileProperties, str] ): # type: (...) -> DataLakeFileClient """Get a client to interact with the specified file. @@ -469,7 +469,7 @@ def get_file_client(self, file # type: Union[FileProperties, str, PurePosixPath :param file: The file with which to interact. This can either be the name of the file, or an instance of FileProperties. eg. directory/subdirectory/file - :type file: str or ~azure.storage.filedatalake.FileProperties or PurePosixPath + :type file: str or ~azure.storage.filedatalake.FileProperties :returns: A DataLakeFileClient. :rtype: ~azure.storage.filedatalake.aio.DataLakeFileClient @@ -482,13 +482,10 @@ def get_file_client(self, file # type: Union[FileProperties, str, PurePosixPath :dedent: 12 :caption: Getting the file client to interact with a specific file. """ - if not isinstance(file, FileProperties) and hasattr(file, "name"): - file_path = str(file) - else: - try: - file_path = file.name - except AttributeError: - file_path = self.path_name + '/' + file + try: + file_path = file.get('name') + except AttributeError: + file_path = self.path_name + '/' + str(file) _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access @@ -501,7 +498,7 @@ def get_file_client(self, file # type: Union[FileProperties, str, PurePosixPath key_encryption_key=self.key_encryption_key, key_resolver_function=self.key_resolver_function) - def get_sub_directory_client(self, sub_directory # type: Union[DirectoryProperties, str, PurePosixPath] + def get_sub_directory_client(self, sub_directory # type: Union[DirectoryProperties, str] ): # type: (...) -> DataLakeDirectoryClient """Get a client to interact with the specified subdirectory of the current directory. @@ -511,7 +508,7 @@ def get_sub_directory_client(self, sub_directory # type: Union[DirectoryPropert :param sub_directory: The directory with which to interact. This can either be the name of the directory, or an instance of DirectoryProperties. - :type sub_directory: str or ~azure.storage.filedatalake.DirectoryProperties or a PurePosixPath + :type sub_directory: str or ~azure.storage.filedatalake.DirectoryProperties :returns: A DataLakeDirectoryClient. :rtype: ~azure.storage.filedatalake.aio.DataLakeDirectoryClient @@ -524,13 +521,10 @@ def get_sub_directory_client(self, sub_directory # type: Union[DirectoryPropert :dedent: 12 :caption: Getting the directory client to interact with a specific directory. """ - if not isinstance(sub_directory, DirectoryProperties) and hasattr(sub_directory, "name"): - subdir_path = str(sub_directory) - else: - try: - subdir_path = sub_directory.name - except AttributeError: - subdir_path = self.path_name + '/' + sub_directory + try: + subdir_path = sub_directory.get('name') + except AttributeError: + subdir_path = self.path_name + '/' + str(sub_directory) _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access diff --git a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py index d5a955b807c6..3c375a5a8ab2 100644 --- a/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_file_system_client_async.py @@ -674,7 +674,7 @@ def _get_root_directory_client(self): """ return self.get_directory_client('/') - def get_directory_client(self, directory # type: Union[DirectoryProperties, str, PurePosixPath] + def get_directory_client(self, directory # type: Union[DirectoryProperties, str] ): # type: (...) -> DataLakeDirectoryClient """Get a client to interact with the specified directory. @@ -684,7 +684,7 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str :param directory: The directory with which to interact. This can either be the name of the directory, or an instance of DirectoryProperties. - :type directory: str or ~azure.storage.filedatalake.DirectoryProperties or a PurePosixPath + :type directory: str or ~azure.storage.filedatalake.DirectoryProperties :returns: A DataLakeDirectoryClient. :rtype: ~azure.storage.filedatalake.aio.DataLakeDirectoryClient @@ -697,13 +697,10 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str :dedent: 12 :caption: Getting the directory client to interact with a specific directory. """ - if not isinstance(directory, DirectoryProperties) and hasattr(directory, "name"): + try: + directory_name = directory.get('name') + except AttributeError: directory_name = str(directory) - else: - try: - directory_name = directory.name - except AttributeError: - directory_name = directory _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access policies=self._pipeline._impl_policies # pylint: disable = protected-access @@ -718,7 +715,7 @@ def get_directory_client(self, directory # type: Union[DirectoryProperties, str loop=self._loop ) - def get_file_client(self, file_path # type: Union[FileProperties, str, PurePosixPath] + def get_file_client(self, file_path # type: Union[FileProperties, str] ): # type: (...) -> DataLakeFileClient """Get a client to interact with the specified file. @@ -728,7 +725,7 @@ def get_file_client(self, file_path # type: Union[FileProperties, str, PurePosi :param file_path: The file with which to interact. This can either be the path of the file(from root directory), or an instance of FileProperties. eg. directory/subdirectory/file - :type file_path: str or ~azure.storage.filedatalake.FileProperties or a PurePosixPath + :type file_path: str or ~azure.storage.filedatalake.FileProperties :returns: A DataLakeFileClient. :rtype: ~azure.storage.filedatalake.aio.DataLakeFileClient @@ -741,13 +738,10 @@ def get_file_client(self, file_path # type: Union[FileProperties, str, PurePosi :dedent: 12 :caption: Getting the file client to interact with a specific file. """ - if not isinstance(file_path, FileProperties) and hasattr(file_path, "name"): + try: + file_path = file_path.get('name') + except AttributeError: file_path = str(file_path) - else: - try: - file_path = file_path.name - except AttributeError: - pass _pipeline = AsyncPipeline( transport=AsyncTransportWrapper(self._pipeline._transport), # pylint: disable = protected-access policies=self._pipeline._impl_policies # pylint: disable = protected-access