7
7
8
8
import functools
9
9
from typing import (
10
- Any , Dict , Optional , Union ,
10
+ Any , cast , Dict , Optional , Union ,
11
11
TYPE_CHECKING
12
12
)
13
13
from urllib .parse import quote , unquote
14
-
15
14
from typing_extensions import Self
16
15
17
16
from azure .core .paging import ItemPaged
23
22
from ._list_paths_helper import PathPropertiesPaged
24
23
from ._models import DirectoryProperties , FileProperties
25
24
from ._path_client import PathClient
26
- from ._shared .base_client import TransportWrapper , parse_connection_str
25
+ from ._path_client_helpers import _parse_rename_path
26
+ from ._shared .base_client import parse_connection_str , TransportWrapper
27
27
28
28
if TYPE_CHECKING :
29
29
from azure .core .credentials import AzureNamedKeyCredential , AzureSasCredential , TokenCredential
@@ -37,12 +37,6 @@ class DataLakeDirectoryClient(PathClient):
37
37
For operations relating to a specific subdirectory or file under the directory, a directory client or file client
38
38
can be retrieved using the :func:`~get_sub_directory_client` or :func:`~get_file_client` functions.
39
39
40
- :ivar str url:
41
- The full endpoint URL to the file system, including SAS token if used.
42
- :ivar str primary_endpoint:
43
- The full primary endpoint URL.
44
- :ivar str primary_hostname:
45
- The hostname of the primary endpoint.
46
40
:param str account_url:
47
41
The URI to the storage account.
48
42
:param file_system_name:
@@ -64,7 +58,7 @@ class DataLakeDirectoryClient(PathClient):
64
58
~azure.core.credentials.AzureNamedKeyCredential or
65
59
~azure.core.credentials.AzureSasCredential or
66
60
~azure.core.credentials.TokenCredential or
67
- str or dict [str, str] or None
61
+ str or Dict [str, str] or None
68
62
:keyword str api_version:
69
63
The Storage API version to use for requests. Default value is the most recent service version that is
70
64
compatible with the current SDK. Setting to an older version may result in reduced feature compatibility.
@@ -81,6 +75,14 @@ class DataLakeDirectoryClient(PathClient):
81
75
:dedent: 4
82
76
:caption: Creating the DataLakeServiceClient from connection string.
83
77
"""
78
+
79
+ url : str
80
+ """The full endpoint URL to the file system, including SAS token if used."""
81
+ primary_endpoint : str
82
+ """The full primary endpoint URL."""
83
+ primary_hostname : str
84
+ """The hostname of the primary endpoint."""
85
+
84
86
def __init__ (
85
87
self , account_url : str ,
86
88
file_system_name : str ,
@@ -93,12 +95,12 @@ def __init__(
93
95
94
96
@classmethod
95
97
def from_connection_string (
96
- cls , conn_str : str ,
97
- file_system_name : str ,
98
- directory_name : str ,
99
- credential : Optional [Union [str , Dict [str , str ], "AzureNamedKeyCredential" , "AzureSasCredential" , "TokenCredential" ]] = None , # pylint: disable=line-too-long
100
- ** kwargs : Any
101
- ) -> Self :
98
+ cls , conn_str : str ,
99
+ file_system_name : str ,
100
+ directory_name : str ,
101
+ credential : Optional [Union [str , Dict [str , str ], "AzureNamedKeyCredential" , "AzureSasCredential" , "TokenCredential" ]] = None , # pylint: disable=line-too-long
102
+ ** kwargs : Any
103
+ ) -> Self :
102
104
"""
103
105
Create DataLakeDirectoryClient from a Connection String.
104
106
@@ -120,7 +122,7 @@ def from_connection_string(
120
122
~azure.core.credentials.AzureNamedKeyCredential or
121
123
~azure.core.credentials.AzureSasCredential or
122
124
~azure.core.credentials.TokenCredential or
123
- str or dict [str, str] or None
125
+ str or Dict [str, str] or None
124
126
:param directory_name:
125
127
The name of directory to interact with. The directory is under file system.
126
128
:type directory_name: str
@@ -136,15 +138,16 @@ def from_connection_string(
136
138
credential = credential , ** kwargs )
137
139
138
140
@distributed_trace
139
- def create_directory (self , metadata = None , # type: Optional[Dict[str, str]]
140
- ** kwargs ):
141
- # type: (...) -> Dict[str, Union[str, datetime]]
141
+ def create_directory (
142
+ self , metadata : Optional [Dict [str , str ]] = None ,
143
+ ** kwargs : Any
144
+ ) -> Dict [str , Union [str , "datetime" ]]:
142
145
"""
143
146
Create a new directory.
144
147
145
148
:param metadata:
146
149
Name-value pairs associated with the file as metadata.
147
- :type metadata: dict( str, str)
150
+ :type metadata: Dict[ str, str]
148
151
:keyword ~azure.storage.filedatalake.ContentSettings content_settings:
149
152
ContentSettings object used to set path properties.
150
153
:keyword lease:
@@ -210,7 +213,7 @@ def create_directory(self, metadata=None, # type: Optional[Dict[str, str]]
210
213
see `here <https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-file-datalake
211
214
#other-client--per-operation-configuration>`_.
212
215
:return: A dictionary of response headers.
213
- :rtype: dict [str, Union[str, datetime]]
216
+ :rtype: Dict [str, Union[str, ~datetime. datetime]]
214
217
215
218
.. admonition:: Example:
216
219
@@ -224,8 +227,7 @@ def create_directory(self, metadata=None, # type: Optional[Dict[str, str]]
224
227
return self ._create ('directory' , metadata = metadata , ** kwargs )
225
228
226
229
@distributed_trace
227
- def delete_directory (self , ** kwargs ):
228
- # type: (...) -> None
230
+ def delete_directory (self , ** kwargs : Any ) -> Dict [str , Any ]: # pylint: disable=delete-operation-wrong-return-type
229
231
"""
230
232
Marks the specified directory for deletion.
231
233
@@ -256,8 +258,8 @@ def delete_directory(self, **kwargs):
256
258
This value is not tracked or validated on the client. To configure client-side network timesouts
257
259
see `here <https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-file-datalake
258
260
#other-client--per-operation-configuration>`_.
259
- :returns: None .
260
- :rtype: None
261
+ :returns: A dictionary of response headers .
262
+ :rtype: Dict[str, Any]
261
263
262
264
.. admonition:: Example:
263
265
@@ -271,8 +273,7 @@ def delete_directory(self, **kwargs):
271
273
return self ._delete (recursive = True , ** kwargs )
272
274
273
275
@distributed_trace
274
- def get_directory_properties (self , ** kwargs ):
275
- # type: (**Any) -> DirectoryProperties
276
+ def get_directory_properties (self , ** kwargs : Any ) -> DirectoryProperties :
276
277
"""Returns all user-defined metadata, standard HTTP properties, and
277
278
system properties for the directory. It does not return the content of the directory.
278
279
@@ -333,11 +334,10 @@ def get_directory_properties(self, **kwargs):
333
334
headers = kwargs .pop ('headers' , {})
334
335
headers ['x-ms-upn' ] = str (upn )
335
336
kwargs ['headers' ] = headers
336
- return self ._get_path_properties (cls = deserialize_dir_properties , ** kwargs )
337
+ return cast ( DirectoryProperties , self ._get_path_properties (cls = deserialize_dir_properties , ** kwargs ) )
337
338
338
339
@distributed_trace
339
- def exists (self , ** kwargs ):
340
- # type: (**Any) -> bool
340
+ def exists (self , ** kwargs : Any ) -> bool :
341
341
"""
342
342
Returns True if a directory exists and returns False otherwise.
343
343
@@ -353,8 +353,7 @@ def exists(self, **kwargs):
353
353
return self ._exists (** kwargs )
354
354
355
355
@distributed_trace
356
- def rename_directory (self , new_name , ** kwargs ):
357
- # type: (str, **Any) -> DataLakeDirectoryClient
356
+ def rename_directory (self , new_name : str , ** kwargs : Any ) -> "DataLakeDirectoryClient" :
358
357
"""
359
358
Rename the source directory.
360
359
@@ -422,7 +421,8 @@ def rename_directory(self, new_name, **kwargs):
422
421
:dedent: 4
423
422
:caption: Rename the source directory.
424
423
"""
425
- new_file_system , new_path , new_dir_sas = self ._parse_rename_path (new_name )
424
+ new_file_system , new_path , new_dir_sas = _parse_rename_path (
425
+ new_name , self .file_system_name , self ._query_str , self ._raw_credential )
426
426
427
427
new_directory_client = DataLakeDirectoryClient (
428
428
f"{ self .scheme } ://{ self .primary_hostname } " , new_file_system , directory_name = new_path ,
@@ -433,10 +433,11 @@ def rename_directory(self, new_name, **kwargs):
433
433
return new_directory_client
434
434
435
435
@distributed_trace
436
- def create_sub_directory (self , sub_directory , # type: Union[DirectoryProperties, str]
437
- metadata = None , # type: Optional[Dict[str, str]]
438
- ** kwargs ):
439
- # type: (...) -> DataLakeDirectoryClient
436
+ def create_sub_directory (
437
+ self , sub_directory : Union [DirectoryProperties , str ],
438
+ metadata : Optional [Dict [str , str ]] = None ,
439
+ ** kwargs : Any
440
+ ) -> "DataLakeDirectoryClient" :
440
441
"""
441
442
Create a subdirectory and return the subdirectory client to be interacted with.
442
443
@@ -446,7 +447,7 @@ def create_sub_directory(self, sub_directory, # type: Union[DirectoryProperties
446
447
:type sub_directory: str or ~azure.storage.filedatalake.DirectoryProperties
447
448
:param metadata:
448
449
Name-value pairs associated with the file as metadata.
449
- :type metadata: dict( str, str)
450
+ :type metadata: Dict[ str, str]
450
451
:keyword ~azure.storage.filedatalake.ContentSettings content_settings:
451
452
ContentSettings object used to set path properties.
452
453
:keyword lease:
@@ -519,9 +520,10 @@ def create_sub_directory(self, sub_directory, # type: Union[DirectoryProperties
519
520
return subdir
520
521
521
522
@distributed_trace
522
- def delete_sub_directory (self , sub_directory , # type: Union[DirectoryProperties, str]
523
- ** kwargs ):
524
- # type: (...) -> DataLakeDirectoryClient
523
+ def delete_sub_directory ( # pylint: disable=delete-operation-wrong-return-type
524
+ self , sub_directory : Union [DirectoryProperties , str ],
525
+ ** kwargs : Any
526
+ ) -> "DataLakeDirectoryClient" :
525
527
"""
526
528
Marks the specified subdirectory for deletion.
527
529
@@ -564,9 +566,7 @@ def delete_sub_directory(self, sub_directory, # type: Union[DirectoryProperties
564
566
return subdir
565
567
566
568
@distributed_trace
567
- def create_file (self , file , # type: Union[FileProperties, str]
568
- ** kwargs ):
569
- # type: (...) -> DataLakeFileClient
569
+ def create_file (self , file : Union [FileProperties , str ], ** kwargs : Any ) -> DataLakeFileClient :
570
570
"""
571
571
Create a new file and return the file client to be interacted with.
572
572
@@ -578,7 +578,7 @@ def create_file(self, file, # type: Union[FileProperties, str]
578
578
ContentSettings object used to set path properties.
579
579
:keyword metadata:
580
580
Name-value pairs associated with the file as metadata.
581
- :type metadata: dict( str, str)
581
+ :type metadata: Dict[ str, str]
582
582
:keyword lease:
583
583
Required if the file has an active lease. Value can be a DataLakeLeaseClient object
584
584
or the lease ID as a string.
@@ -688,7 +688,6 @@ def get_paths(
688
688
:returns: An iterable (auto-paging) response of PathProperties.
689
689
:rtype: ~azure.core.paging.ItemPaged[~azure.storage.filedatalake.PathProperties]
690
690
"""
691
- timeout = kwargs .pop ('timeout' , None )
692
691
hostname = self ._hosts [self ._location_mode ]
693
692
url = f"{ self .scheme } ://{ hostname } /{ quote (self .file_system_name )} "
694
693
client = self ._build_generated_client (url )
@@ -702,9 +701,7 @@ def get_paths(
702
701
command , recursive , path = self .path_name , max_results = max_results ,
703
702
upn = upn , page_iterator_class = PathPropertiesPaged , ** kwargs )
704
703
705
- def get_file_client (self , file # type: Union[FileProperties, str]
706
- ):
707
- # type: (...) -> DataLakeFileClient
704
+ def get_file_client (self , file : Union [FileProperties , str ]) -> DataLakeFileClient :
708
705
"""Get a client to interact with the specified file.
709
706
710
707
The file need not already exist.
@@ -716,9 +713,9 @@ def get_file_client(self, file # type: Union[FileProperties, str]
716
713
:returns: A DataLakeFileClient.
717
714
:rtype: ~azure.storage.filedatalake.DataLakeFileClient
718
715
"""
719
- try :
716
+ if isinstance ( file , FileProperties ) :
720
717
file_path = file .get ('name' )
721
- except AttributeError :
718
+ else :
722
719
file_path = self .path_name + '/' + str (file )
723
720
724
721
_pipeline = Pipeline (
@@ -730,9 +727,7 @@ def get_file_client(self, file # type: Union[FileProperties, str]
730
727
api_version = self .api_version ,
731
728
_hosts = self ._hosts , _configuration = self ._config , _pipeline = _pipeline )
732
729
733
- def get_sub_directory_client (self , sub_directory # type: Union[DirectoryProperties, str]
734
- ):
735
- # type: (...) -> DataLakeDirectoryClient
730
+ def get_sub_directory_client (self , sub_directory : Union [DirectoryProperties , str ]) -> "DataLakeDirectoryClient" :
736
731
"""Get a client to interact with the specified subdirectory of the current directory.
737
732
738
733
The sub subdirectory need not already exist.
@@ -744,14 +739,14 @@ def get_sub_directory_client(self, sub_directory # type: Union[DirectoryPropert
744
739
:returns: A DataLakeDirectoryClient.
745
740
:rtype: ~azure.storage.filedatalake.DataLakeDirectoryClient
746
741
"""
747
- try :
742
+ if isinstance ( sub_directory , DirectoryProperties ) :
748
743
subdir_path = sub_directory .get ('name' )
749
- except AttributeError :
744
+ else :
750
745
subdir_path = self .path_name + '/' + str (sub_directory )
751
746
752
747
_pipeline = Pipeline (
753
- transport = TransportWrapper (self ._pipeline ._transport ), # pylint: disable = protected-access
754
- policies = self ._pipeline ._impl_policies # pylint: disable = protected-access
748
+ transport = TransportWrapper (self ._pipeline ._transport ), # pylint: disable= protected-access
749
+ policies = self ._pipeline ._impl_policies # pylint: disable= protected-access
755
750
)
756
751
return DataLakeDirectoryClient (
757
752
self .url , self .file_system_name , directory_name = subdir_path , credential = self ._raw_credential ,
0 commit comments