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
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-blob/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/storage/azure-storage-blob",
"Tag": "python/storage/azure-storage-blob_89c4f2856e"
"Tag": "python/storage/azure-storage-blob_bd8f6233a4"
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class BlobClient(StorageAccountHostsMixin, StorageEncryptionMixin):
legal_hold: Optional[bool] = None,
standard_blob_tier: Optional[StandardBlobTier] = None,
maxsize_condition: Optional[int] = None,
max_concurrency: int = 1,
max_concurrency: Optional[int] = None,
cpk: Optional[CustomerProvidedEncryptionKey] = None,
encryption_scope: Optional[str] = None,
encoding: str = "UTF-8",
Expand All @@ -208,7 +208,7 @@ class BlobClient(StorageAccountHostsMixin, StorageEncryptionMixin):
match_condition: Optional[MatchConditions] = None,
if_tags_match_condition: Optional[str] = None,
cpk: Optional[CustomerProvidedEncryptionKey] = None,
max_concurrency: int = 1,
max_concurrency: Optional[int] = None,
encoding: str,
progress_hook: Optional[Callable[[int, int], None]] = None,
decompress: Optional[bool] = None,
Expand All @@ -230,7 +230,7 @@ class BlobClient(StorageAccountHostsMixin, StorageEncryptionMixin):
match_condition: Optional[MatchConditions] = None,
if_tags_match_condition: Optional[str] = None,
cpk: Optional[CustomerProvidedEncryptionKey] = None,
max_concurrency: int = 1,
max_concurrency: Optional[int] = None,
encoding: None = None,
progress_hook: Optional[Callable[[int, int], None]] = None,
decompress: Optional[bool] = None,
Expand All @@ -252,7 +252,7 @@ class BlobClient(StorageAccountHostsMixin, StorageEncryptionMixin):
match_condition: Optional[MatchConditions] = None,
if_tags_match_condition: Optional[str] = None,
cpk: Optional[CustomerProvidedEncryptionKey] = None,
max_concurrency: int = 1,
max_concurrency: Optional[int] = None,
encoding: Optional[str] = None,
progress_hook: Optional[Callable[[int, int], None]] = None,
decompress: Optional[bool] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
)
from ._shared import encode_base64
from ._shared.base_client import parse_query
from ._shared.constants import DEFAULT_MAX_CONCURRENCY
from ._shared.request_handlers import (
add_metadata_headers,
get_length,
Expand Down Expand Up @@ -137,7 +138,9 @@ def _upload_blob_options( # pylint:disable=too-many-statements
validate_content = kwargs.pop('validate_content', False)
content_settings = kwargs.pop('content_settings', None)
overwrite = kwargs.pop('overwrite', False)
max_concurrency = kwargs.pop('max_concurrency', 1)
max_concurrency = kwargs.pop('max_concurrency', None)
if max_concurrency is None:
max_concurrency = DEFAULT_MAX_CONCURRENCY
cpk = kwargs.pop('cpk', None)
cpk_info = None
if cpk:
Expand Down Expand Up @@ -323,7 +326,7 @@ def _download_blob_options(
'modified_access_conditions': mod_conditions,
'cpk_info': cpk_info,
'download_cls': kwargs.pop('cls', None) or deserialize_blob_stream,
'max_concurrency':kwargs.pop('max_concurrency', 1),
'max_concurrency': kwargs.pop('max_concurrency', None) or DEFAULT_MAX_CONCURRENCY,
'encoding': encoding,
'timeout': kwargs.pop('timeout', None),
'name': blob_name,
Expand Down
17 changes: 9 additions & 8 deletions sdk/storage/azure-storage-blob/azure/storage/blob/_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from ._shared.request_handlers import validate_and_format_range_headers
from ._shared.response_handlers import parse_length_from_content_range, process_storage_error
from ._shared.constants import DEFAULT_MAX_CONCURRENCY
from ._deserialize import deserialize_blob_properties, get_page_ranges_result
from ._encryption import (
adjust_blob_size_for_encryption,
Expand Down Expand Up @@ -330,7 +331,7 @@ def __init__(
end_range: Optional[int] = None,
validate_content: bool = None, # type: ignore [assignment]
encryption_options: Dict[str, Any] = None, # type: ignore [assignment]
max_concurrency: int = 1,
max_concurrency: Optional[int] = None,
name: str = None, # type: ignore [assignment]
container: str = None, # type: ignore [assignment]
encoding: Optional[str] = None,
Expand All @@ -345,7 +346,7 @@ def __init__(
self._config = config
self._start_range = start_range
self._end_range = end_range
self._max_concurrency = max_concurrency
self._max_concurrency = max_concurrency if max_concurrency is not None else DEFAULT_MAX_CONCURRENCY
self._encoding = encoding
self._validate_content = validate_content
self._encryption_options = encryption_options or {}
Expand Down Expand Up @@ -865,7 +866,7 @@ def _check_and_report_progress(self):
if self._progress_hook and self._current_content_offset == len(self._current_content):
self._progress_hook(self._download_offset, self.size)

def content_as_bytes(self, max_concurrency=1):
def content_as_bytes(self, max_concurrency=None):
"""DEPRECATED: Download the contents of this file.

This operation is blocking until all data is downloaded.
Expand All @@ -885,10 +886,10 @@ def content_as_bytes(self, max_concurrency=1):
raise ValueError("Stream has been partially read in text mode. "
"content_as_bytes is not supported in text mode.")

self._max_concurrency = max_concurrency
self._max_concurrency = max_concurrency if max_concurrency is not None else DEFAULT_MAX_CONCURRENCY
return self.readall()

def content_as_text(self, max_concurrency=1, encoding="UTF-8"):
def content_as_text(self, max_concurrency=None, encoding="UTF-8"):
"""DEPRECATED: Download the contents of this blob, and decode as text.

This operation is blocking until all data is downloaded.
Expand All @@ -910,11 +911,11 @@ def content_as_text(self, max_concurrency=1, encoding="UTF-8"):
raise ValueError("Stream has been partially read in text mode. "
"content_as_text is not supported in text mode.")

self._max_concurrency = max_concurrency
self._max_concurrency = max_concurrency if max_concurrency is not None else DEFAULT_MAX_CONCURRENCY
self._encoding = encoding
return self.readall()

def download_to_stream(self, stream, max_concurrency=1):
def download_to_stream(self, stream, max_concurrency=None):
"""DEPRECATED: Download the contents of this blob to a stream.

This method is deprecated, use func:`readinto` instead.
Expand All @@ -936,6 +937,6 @@ def download_to_stream(self, stream, max_concurrency=1):
raise ValueError("Stream has been partially read in text mode. "
"download_to_stream is not supported in text mode.")

self._max_concurrency = max_concurrency
self._max_concurrency = max_concurrency if max_concurrency is not None else DEFAULT_MAX_CONCURRENCY
self.readinto(stream)
return self.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
READ_TIMEOUT = 60
DATA_BLOCK_SIZE = 256 * 1024

DEFAULT_MAX_CONCURRENCY = 1

DEFAULT_OAUTH_SCOPE = "/.default"
STORAGE_OAUTH_SCOPE = "https://storage.azure.com/.default"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class BlobClient( # type: ignore[misc]
legal_hold: Optional[bool] = None,
standard_blob_tier: Optional[StandardBlobTier] = None,
maxsize_condition: Optional[int] = None,
max_concurrency: int = 1,
max_concurrency: Optional[int] = None,
cpk: Optional[CustomerProvidedEncryptionKey] = None,
encryption_scope: Optional[str] = None,
encoding: str = "UTF-8",
Expand All @@ -210,7 +210,7 @@ class BlobClient( # type: ignore[misc]
match_condition: Optional[MatchConditions] = None,
if_tags_match_condition: Optional[str] = None,
cpk: Optional[CustomerProvidedEncryptionKey] = None,
max_concurrency: int = 1,
max_concurrency: Optional[int] = None,
encoding: str,
progress_hook: Optional[Callable[[int, int], Awaitable[None]]] = None,
decompress: Optional[bool] = None,
Expand All @@ -232,7 +232,7 @@ class BlobClient( # type: ignore[misc]
match_condition: Optional[MatchConditions] = None,
if_tags_match_condition: Optional[str] = None,
cpk: Optional[CustomerProvidedEncryptionKey] = None,
max_concurrency: int = 1,
max_concurrency: Optional[int] = None,
encoding: None = None,
progress_hook: Optional[Callable[[int, int], Awaitable[None]]] = None,
decompress: Optional[bool] = None,
Expand All @@ -254,7 +254,7 @@ class BlobClient( # type: ignore[misc]
match_condition: Optional[MatchConditions] = None,
if_tags_match_condition: Optional[str] = None,
cpk: Optional[CustomerProvidedEncryptionKey] = None,
max_concurrency: int = 1,
max_concurrency: Optional[int] = None,
encoding: Optional[str] = None,
progress_hook: Optional[Callable[[int, int], Awaitable[None]]] = None,
decompress: Optional[bool] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from .._shared.request_handlers import validate_and_format_range_headers
from .._shared.response_handlers import parse_length_from_content_range, process_storage_error
from .._shared.constants import DEFAULT_MAX_CONCURRENCY
from .._deserialize import deserialize_blob_properties, get_page_ranges_result
from .._download import process_range_and_offset, _ChunkDownloader
from .._encryption import (
Expand Down Expand Up @@ -239,7 +240,7 @@ def __init__(
end_range: Optional[int] = None,
validate_content: bool = None, # type: ignore [assignment]
encryption_options: Dict[str, Any] = None, # type: ignore [assignment]
max_concurrency: int = 1,
max_concurrency: Optional[int] = None,
name: str = None, # type: ignore [assignment]
container: str = None, # type: ignore [assignment]
encoding: Optional[str] = None,
Expand All @@ -254,7 +255,7 @@ def __init__(
self._config = config
self._start_range = start_range
self._end_range = end_range
self._max_concurrency = max_concurrency
self._max_concurrency = max_concurrency if max_concurrency is not None else DEFAULT_MAX_CONCURRENCY
self._encoding = encoding
self._validate_content = validate_content
self._encryption_options = encryption_options or {}
Expand Down Expand Up @@ -808,7 +809,7 @@ async def _check_and_report_progress(self):
if self._progress_hook and self._current_content_offset == len(self._current_content):
await self._progress_hook(self._download_offset, self.size)

async def content_as_bytes(self, max_concurrency=1):
async def content_as_bytes(self, max_concurrency=None):
"""DEPRECATED: Download the contents of this file.

This operation is blocking until all data is downloaded.
Expand All @@ -828,10 +829,10 @@ async def content_as_bytes(self, max_concurrency=1):
raise ValueError("Stream has been partially read in text mode. "
"content_as_bytes is not supported in text mode.")

self._max_concurrency = max_concurrency
self._max_concurrency = max_concurrency if max_concurrency is not None else DEFAULT_MAX_CONCURRENCY
return await self.readall()

async def content_as_text(self, max_concurrency=1, encoding="UTF-8"):
async def content_as_text(self, max_concurrency=None, encoding="UTF-8"):
"""DEPRECATED: Download the contents of this blob, and decode as text.

This operation is blocking until all data is downloaded.
Expand All @@ -853,11 +854,11 @@ async def content_as_text(self, max_concurrency=1, encoding="UTF-8"):
raise ValueError("Stream has been partially read in text mode. "
"content_as_text is not supported in text mode.")

self._max_concurrency = max_concurrency
self._max_concurrency = max_concurrency if max_concurrency is not None else DEFAULT_MAX_CONCURRENCY
self._encoding = encoding
return await self.readall()

async def download_to_stream(self, stream, max_concurrency=1):
async def download_to_stream(self, stream, max_concurrency=None):
"""DEPRECATED: Download the contents of this blob to a stream.

This method is deprecated, use func:`readinto` instead.
Expand All @@ -879,6 +880,6 @@ async def download_to_stream(self, stream, max_concurrency=1):
raise ValueError("Stream has been partially read in text mode. "
"download_to_stream is not supported in text mode.")

self._max_concurrency = max_concurrency
self._max_concurrency = max_concurrency if max_concurrency is not None else DEFAULT_MAX_CONCURRENCY
await self.readinto(stream)
return self.properties
17 changes: 17 additions & 0 deletions sdk/storage/azure-storage-blob/tests/test_block_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1984,4 +1984,21 @@ def test_upload_blob_copy_source_error_and_status_code(self, **kwargs):
finally:
self.bsc.delete_container(self.container_name)

@BlobPreparer()
@recorded_by_proxy
def test_put_block_blob_with_none_concurrency(self, **kwargs):
storage_account_name = kwargs.pop("storage_account_name")
storage_account_key = kwargs.pop("storage_account_key")

self._setup(storage_account_name, storage_account_key)
blob_name = self._get_blob_reference()
blob = self.bsc.get_blob_client(self.container_name, blob_name)
data = b'a' * 5 * 1024

# max_concurrency=None should not raise TypeError
blob.upload_blob(data, max_concurrency=None, overwrite=True)

content = blob.download_blob().readall()
assert data == content

#------------------------------------------------------------------------------
17 changes: 17 additions & 0 deletions sdk/storage/azure-storage-blob/tests/test_block_blob_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -2102,4 +2102,21 @@ async def test_upload_blob_copy_source_error_and_status_code(self, **kwargs):
finally:
await self.bsc.delete_container(self.container_name)

@BlobPreparer()
@recorded_by_proxy_async
async def test_put_block_blob_with_none_concurrency(self, **kwargs):
storage_account_name = kwargs.pop("storage_account_name")
storage_account_key = kwargs.pop("storage_account_key")

await self._setup(storage_account_name, storage_account_key)
blob_name = self._get_blob_reference()
blob = self.bsc.get_blob_client(self.container_name, blob_name)
data = b'a' * 5 * 1024

# max_concurrency=None should not raise TypeError
await blob.upload_blob(data, max_concurrency=None, overwrite=True)

content = await (await blob.download_blob()).readall()
assert data == content

# ------------------------------------------------------------------------------
15 changes: 15 additions & 0 deletions sdk/storage/azure-storage-blob/tests/test_get_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1663,4 +1663,19 @@ def test_get_blob_read_chars_utf32(self, **kwargs):
result += stream.readall()
assert result == data

@BlobPreparer()
@recorded_by_proxy
def test_get_blob_to_bytes_with_none_concurrency(self, **kwargs):
storage_account_name = kwargs.pop("storage_account_name")
storage_account_key = kwargs.pop("storage_account_key")

self._setup(storage_account_name, storage_account_key)
blob = self.bsc.get_blob_client(self.container_name, self.byte_blob)

# max_concurrency=None should not raise TypeError
stream = blob.download_blob(max_concurrency=None)
content = stream.readall()

assert self.byte_data == content

# ------------------------------------------------------------------------------
15 changes: 15 additions & 0 deletions sdk/storage/azure-storage-blob/tests/test_get_blob_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -1815,4 +1815,19 @@ async def test_get_blob_read_chars_utf32(self, **kwargs):
result += await stream.readall()
assert result == data

@BlobPreparer()
@recorded_by_proxy_async
async def test_get_blob_to_bytes_with_none_concurrency(self, **kwargs):
storage_account_name = kwargs.pop("storage_account_name")
storage_account_key = kwargs.pop("storage_account_key")

await self._setup(storage_account_name, storage_account_key)
blob = self.bsc.get_blob_client(self.container_name, self.byte_blob)

# max_concurrency=None should not raise TypeError
stream = await blob.download_blob(max_concurrency=None)
content = await stream.readall()

assert self.byte_data == content

# ------------------------------------------------------------------------------