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
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-blob/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Removed types that were accidentally exposed from two modules. Only `BlobServiceClient`, `ContainerClient`,
`BlobClient` and `LeaseClient` should be imported from azure.storage.blob.aio
- `Logging` has been renamed to `BlobAnalyticsLogging`.
- Client and model files have been made internal. Users should import from the top level modules `azure.storage.blob` and `azure.storage.blob.aio` only.
- All operations that take Etag conditional parameters (`if_match` and `if_none_match`) now take explicit `etag` and `match_condition` parameters, where `etag` is the Etag value, and `match_condition` is an instance of `azure.core.MatchConditions`.
- The `generate_shared_access_signature` methods on each of `BlobServiceClient`, `ContainerClient` and `BlobClient` have been replaced by module level functions `generate_account_sas`, `generate_container_sas` and `generate_blob_sas`.
- The batch APIs now have an additional keyword only argument `raise_on_any_failure` which defaults to True. This will raise an error even if there's a partial batch failure.
Expand Down
18 changes: 9 additions & 9 deletions sdk/storage/azure-storage-blob/azure/storage/blob/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import os

from typing import Union, Iterable, AnyStr, IO, Any # pylint: disable=unused-import
from .version import VERSION
from .blob_client import BlobClient
from .container_client import ContainerClient
from .blob_service_client import BlobServiceClient
from .lease import LeaseClient
from .download import StorageStreamDownloader
from typing import Union, Iterable, AnyStr, IO, Any, Dict # pylint: disable=unused-import
from ._version import VERSION
from ._blob_client import BlobClient
from ._container_client import ContainerClient
from ._blob_service_client import BlobServiceClient
from ._lease import LeaseClient
from ._download import StorageStreamDownloader
from ._shared_access_signature import generate_account_sas, generate_container_sas, generate_blob_sas
from ._shared.policies import ExponentialRetry, LinearRetry
from ._shared.response_handlers import PartialBatchErrorException
Expand All @@ -26,7 +26,7 @@
from ._generated.models import (
RehydratePriority
)
from .models import (
from ._models import (
BlobType,
BlockState,
StandardBlobTier,
Expand Down Expand Up @@ -59,7 +59,7 @@ def upload_blob_to_url(
data, # type: Union[Iterable[AnyStr], IO[AnyStr]]
credential=None, # type: Any
**kwargs):
# type: (...) -> dict[str, Any]
# type: (...) -> Dict[str, Any]
"""Upload data to a given URL

The data will be uploaded as a block blob.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
upload_block_blob,
upload_append_blob,
upload_page_blob)
from .models import BlobType, BlobBlock
from .download import StorageStreamDownloader
from .lease import LeaseClient, get_access_conditions
from ._models import BlobType, BlobBlock
from ._download import StorageStreamDownloader
from ._lease import LeaseClient, get_access_conditions

if TYPE_CHECKING:
from datetime import datetime
from ._generated.models import BlockList
from .models import ( # pylint: disable=unused-import
from ._models import ( # pylint: disable=unused-import
ContainerProperties,
BlobProperties,
BlobSasPermissions,
Expand Down Expand Up @@ -470,7 +470,7 @@ def upload_blob( # pylint: disable=too-many-locals
return upload_append_blob(**options)

def _download_blob_options(self, offset=None, length=None, **kwargs):
# type: (Optional[int], Optional[int], bool, **Any) -> Dict[str, Any]
# type: (Optional[int], Optional[int], **Any) -> Dict[str, Any]
if self.require_encryption and not self.key_encryption_key:
raise ValueError("Encryption required but no key was provided.")
if length is not None and offset is None:
Expand Down Expand Up @@ -514,7 +514,7 @@ def _download_blob_options(self, offset=None, length=None, **kwargs):

@distributed_trace
def download_blob(self, offset=None, length=None, **kwargs):
# type: (Optional[int], Optional[int], bool, **Any) -> Iterable[bytes]
# type: (Optional[int], Optional[int], **Any) -> Iterable[bytes]
"""Downloads a blob to a stream with automatic chunking.

:param int offset:
Expand Down Expand Up @@ -1692,7 +1692,7 @@ def stage_block_from_url(
process_storage_error(error)

def _get_block_list_result(self, blocks):
# type: (BlockList) -> Tuple(List[BlobBlock], List[BlobBlock])
# type: (BlockList) -> Tuple[List[BlobBlock], List[BlobBlock]]
committed = [] # type: List
uncommitted = [] # type: List
if blocks.committed_blocks:
Expand Down Expand Up @@ -1863,7 +1863,7 @@ def commit_block_list( # type: ignore

@distributed_trace
def set_premium_page_blob_tier(self, premium_page_blob_tier, **kwargs):
# type: (Union[str, PremiumPageBlobTier], Optional[int], Optional[Union[LeaseClient, str]], **Any) -> None
# type: (Union[str, PremiumPageBlobTier], **Any) -> None
"""Sets the page blob tiers on the blob. This API is only supported for page blobs on premium accounts.

:param premium_page_blob_tier:
Expand Down Expand Up @@ -1902,6 +1902,8 @@ def _get_page_ranges_options( # type: ignore
# type: (...) -> Dict[str, Any]
access_conditions = get_access_conditions(kwargs.pop('lease', None))
mod_conditions = get_modify_conditions(kwargs)
if length is not None and offset is None:
raise ValueError("Offset value must not be None if length is set.")
if length is not None:
length = offset + length - 1 # Reformat to an inclusive range index
page_range, _ = validate_and_format_range_headers(
Expand Down Expand Up @@ -1931,7 +1933,7 @@ def get_page_ranges( # type: ignore
previous_snapshot_diff=None, # type: Optional[Union[str, Dict[str, Any]]]
**kwargs
):
# type: (...) -> Tuple(List[Dict[str, int]], List[Dict[str, int]])
# type: (...) -> Tuple[List[Dict[str, int]], List[Dict[str, int]]]
"""Returns the list of valid page ranges for a Page Blob or snapshot
of a page blob.

Expand Down Expand Up @@ -2638,8 +2640,8 @@ def append_block( # type: ignore

def _append_block_from_url_options( # type: ignore
self, copy_source_url, # type: str
source_offset=None, # type Optional[int]
source_length=None, # type Optional[int]
source_offset=None, # type: Optional[int]
source_length=None, # type: Optional[int]
**kwargs
):
# type: (...) -> Dict[str, Any]
Expand Down Expand Up @@ -2696,8 +2698,8 @@ def _append_block_from_url_options( # type: ignore

@distributed_trace
def append_block_from_url(self, copy_source_url, # type: str
source_offset=None, # type Optional[int]
source_length=None, # type Optional[int]
source_offset=None, # type: Optional[int]
source_length=None, # type: Optional[int]
**kwargs):
# type: (...) -> Dict[str, Union[str, datetime, int]]
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
parse_to_internal_user_delegation_key
from ._generated import AzureBlobStorage
from ._generated.models import StorageErrorException, StorageServiceProperties, KeyInfo
from .container_client import ContainerClient
from .blob_client import BlobClient
from .models import ContainerPropertiesPaged
from ._container_client import ContainerClient
from ._blob_client import BlobClient
from ._models import ContainerPropertiesPaged

if TYPE_CHECKING:
from datetime import datetime
from azure.core.pipeline.transport import HttpTransport
from azure.core.pipeline.policies import HTTPPolicy
from ._shared.models import UserDelegationKey
from .lease import LeaseClient
from .models import (
from ._lease import LeaseClient
from ._models import (
BlobProperties,
ContainerProperties,
BlobAnalyticsLogging,
Expand Down Expand Up @@ -163,7 +163,7 @@ def get_user_delegation_key(self, key_start_time, # type: datetime
key_expiry_time, # type: datetime
**kwargs # type: Any
):
# type: (datetime, datetime, Optional[int]) -> UserDelegationKey
# type: (...) -> UserDelegationKey
"""
Obtain a user delegation key for the purpose of signing SAS tokens.
A token credential must be present on the service object for this request to succeed.
Expand All @@ -189,8 +189,8 @@ def get_user_delegation_key(self, key_start_time, # type: datetime
return parse_to_internal_user_delegation_key(user_delegation_key) # type: ignore

@distributed_trace
def get_account_information(self, **kwargs): # type: ignore
# type: (Optional[int]) -> Dict[str, str]
def get_account_information(self, **kwargs):
# type: (Any) -> Dict[str, str]
"""Gets information related to the storage account.

The information can also be retrieved if the user has a SAS to a container or blob.
Expand All @@ -214,7 +214,7 @@ def get_account_information(self, **kwargs): # type: ignore
process_storage_error(error)

@distributed_trace
def get_service_stats(self, **kwargs): # type: ignore
def get_service_stats(self, **kwargs):
# type: (**Any) -> Dict[str, Any]
"""Retrieves statistics related to replication for the Blob service.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,24 @@
SignedIdentifier)
from ._deserialize import deserialize_container_properties
from ._serialize import get_modify_conditions
from .models import ( # pylint: disable=unused-import
from ._models import ( # pylint: disable=unused-import
ContainerProperties,
BlobProperties,
BlobPropertiesPaged,
BlobType,
BlobPrefix)
from .lease import LeaseClient, get_access_conditions
from .blob_client import BlobClient
from ._lease import LeaseClient, get_access_conditions
from ._blob_client import BlobClient

if TYPE_CHECKING:
from azure.core.pipeline.transport import HttpTransport, HttpResponse # pylint: disable=ungrouped-imports
from azure.core.pipeline.policies import HTTPPolicy # pylint: disable=ungrouped-imports
from datetime import datetime
from .models import ( # pylint: disable=unused-import
from ._models import ( # pylint: disable=unused-import
PublicAccess,
AccessPolicy,
ContentSettings,
StandardBlobTier,
PremiumPageBlobTier)


Expand Down Expand Up @@ -363,7 +364,7 @@ def acquire_lease(
return lease

@distributed_trace
def get_account_information(self, **kwargs): # type: ignore
def get_account_information(self, **kwargs):
# type: (**Any) -> Dict[str, str]
"""Gets information related to the storage account.

Expand Down
12 changes: 10 additions & 2 deletions sdk/storage/azure-storage-blob/azure/storage/blob/_deserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
# --------------------------------------------------------------------------
# pylint: disable=no-self-use

from typing import ( # pylint: disable=unused-import

@rakshith91 rakshith91 Oct 17, 2019

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.

typing isn't a part of python 2.7 or azure-core requirements. should we guard it?

#6133

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

According to @lmazuel all packages have dependency on typing now.

Tuple, Dict, List,
TYPE_CHECKING
)

from ._shared.response_handlers import deserialize_metadata
from .models import BlobProperties, ContainerProperties
from ._models import BlobProperties, ContainerProperties

if TYPE_CHECKING:
from azure.storage.blob._generated.models import PageList


def deserialize_blob_properties(response, obj, headers):
Expand Down Expand Up @@ -39,7 +47,7 @@ def deserialize_container_properties(response, obj, headers):


def get_page_ranges_result(ranges):
# type: (PageList) -> Tuple(List[Dict[str, int]], List[Dict[str, int]])
# type: (PageList) -> Tuple[List[Dict[str, int]], List[Dict[str, int]]]
page_range = [] # type: ignore
clear_range = [] # type: List
if ranges.page_range:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __exit__(self, *args):

@distributed_trace
def acquire(self, lease_duration=-1, **kwargs):
# type: (int, Optional[int], **Any) -> None
# type: (int, **Any) -> None
"""Requests a new lease.

If the container does not have an active lease, the Blob service creates a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from azure.core.exceptions import HttpResponseError

from ..version import VERSION
from .._version import VERSION
from . import encode_base64, decode_base64_to_bytes


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,11 @@ class Services(object):
"""Specifies the services accessible with the account SAS.

:param bool blob:
Access for the `~azure.storage.blob.blob_service_client.BlobServiceClient`
Access for the `~azure.storage.blob.BlobServiceClient`
:param bool queue:
Access for the `~azure.storage.queue.queue_service_client.QueueServiceClient`
Access for the `~azure.storage.queue.QueueServiceClient`
:param bool file:
Access for the `~azure.storage.file.file_service_client.FileServiceClient`
Access for the `~azure.storage.file.FileServiceClient`
"""

def __init__(self, blob=False, queue=False, file=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
)
from azure.core.exceptions import AzureError, ServiceRequestError, ServiceResponseError

from ..version import VERSION
from .._version import VERSION
from .models import LocationMode

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
AppendPositionAccessConditions,
ModifiedAccessConditions,
)
from .models import BlobProperties, ContainerProperties
from ._models import BlobProperties, ContainerProperties

if TYPE_CHECKING:
from datetime import datetime # pylint: disable=unused-import
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

import os

from ..models import BlobType
from .._models import BlobType
from .._shared.policies_async import ExponentialRetry, LinearRetry
from .blob_client_async import BlobClient
from .container_client_async import ContainerClient
from .blob_service_client_async import BlobServiceClient
from .lease_async import LeaseClient
from ._blob_client_async import BlobClient
from ._container_client_async import ContainerClient
from ._blob_service_client_async import BlobServiceClient
from ._lease_async import LeaseClient


async def upload_blob_to_url(
Expand Down
Loading