Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sdk/storage/azure-storage-file/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,20 @@ 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, account_url, # type: str
share_name, # type: str
directory_path, # type: 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add :keyword loop: to docstring?

super(DirectoryClient, self).__init__(
account_url,
share_name=share_name,
Expand Down Expand Up @@ -142,18 +144,14 @@ def get_subdirectory_client(self, directory_name, **kwargs):
_pipeline=self._pipeline, _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)
Expand All @@ -167,6 +165,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:
Expand All @@ -179,12 +179,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

Expand All @@ -197,20 +197,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]
Expand All @@ -224,6 +225,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,
Expand All @@ -235,18 +237,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) -> AsyncItemPaged
def list_handles(self, recursive=False, **kwargs):
# type: (bool, 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,
Expand All @@ -262,7 +265,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: (...) -> int
Expand All @@ -275,11 +277,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: The number of file handles that were closed.
:rtype: int
"""
timeout = kwargs.pop('timeout', None)
try:
handle_id = handle.id # type: ignore
except AttributeError:
Expand All @@ -305,17 +308,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,
Expand All @@ -326,8 +330,8 @@ 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
# type: (Dict[str, Any], Optional[int], Any) -> Dict[str, Any]
async 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
Expand All @@ -337,11 +341,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:
Expand All @@ -359,12 +364,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.
Expand All @@ -391,6 +395,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
Expand All @@ -408,8 +413,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
Expand All @@ -418,10 +421,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
Expand All @@ -435,22 +438,23 @@ 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

@distributed_trace_async
async def delete_subdirectory(
self, directory_name, # type: str
timeout=None, # type: Optional[int]
**kwargs
):
# type: (...) -> None
"""Deletes a 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

Expand All @@ -463,6 +467,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)

Expand All @@ -471,12 +476,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
Expand All @@ -489,23 +488,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.
:param int timeout:
:keyword int timeout:
The timeout parameter is expressed in seconds.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to change metadata, content_settings, validate_content, max_concurrency, and encoding to :keyword: as well.

:param str encoding:
:keyword str encoding:
Defaults to UTF-8.
:returns: FileClient
:rtype: ~azure.storage.file.aio.file_client_async.FileClient
Expand All @@ -523,19 +522,12 @@ async def upload_file(
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

@distributed_trace_async
async def delete_file(
self, file_name, # type: str
timeout=None, # type: Optional[int]
**kwargs # type: Optional[Any]
):
# type: (...) -> None
Expand All @@ -544,7 +536,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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're keeping this timeout as a param.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, was this one just missed being put into kwargs?

:rtype: None

Expand All @@ -558,4 +550,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(**kwargs)
Loading