Skip to content

Commit bef6013

Browse files
Update generated (Azure#16049)
Use more generated code for config and pipeline creation
1 parent 8f9baf8 commit bef6013

15 files changed

+210
-223
lines changed

sdk/tables/azure-data-tables/azure/data/tables/_base_client.py

Lines changed: 23 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from azure.core.exceptions import ClientAuthenticationError, ResourceNotFoundError
3131
from azure.core.pipeline import Pipeline
3232
from azure.core.pipeline.transport import (
33-
RequestsTransport,
3433
HttpTransport,
3534
HttpRequest,
3635
)
@@ -66,7 +65,6 @@
6665
from ._models import BatchErrorException
6766
from ._sdk_moniker import SDK_MONIKER
6867

69-
7068
_LOGGER = logging.getLogger(__name__)
7169
_SERVICE_PARAMS = {
7270
"blob": {"primary": "BlobEndpoint", "secondary": "BlobSecondaryEndpoint"},
@@ -124,9 +122,27 @@ def __init__(
124122
self.require_encryption = kwargs.get("require_encryption", False)
125123
self.key_encryption_key = kwargs.get("key_encryption_key")
126124
self.key_resolver_function = kwargs.get("key_resolver_function")
127-
self._config, self._pipeline = self._create_pipeline(
128-
self.credential, storage_sdk=service, **kwargs
129-
)
125+
126+
self._configure_credential(self.credential)
127+
kwargs.setdefault("connection_timeout", CONNECTION_TIMEOUT)
128+
kwargs.setdefault("read_timeout", READ_TIMEOUT)
129+
130+
self._policies = [
131+
StorageHeadersPolicy(**kwargs),
132+
ProxyPolicy(**kwargs),
133+
UserAgentPolicy(sdk_moniker=SDK_MONIKER, **kwargs),
134+
StorageContentValidation(),
135+
StorageRequestHook(**kwargs),
136+
self._credential_policy,
137+
ContentDecodePolicy(response_encoding="utf-8"),
138+
RedirectPolicy(**kwargs),
139+
StorageHosts(hosts=self._hosts, **kwargs),
140+
kwargs.get("retry_policy") or TablesRetryPolicy(**kwargs),
141+
StorageLoggingPolicy(**kwargs),
142+
StorageResponseHook(**kwargs),
143+
DistributedTracingPolicy(**kwargs),
144+
HttpLoggingPolicy(**kwargs),
145+
]
130146

131147
def __enter__(self):
132148
self._client.__enter__()
@@ -233,7 +249,7 @@ def _format_query_string(
233249
credential = None
234250
return query_str.rstrip("?&"), credential
235251

236-
def _create_pipeline(self, credential, **kwargs):
252+
def _configure_credential(self, credential):
237253
# type: (Any, **Any) -> Tuple[Configuration, Pipeline]
238254
self._credential_policy = None
239255
if hasattr(credential, "get_token"):
@@ -245,32 +261,6 @@ def _create_pipeline(self, credential, **kwargs):
245261
elif credential is not None:
246262
raise TypeError("Unsupported credential: {}".format(credential))
247263

248-
config = kwargs.get("_configuration") or create_configuration(**kwargs)
249-
if kwargs.get("_pipeline"):
250-
return config, kwargs["_pipeline"]
251-
config.transport = kwargs.get("transport") # type: ignore
252-
kwargs.setdefault("connection_timeout", CONNECTION_TIMEOUT)
253-
kwargs.setdefault("read_timeout", READ_TIMEOUT)
254-
if not config.transport:
255-
config.transport = RequestsTransport(**kwargs)
256-
policies = [
257-
config.headers_policy,
258-
config.proxy_policy,
259-
config.user_agent_policy,
260-
StorageContentValidation(),
261-
StorageRequestHook(**kwargs),
262-
self._credential_policy,
263-
ContentDecodePolicy(response_encoding="utf-8"),
264-
RedirectPolicy(**kwargs),
265-
StorageHosts(hosts=self._hosts, **kwargs),
266-
config.retry_policy,
267-
config.logging_policy,
268-
StorageResponseHook(**kwargs),
269-
DistributedTracingPolicy(**kwargs),
270-
HttpLoggingPolicy(**kwargs),
271-
]
272-
return config, Pipeline(config.transport, policies=policies)
273-
274264
def _batch_send( # pylint: disable=inconsistent-return-statements
275265
self,
276266
entities, # type: List[TableEntity]
@@ -302,7 +292,7 @@ def _batch_send( # pylint: disable=inconsistent-return-statements
302292
boundary="batch_{}".format(uuid4()),
303293
)
304294

305-
pipeline_response = self._pipeline.run(request, **kwargs)
295+
pipeline_response = self._client._client._pipeline.run(request, **kwargs) # pylint:disable=protected-access
306296
response = pipeline_response.http_response
307297

308298
if response.status_code == 403:
@@ -461,39 +451,6 @@ def parse_connection_str(conn_str, credential, service, keyword_args):
461451
return primary, credential
462452

463453

464-
def create_configuration(**kwargs):
465-
# type: (**Any) -> Configuration
466-
config = Configuration(**kwargs)
467-
config.headers_policy = StorageHeadersPolicy(**kwargs)
468-
config.user_agent_policy = UserAgentPolicy(sdk_moniker=SDK_MONIKER, **kwargs)
469-
# sdk_moniker="storage-{}/{}".format(kwargs.pop('storage_sdk'), VERSION), **kwargs)
470-
config.retry_policy = kwargs.get("retry_policy") or TablesRetryPolicy(**kwargs)
471-
config.logging_policy = StorageLoggingPolicy(**kwargs)
472-
config.proxy_policy = ProxyPolicy(**kwargs)
473-
474-
# Storage settings
475-
config.max_single_put_size = kwargs.get("max_single_put_size", 64 * 1024 * 1024)
476-
config.copy_polling_interval = 15
477-
478-
# Block blob uploads
479-
config.max_block_size = kwargs.get("max_block_size", 4 * 1024 * 1024)
480-
config.min_large_block_upload_threshold = kwargs.get(
481-
"min_large_block_upload_threshold", 4 * 1024 * 1024 + 1
482-
)
483-
config.use_byte_buffer = kwargs.get("use_byte_buffer", False)
484-
485-
# Page blob uploads
486-
config.max_page_size = kwargs.get("max_page_size", 4 * 1024 * 1024)
487-
488-
# Blob downloads
489-
config.max_single_get_size = kwargs.get("max_single_get_size", 32 * 1024 * 1024)
490-
config.max_chunk_get_size = kwargs.get("max_chunk_get_size", 4 * 1024 * 1024)
491-
492-
# File uploads
493-
config.max_range_size = kwargs.get("max_range_size", 4 * 1024 * 1024)
494-
return config
495-
496-
497454
def parse_query(query_str):
498455
sas_values = QueryStringConstants.to_list()
499456
parsed_query = {k: v[0] for k, v in parse_qs(query_str).items()}

sdk/tables/azure-data-tables/azure/data/tables/_generated/_azure_table.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __init__(
4444

4545
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
4646
self._serialize = Serializer(client_models)
47+
self._serialize.client_side_validation = False
4748
self._deserialize = Deserializer(client_models)
4849

4950
self.table = TableOperations(

sdk/tables/azure-data-tables/azure/data/tables/_generated/aio/_azure_table.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(
3939

4040
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
4141
self._serialize = Serializer(client_models)
42+
self._serialize.client_side_validation = False
4243
self._deserialize = Deserializer(client_models)
4344

4445
self.table = TableOperations(

sdk/tables/azure-data-tables/azure/data/tables/_generated/aio/operations/_service_operations.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from azure.core.pipeline import PipelineResponse
1313
from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
1414

15-
from ... import models
15+
from ... import models as _models
1616

1717
T = TypeVar('T')
1818
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]
@@ -31,7 +31,7 @@ class ServiceOperations:
3131
:param deserializer: An object model deserializer.
3232
"""
3333

34-
models = models
34+
models = _models
3535

3636
def __init__(self, client, config, serializer, deserializer) -> None:
3737
self._client = client
@@ -41,7 +41,7 @@ def __init__(self, client, config, serializer, deserializer) -> None:
4141

4242
async def set_properties(
4343
self,
44-
table_service_properties: "models.TableServiceProperties",
44+
table_service_properties: "_models.TableServiceProperties",
4545
timeout: Optional[int] = None,
4646
request_id_parameter: Optional[str] = None,
4747
**kwargs
@@ -102,7 +102,7 @@ async def set_properties(
102102

103103
if response.status_code not in [202]:
104104
map_error(status_code=response.status_code, response=response, error_map=error_map)
105-
error = self._deserialize(models.TableServiceError, response)
105+
error = self._deserialize(_models.TableServiceError, response)
106106
raise HttpResponseError(response=response, model=error)
107107

108108
response_headers = {}
@@ -120,7 +120,7 @@ async def get_properties(
120120
timeout: Optional[int] = None,
121121
request_id_parameter: Optional[str] = None,
122122
**kwargs
123-
) -> "models.TableServiceProperties":
123+
) -> "_models.TableServiceProperties":
124124
"""Gets the properties of an account's Table service, including properties for Analytics and CORS
125125
(Cross-Origin Resource Sharing) rules.
126126
@@ -134,7 +134,7 @@ async def get_properties(
134134
:rtype: ~azure.data.tables.models.TableServiceProperties
135135
:raises: ~azure.core.exceptions.HttpResponseError
136136
"""
137-
cls = kwargs.pop('cls', None) # type: ClsType["models.TableServiceProperties"]
137+
cls = kwargs.pop('cls', None) # type: ClsType["_models.TableServiceProperties"]
138138
error_map = {
139139
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
140140
}
@@ -170,7 +170,7 @@ async def get_properties(
170170

171171
if response.status_code not in [200]:
172172
map_error(status_code=response.status_code, response=response, error_map=error_map)
173-
error = self._deserialize(models.TableServiceError, response)
173+
error = self._deserialize(_models.TableServiceError, response)
174174
raise HttpResponseError(response=response, model=error)
175175

176176
response_headers = {}
@@ -190,7 +190,7 @@ async def get_statistics(
190190
timeout: Optional[int] = None,
191191
request_id_parameter: Optional[str] = None,
192192
**kwargs
193-
) -> "models.TableServiceStats":
193+
) -> "_models.TableServiceStats":
194194
"""Retrieves statistics related to replication for the Table service. It is only available on the
195195
secondary location endpoint when read-access geo-redundant replication is enabled for the
196196
account.
@@ -205,7 +205,7 @@ async def get_statistics(
205205
:rtype: ~azure.data.tables.models.TableServiceStats
206206
:raises: ~azure.core.exceptions.HttpResponseError
207207
"""
208-
cls = kwargs.pop('cls', None) # type: ClsType["models.TableServiceStats"]
208+
cls = kwargs.pop('cls', None) # type: ClsType["_models.TableServiceStats"]
209209
error_map = {
210210
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
211211
}
@@ -241,7 +241,7 @@ async def get_statistics(
241241

242242
if response.status_code not in [200]:
243243
map_error(status_code=response.status_code, response=response, error_map=error_map)
244-
error = self._deserialize(models.TableServiceError, response)
244+
error = self._deserialize(_models.TableServiceError, response)
245245
raise HttpResponseError(response=response, model=error)
246246

247247
response_headers = {}

0 commit comments

Comments
 (0)