|
1 | | -# ------------------------------------------------------------------------- |
| 1 | +# coding=utf-8 |
| 2 | +# -------------------------------------------------------------------------- |
2 | 3 | # Copyright (c) Microsoft Corporation. All rights reserved. |
3 | | -# Licensed under the MIT License. See License.txt in the project root for |
4 | | -# license information. |
| 4 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
| 5 | +# Code generated by Microsoft (R) Python Code Generator. |
| 6 | +# Changes may cause incorrect behavior and will be lost if the code is regenerated. |
5 | 7 | # -------------------------------------------------------------------------- |
6 | | -# pylint: disable=docstring-keyword-should-match-keyword-only |
7 | | - |
8 | | -import os |
| 8 | +# pylint: disable=wrong-import-position |
9 | 9 |
|
10 | | -from typing import Any, AnyStr, cast, Dict, IO, Iterable, Optional, Union, TYPE_CHECKING |
11 | | -from ._version import VERSION |
12 | | -from ._blob_client import BlobClient |
13 | | -from ._container_client import ContainerClient |
14 | | -from ._blob_service_client import BlobServiceClient |
15 | | -from ._lease import BlobLeaseClient |
16 | | -from ._download import StorageStreamDownloader |
17 | | -from ._quick_query_helper import BlobQueryReader |
18 | | -from ._shared_access_signature import generate_account_sas, generate_container_sas, generate_blob_sas |
19 | | -from ._shared.policies import ExponentialRetry, LinearRetry |
20 | | -from ._shared.response_handlers import PartialBatchErrorException |
21 | | -from ._shared.models import ( |
22 | | - LocationMode, |
23 | | - ResourceTypes, |
24 | | - AccountSasPermissions, |
25 | | - StorageErrorCode, |
26 | | - UserDelegationKey, |
27 | | - Services |
28 | | -) |
29 | | -from ._generated.models import RehydratePriority |
30 | | -from ._models import ( |
31 | | - BlobType, |
32 | | - BlockState, |
33 | | - StandardBlobTier, |
34 | | - PremiumPageBlobTier, |
35 | | - BlobImmutabilityPolicyMode, |
36 | | - SequenceNumberAction, |
37 | | - PublicAccess, |
38 | | - BlobAnalyticsLogging, |
39 | | - Metrics, |
40 | | - RetentionPolicy, |
41 | | - StaticWebsite, |
42 | | - CorsRule, |
43 | | - ContainerProperties, |
44 | | - BlobProperties, |
45 | | - FilteredBlob, |
46 | | - LeaseProperties, |
47 | | - ContentSettings, |
48 | | - CopyProperties, |
49 | | - BlobBlock, |
50 | | - PageRange, |
51 | | - AccessPolicy, |
52 | | - ContainerSasPermissions, |
53 | | - BlobSasPermissions, |
54 | | - CustomerProvidedEncryptionKey, |
55 | | - ContainerEncryptionScope, |
56 | | - BlobQueryError, |
57 | | - DelimitedJsonDialect, |
58 | | - DelimitedTextDialect, |
59 | | - QuickQueryDialect, |
60 | | - ArrowDialect, |
61 | | - ArrowType, |
62 | | - ObjectReplicationPolicy, |
63 | | - ObjectReplicationRule, |
64 | | - ImmutabilityPolicy, |
65 | | -) |
66 | | -from ._list_blobs_helper import BlobPrefix |
| 10 | +from typing import TYPE_CHECKING |
67 | 11 |
|
68 | 12 | if TYPE_CHECKING: |
69 | | - from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential |
70 | | - |
71 | | -__version__ = VERSION |
72 | | - |
73 | | - |
74 | | -def upload_blob_to_url( |
75 | | - blob_url: str, |
76 | | - data: Union[Iterable[AnyStr], IO[AnyStr]], |
77 | | - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long |
78 | | - **kwargs: Any |
79 | | -) -> Dict[str, Any]: |
80 | | - """Upload data to a given URL |
81 | | -
|
82 | | - The data will be uploaded as a block blob. |
| 13 | + from ._patch import * # pylint: disable=unused-wildcard-import |
83 | 14 |
|
84 | | - :param str blob_url: |
85 | | - The full URI to the blob. This can also include a SAS token. |
86 | | - :param data: |
87 | | - The data to upload. This can be bytes, text, an iterable or a file-like object. |
88 | | - :type data: bytes or str or Iterable |
89 | | - :param credential: |
90 | | - The credentials with which to authenticate. This is optional if the |
91 | | - blob URL already has a SAS token. The value can be a SAS token string, |
92 | | - an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, |
93 | | - an account shared access key, or an instance of a TokenCredentials class from azure.identity. |
94 | | - If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential |
95 | | - - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. |
96 | | - If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" |
97 | | - should be the storage account key. |
98 | | - :type credential: |
99 | | - ~azure.core.credentials.AzureNamedKeyCredential or |
100 | | - ~azure.core.credentials.AzureSasCredential or |
101 | | - ~azure.core.credentials.TokenCredential or |
102 | | - str or dict[str, str] or None |
103 | | - :keyword bool overwrite: |
104 | | - Whether the blob to be uploaded should overwrite the current data. |
105 | | - If True, upload_blob_to_url will overwrite any existing data. If set to False, the |
106 | | - operation will fail with a ResourceExistsError. |
107 | | - :keyword int max_concurrency: |
108 | | - The number of parallel connections with which to download. |
109 | | - :keyword int length: |
110 | | - Number of bytes to read from the stream. This is optional, but |
111 | | - should be supplied for optimal performance. |
112 | | - :keyword dict(str,str) metadata: |
113 | | - Name-value pairs associated with the blob as metadata. |
114 | | - :keyword bool validate_content: |
115 | | - If true, calculates an MD5 hash for each chunk of the blob. The storage |
116 | | - service checks the hash of the content that has arrived with the hash |
117 | | - that was sent. This is primarily valuable for detecting bitflips on |
118 | | - the wire if using http instead of https as https (the default) will |
119 | | - already validate. Note that this MD5 hash is not stored with the |
120 | | - blob. Also note that if enabled, the memory-efficient upload algorithm |
121 | | - will not be used, because computing the MD5 hash requires buffering |
122 | | - entire blocks, and doing so defeats the purpose of the memory-efficient algorithm. |
123 | | - :keyword str encoding: |
124 | | - Encoding to use if text is supplied as input. Defaults to UTF-8. |
125 | | - :returns: Blob-updated property dict (Etag and last modified) |
126 | | - :rtype: dict(str, Any) |
127 | | - """ |
128 | | - with BlobClient.from_blob_url(blob_url, credential=credential) as client: |
129 | | - return cast(BlobClient, client).upload_blob(data=data, blob_type=BlobType.BLOCKBLOB, **kwargs) |
130 | | - |
131 | | - |
132 | | -def _download_to_stream(client: BlobClient, handle: IO[bytes], **kwargs: Any) -> None: |
133 | | - """ |
134 | | - Download data to specified open file-handle. |
135 | | -
|
136 | | - :param BlobClient client: The BlobClient to download with. |
137 | | - :param Stream handle: A Stream to download the data into. |
138 | | - """ |
139 | | - stream = client.download_blob(**kwargs) |
140 | | - stream.readinto(handle) |
141 | | - |
142 | | - |
143 | | -def download_blob_from_url( |
144 | | - blob_url: str, |
145 | | - output: Union[str, IO[bytes]], |
146 | | - credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long |
147 | | - **kwargs: Any |
148 | | -) -> None: |
149 | | - """Download the contents of a blob to a local file or stream. |
| 15 | +from ._client import BlobClient # type: ignore |
| 16 | +from ._version import VERSION |
150 | 17 |
|
151 | | - :param str blob_url: |
152 | | - The full URI to the blob. This can also include a SAS token. |
153 | | - :param output: |
154 | | - Where the data should be downloaded to. This could be either a file path to write to, |
155 | | - or an open IO handle to write to. |
156 | | - :type output: str or writable stream. |
157 | | - :param credential: |
158 | | - The credentials with which to authenticate. This is optional if the |
159 | | - blob URL already has a SAS token or the blob is public. The value can be a SAS token string, |
160 | | - an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, |
161 | | - an account shared access key, or an instance of a TokenCredentials class from azure.identity. |
162 | | - If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential |
163 | | - - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. |
164 | | - If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" |
165 | | - should be the storage account key. |
166 | | - :type credential: |
167 | | - ~azure.core.credentials.AzureNamedKeyCredential or |
168 | | - ~azure.core.credentials.AzureSasCredential or |
169 | | - ~azure.core.credentials.TokenCredential or |
170 | | - str or dict[str, str] or None |
171 | | - :keyword bool overwrite: |
172 | | - Whether the local file should be overwritten if it already exists. The default value is |
173 | | - `False` - in which case a ValueError will be raised if the file already exists. If set to |
174 | | - `True`, an attempt will be made to write to the existing file. If a stream handle is passed |
175 | | - in, this value is ignored. |
176 | | - :keyword int max_concurrency: |
177 | | - The number of parallel connections with which to download. |
178 | | - :keyword int offset: |
179 | | - Start of byte range to use for downloading a section of the blob. |
180 | | - Must be set if length is provided. |
181 | | - :keyword int length: |
182 | | - Number of bytes to read from the stream. This is optional, but |
183 | | - should be supplied for optimal performance. |
184 | | - :keyword bool validate_content: |
185 | | - If true, calculates an MD5 hash for each chunk of the blob. The storage |
186 | | - service checks the hash of the content that has arrived with the hash |
187 | | - that was sent. This is primarily valuable for detecting bitflips on |
188 | | - the wire if using http instead of https as https (the default) will |
189 | | - already validate. Note that this MD5 hash is not stored with the |
190 | | - blob. Also note that if enabled, the memory-efficient upload algorithm |
191 | | - will not be used, because computing the MD5 hash requires buffering |
192 | | - entire blocks, and doing so defeats the purpose of the memory-efficient algorithm. |
193 | | - :rtype: None |
194 | | - """ |
195 | | - overwrite = kwargs.pop('overwrite', False) |
196 | | - with BlobClient.from_blob_url(blob_url, credential=credential) as client: |
197 | | - if hasattr(output, 'write'): |
198 | | - _download_to_stream(client, cast(IO[bytes], output), **kwargs) |
199 | | - else: |
200 | | - if not overwrite and os.path.isfile(output): |
201 | | - raise ValueError(f"The file '{output}' already exists.") |
202 | | - with open(output, 'wb') as file_handle: |
203 | | - _download_to_stream(client, file_handle, **kwargs) |
| 18 | +__version__ = VERSION |
204 | 19 |
|
| 20 | +try: |
| 21 | + from ._patch import __all__ as _patch_all |
| 22 | + from ._patch import * |
| 23 | +except ImportError: |
| 24 | + _patch_all = [] |
| 25 | +from ._patch import patch_sdk as _patch_sdk |
205 | 26 |
|
206 | 27 | __all__ = [ |
207 | | - 'upload_blob_to_url', |
208 | | - 'download_blob_from_url', |
209 | | - 'BlobServiceClient', |
210 | | - 'ContainerClient', |
211 | | - 'BlobClient', |
212 | | - 'BlobType', |
213 | | - 'BlobLeaseClient', |
214 | | - 'StorageErrorCode', |
215 | | - 'UserDelegationKey', |
216 | | - 'ExponentialRetry', |
217 | | - 'LinearRetry', |
218 | | - 'LocationMode', |
219 | | - 'BlockState', |
220 | | - 'StandardBlobTier', |
221 | | - 'PremiumPageBlobTier', |
222 | | - 'SequenceNumberAction', |
223 | | - 'BlobImmutabilityPolicyMode', |
224 | | - 'ImmutabilityPolicy', |
225 | | - 'PublicAccess', |
226 | | - 'BlobAnalyticsLogging', |
227 | | - 'Metrics', |
228 | | - 'RetentionPolicy', |
229 | | - 'StaticWebsite', |
230 | | - 'CorsRule', |
231 | | - 'ContainerProperties', |
232 | | - 'BlobProperties', |
233 | | - 'BlobPrefix', |
234 | | - 'FilteredBlob', |
235 | | - 'LeaseProperties', |
236 | | - 'ContentSettings', |
237 | | - 'CopyProperties', |
238 | | - 'BlobBlock', |
239 | | - 'PageRange', |
240 | | - 'AccessPolicy', |
241 | | - 'QuickQueryDialect', |
242 | | - 'ContainerSasPermissions', |
243 | | - 'BlobSasPermissions', |
244 | | - 'ResourceTypes', |
245 | | - 'AccountSasPermissions', |
246 | | - 'StorageStreamDownloader', |
247 | | - 'CustomerProvidedEncryptionKey', |
248 | | - 'RehydratePriority', |
249 | | - 'generate_account_sas', |
250 | | - 'generate_container_sas', |
251 | | - 'generate_blob_sas', |
252 | | - 'PartialBatchErrorException', |
253 | | - 'ContainerEncryptionScope', |
254 | | - 'BlobQueryError', |
255 | | - 'DelimitedJsonDialect', |
256 | | - 'DelimitedTextDialect', |
257 | | - 'ArrowDialect', |
258 | | - 'ArrowType', |
259 | | - 'BlobQueryReader', |
260 | | - 'ObjectReplicationPolicy', |
261 | | - 'ObjectReplicationRule', |
262 | | - 'Services', |
| 28 | + "BlobClient", |
263 | 29 | ] |
| 30 | +__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore |
| 31 | + |
| 32 | +_patch_sdk() |
0 commit comments