1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # --------------------------------------------------------------------------
1
6
import functools
2
7
from typing import (
3
- Union ,
4
- Optional ,
8
+ Union ,
5
9
Any ,
6
- Dict ,
7
- List
8
10
)
9
11
10
12
from azure .core .async_paging import AsyncItemPaged
14
16
from azure .data .tables import VERSION
15
17
from azure .data .tables ._entity import TableEntity
16
18
from azure .data .tables ._generated .aio ._azure_table_async import AzureTable
17
- from azure .data .tables ._generated .models import SignedIdentifier , TableProperties , QueryOptions , TableServiceProperties
19
+ from azure .data .tables ._generated .models import SignedIdentifier , TableProperties , QueryOptions
18
20
from azure .data .tables ._models import AccessPolicy
19
- from azure .data .tables ._shared .base_client import parse_connection_str
20
21
from azure .data .tables ._shared .base_client_async import AsyncStorageAccountHostsMixin
21
22
from azure .data .tables ._shared .policies_async import ExponentialRetry
22
23
from azure .data .tables ._shared .request_handlers import serialize_iso
23
24
from azure .data .tables ._shared .response_handlers import return_headers_and_deserialized , process_table_error
24
25
25
- from .._models import UpdateMode
26
+ from .._models import UpdateMode
26
27
from ._models import TableEntityPropertiesPaged
27
28
from .._deserialize import _convert_to_entity
28
29
from .._serialize import _add_entity_properties , _get_match_headers
29
30
from .._shared ._table_client_base import TableClientBase
30
31
31
32
32
33
class TableClient (AsyncStorageAccountHostsMixin , TableClientBase ):
33
- """A client to interact with a specific Queue.
34
-
35
- :param str account_url:
36
- The URL to the storage account. In order to create a client given the full URI to the queue,
37
- use the :func:`from_queue_url` classmethod.
38
- :param queue_name: The name of the queue.
39
- :type queue_name: str
40
- :param credential:
41
- The credentials with which to authenticate. This is optional if the
42
- account URL already has a SAS token. The value can be a SAS token string, an account
43
- shared access key.
44
- :keyword str api_version:
45
- The Storage API version to use for requests. Default value is '2019-07-07'.
46
- Setting to an older version may result in reduced feature compatibility.
47
- :keyword str secondary_hostname:
48
- The hostname of the secondary endpoint.
49
- :keyword message_encode_policy: The encoding policy to use on outgoing messages.
50
- Default is not to encode messages. Other options include :class:`TextBase64EncodePolicy`,
51
- :class:`BinaryBase64EncodePolicy` or `None`.
52
- :keyword message_decode_policy: The decoding policy to use on incoming messages.
53
- Default value is not to decode messages. Other options include :class:`TextBase64DecodePolicy`,
54
- :class:`BinaryBase64DecodePolicy` or `None`.
55
-
56
- """
34
+ """ :ivar str account_name: Name of the storage account (Cosmos or Azure)"""
57
35
58
36
def __init__ (
59
37
self ,
60
- account_url : str ,
61
- table_name : str ,
62
- credential : Optional [Any ]= None ,
63
- ** kwargs : Any
64
- ) -> None :
38
+ account_url , # type: str
39
+ table_name , # type: str
40
+ credential , # type : Optional[Any]=None
41
+ ** kwargs # type: Any
42
+ ):
43
+ # type: (...) -> None
44
+ """Create TableClient from a Credential.
45
+
46
+ :param account_url:
47
+ A url to an Azure Storage account.
48
+ :type account_url: str
49
+ :param table_name: The table name.
50
+ :type table_name: str
51
+ :param credential:
52
+ The credentials with which to authenticate. This is optional if the
53
+ account URL already has a SAS token, or the connection string already has shared
54
+ access key values. The value can be a SAS token string, an account shared access
55
+ key, or an instance of a TokenCredentials class from azure.identity.
56
+ :type credential: Union[str,TokenCredential]
57
+
58
+ :returns: None
59
+ """
65
60
kwargs ["retry_policy" ] = kwargs .get ("retry_policy" ) or ExponentialRetry (** kwargs )
66
61
loop = kwargs .pop ('loop' , None )
67
62
super (TableClient , self ).__init__ (
68
63
account_url , table_name = table_name , credential = credential , loop = loop , ** kwargs
69
64
)
70
65
self ._client = AzureTable (self .url , pipeline = self ._pipeline , loop = loop )
71
- self ._client ._config .version = kwargs .get ('api_version' , VERSION )
66
+ self ._client ._config .version = kwargs .get ('api_version' , VERSION ) # pylint: disable = W0212
72
67
self ._loop = loop
73
68
74
69
@distributed_trace_async
75
70
async def get_table_access_policy (
76
71
self ,
77
- ** kwargs : Any
78
- ) -> Dict [str ,AccessPolicy ]:
79
- """Retrieves details about any stored access policies specified on the table that may be
72
+ ** kwargs # type: Any
73
+ ):
74
+ # type: (...) -> dict[str,AccessPolicy]
75
+ """
76
+ Retrieves details about any stored access policies specified on the table that may be
80
77
used with Shared Access Signatures.
81
78
:return: Dictionary of SignedIdentifiers
82
79
:rtype: dict[str,~azure.data.tables.AccessPolicy]
@@ -126,8 +123,9 @@ async def set_table_access_policy(
126
123
@distributed_trace_async
127
124
async def create_table (
128
125
self ,
129
- ** kwargs : Any
130
- ) -> str :
126
+ ** kwargs # type: Any
127
+ ):
128
+ # type: (...) -> str
131
129
"""Creates a new table under the given account.
132
130
:return: Table created
133
131
:rtype: str
@@ -140,8 +138,9 @@ async def create_table(
140
138
@distributed_trace_async
141
139
async def delete_table (
142
140
self ,
143
- ** kwargs : Any
144
- ) -> None :
141
+ ** kwargs # type: Any
142
+ ):
143
+ # type: (...) -> None
145
144
"""Creates a new table under the given account.
146
145
:return: None
147
146
:rtype: None
@@ -151,10 +150,11 @@ async def delete_table(
151
150
@distributed_trace_async
152
151
async def delete_entity (
153
152
self ,
154
- partition_key : str ,
155
- row_key : str ,
156
- ** kwargs : Any
157
- ) -> None :
153
+ partition_key , # type: str
154
+ row_key , # type: str
155
+ ** kwargs # type: Any
156
+ ):
157
+ # type: (...) -> None
158
158
"""Deletes the specified entity in a table.
159
159
:param partition_key: The partition key of the entity.
160
160
:type partition_key: str
@@ -168,7 +168,7 @@ async def delete_entity(
168
168
"""
169
169
if_match , if_not_match = _get_match_headers (kwargs = dict (kwargs , etag = kwargs .pop ('etag' , None ),
170
170
match_condition = kwargs .pop ('match_condition' , None )),
171
- etag_param = 'etag' , match_param = 'match_condition' )
171
+ etag_param = 'etag' , match_param = 'match_condition' )
172
172
173
173
await self ._client .table .delete_entity (
174
174
table = self .table_name ,
@@ -180,9 +180,10 @@ async def delete_entity(
180
180
@distributed_trace_async
181
181
async def create_entity (
182
182
self ,
183
- entity : Dict [str ,str ],
184
- ** kwargs : Any
185
- ) -> Union [Dict [str ,str ], TableEntity ]:
183
+ entity , # type: Union[TableEntity, dict[str,str]]
184
+ ** kwargs # type: Any
185
+ ):
186
+ # type: (...) -> TableEntity
186
187
"""Insert entity in a table.
187
188
:param entity: The properties for the table entity.
188
189
:type entity: dict[str, str]
@@ -203,17 +204,18 @@ async def create_entity(
203
204
** kwargs
204
205
)
205
206
properties = _convert_to_entity (inserted_entity )
206
- return properties
207
- except ResourceNotFoundError as error :
207
+ return properties
208
+ except ResourceNotFoundError as error :
208
209
process_table_error (error )
209
210
210
211
@distributed_trace_async
211
- async def update_entity (
212
+ async def update_entity (
212
213
self ,
213
- entity : Dict [str ,str ],
214
- mode : UpdateMode = UpdateMode .MERGE ,
215
- ** kwargs : Any
216
- ) -> None :
214
+ entity , # type: Union[TableEntity, dict[str,str]]
215
+ mode = UpdateMode .MERGE , # type: UpdateMode
216
+ ** kwargs # type: Any
217
+ ):
218
+ # type: (...) -> None
217
219
"""Update entity in a table.
218
220
:param mode: Merge or Replace entity
219
221
:type mode: ~azure.data.tables.UpdateMode
@@ -231,8 +233,8 @@ async def update_entity(
231
233
:rtype: None
232
234
:raises: ~azure.core.exceptions.HttpResponseError
233
235
"""
234
- if_match , if_not_match = _get_match_headers (kwargs = dict (kwargs , etag = kwargs .pop ('etag' , None ),
235
- match_condition = kwargs .pop ('match_condition' , None )),
236
+ if_match , if_not_match = _get_match_headers (kwargs = dict (kwargs , etag = kwargs .pop ('etag' , None ),
237
+ match_condition = kwargs .pop ('match_condition' , None )),
236
238
etag_param = 'etag' , match_param = 'match_condition' )
237
239
238
240
partition_key = entity ['PartitionKey' ]
@@ -256,9 +258,10 @@ async def update_entity(
256
258
257
259
@distributed_trace
258
260
def list_entities (
259
- self ,
260
- ** kwargs : Any
261
- ) -> AsyncItemPaged [TableEntity ]:
261
+ self ,
262
+ ** kwargs # type: Any
263
+ ):
264
+ # type: (...) -> AsyncItemPaged[TableEntity]
262
265
"""Lists entities in a table.
263
266
264
267
:keyword int results_per_page: Number of entities per page in return ItemPaged
@@ -284,9 +287,10 @@ def list_entities(
284
287
@distributed_trace
285
288
def query_entities (
286
289
self ,
287
- filter : List [str ],
288
- ** kwargs : Any
289
- ) -> AsyncItemPaged [TableEntity ]:
290
+ filter , # type: str # pylint: disable = W0622
291
+ ** kwargs
292
+ ):
293
+ # type: (...) -> AsyncItemPaged[TableEntity]
290
294
"""Lists entities in a table.
291
295
292
296
:param str filter: Specify a filter to return certain entities
@@ -298,7 +302,7 @@ def query_entities(
298
302
:raises: ~azure.core.exceptions.HttpResponseError
299
303
"""
300
304
parameters = kwargs .pop ('parameters' , None )
301
- filter = self ._parameter_filter_substitution (parameters , filter ) # pylint: disable = W0622
305
+ filter = self ._parameter_filter_substitution (parameters , filter ) # pylint: disable = W0622
302
306
303
307
user_select = kwargs .pop ('select' , None )
304
308
if user_select and not isinstance (user_select , str ):
@@ -319,10 +323,11 @@ def query_entities(
319
323
@distributed_trace_async
320
324
async def get_entity (
321
325
self ,
322
- partition_key : str ,
323
- row_key : str ,
324
- ** kwargs : Any
325
- ) -> TableEntity :
326
+ partition_key , # type: str
327
+ row_key , # type: str
328
+ ** kwargs # type: Any
329
+ ):
330
+ # type: (...) -> TableEntity
326
331
"""Queries entities in a table.
327
332
:param partition_key: The partition key of the entity.
328
333
:type partition_key: str
@@ -338,25 +343,22 @@ async def get_entity(
338
343
row_key = row_key ,
339
344
** kwargs )
340
345
properties = _convert_to_entity (entity .additional_properties )
341
- return properties
346
+ return properties
342
347
343
348
@distributed_trace_async
344
- async def upsert_entity (
349
+ async def upsert_entity (
345
350
self ,
346
- entity : Dict [str ,str ],
347
- mode : UpdateMode = UpdateMode .MERGE ,
348
- ** kwargs : Any
349
- ) -> None :
351
+ entity , # type: Union[TableEntity, dict[str,str]]
352
+ mode = UpdateMode .MERGE , # type: UpdateMode
353
+ ** kwargs # type: Any
354
+ ):
355
+ # type: (...) -> None
350
356
351
357
"""Update/Merge or Insert entity into table.
352
358
:param mode: Merge or Replace and Insert on fail
353
359
:type mode: ~azure.data.tables.UpdateMode
354
360
:param entity: The properties for the table entity.
355
361
:type entity: dict[str, str]
356
- :param partition_key: The partition key of the entity.
357
- :type partition_key: str
358
- :param row_key: The row key of the entity.
359
- :type row_key: str
360
362
:return: Entity mapping str to azure.data.tables.EntityProperty or None
361
363
:rtype: None
362
364
:raises: ~azure.core.exceptions.HttpResponseError
@@ -385,9 +387,9 @@ async def upsert_entity(
385
387
else :
386
388
raise ValueError ('Mode type is not supported' )
387
389
except ResourceNotFoundError :
388
- await self .create_entity (
389
- partition_key = partition_key ,
390
- row_key = row_key ,
391
- table_entity_properties = entity ,
392
- ** kwargs
393
- )
390
+ await self .create_entity (
391
+ partition_key = partition_key ,
392
+ row_key = row_key ,
393
+ table_entity_properties = entity ,
394
+ ** kwargs
395
+ )
0 commit comments