77# Changes may cause incorrect behavior and will be lost if the code is regenerated.
88# --------------------------------------------------------------------------
99from io import IOBase
10- from typing import Any , AsyncIterable , Callable , Dict , IO , Optional , TypeVar , Union , cast , overload
10+ import sys
11+ from typing import Any , AsyncIterable , AsyncIterator , Callable , Dict , IO , Optional , Type , TypeVar , Union , cast , overload
1112import urllib .parse
1213
1314from azure .core .async_paging import AsyncItemPaged , AsyncList
1718 ResourceExistsError ,
1819 ResourceNotFoundError ,
1920 ResourceNotModifiedError ,
21+ StreamClosedError ,
22+ StreamConsumedError ,
2023 map_error ,
2124)
2225from azure .core .pipeline import PipelineResponse
23- from azure .core .pipeline .transport import AsyncHttpResponse
2426from azure .core .polling import AsyncLROPoller , AsyncNoPolling , AsyncPollingMethod
25- from azure .core .rest import HttpRequest
27+ from azure .core .rest import AsyncHttpResponse , HttpRequest
2628from azure .core .tracing .decorator import distributed_trace
2729from azure .core .tracing .decorator_async import distributed_trace_async
2830from azure .core .utils import case_insensitive_dict
2931from azure .mgmt .core .exceptions import ARMErrorFormat
3032from azure .mgmt .core .polling .async_arm_polling import AsyncARMPolling
3133
3234from ... import models as _models
33- from ..._vendor import _convert_request
3435from ...operations ._ca_certificates_operations import (
3536 build_create_or_update_request ,
3637 build_delete_request ,
3738 build_get_request ,
3839 build_list_by_namespace_request ,
3940)
4041
42+ if sys .version_info >= (3 , 9 ):
43+ from collections .abc import MutableMapping
44+ else :
45+ from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports
4146T = TypeVar ("T" )
4247ClsType = Optional [Callable [[PipelineResponse [HttpRequest , AsyncHttpResponse ], T , Dict [str , Any ]], Any ]]
4348
@@ -80,7 +85,7 @@ async def get(
8085 :rtype: ~azure.mgmt.eventgrid.models.CaCertificate
8186 :raises ~azure.core.exceptions.HttpResponseError:
8287 """
83- error_map = {
88+ error_map : MutableMapping [ int , Type [ HttpResponseError ]] = {
8489 401 : ClientAuthenticationError ,
8590 404 : ResourceNotFoundError ,
8691 409 : ResourceExistsError ,
@@ -103,7 +108,6 @@ async def get(
103108 headers = _headers ,
104109 params = _params ,
105110 )
106- _request = _convert_request (_request )
107111 _request .url = self ._client .format_url (_request .url )
108112
109113 _stream = False
@@ -118,7 +122,7 @@ async def get(
118122 error = self ._deserialize .failsafe_deserialize (_models .ErrorResponse , pipeline_response )
119123 raise HttpResponseError (response = response , model = error , error_format = ARMErrorFormat )
120124
121- deserialized = self ._deserialize ("CaCertificate" , pipeline_response )
125+ deserialized = self ._deserialize ("CaCertificate" , pipeline_response . http_response )
122126
123127 if cls :
124128 return cls (pipeline_response , deserialized , {}) # type: ignore
@@ -132,8 +136,8 @@ async def _create_or_update_initial(
132136 ca_certificate_name : str ,
133137 ca_certificate_info : Union [_models .CaCertificate , IO [bytes ]],
134138 ** kwargs : Any
135- ) -> _models . CaCertificate :
136- error_map = {
139+ ) -> AsyncIterator [ bytes ] :
140+ error_map : MutableMapping [ int , Type [ HttpResponseError ]] = {
137141 401 : ClientAuthenticationError ,
138142 404 : ResourceNotFoundError ,
139143 409 : ResourceExistsError ,
@@ -146,7 +150,7 @@ async def _create_or_update_initial(
146150
147151 api_version : str = kwargs .pop ("api_version" , _params .pop ("api-version" , self ._config .api_version ))
148152 content_type : Optional [str ] = kwargs .pop ("content_type" , _headers .pop ("Content-Type" , None ))
149- cls : ClsType [_models . CaCertificate ] = kwargs .pop ("cls" , None )
153+ cls : ClsType [AsyncIterator [ bytes ] ] = kwargs .pop ("cls" , None )
150154
151155 content_type = content_type or "application/json"
152156 _json = None
@@ -168,26 +172,26 @@ async def _create_or_update_initial(
168172 headers = _headers ,
169173 params = _params ,
170174 )
171- _request = _convert_request (_request )
172175 _request .url = self ._client .format_url (_request .url )
173176
174- _stream = False
177+ _decompress = kwargs .pop ("decompress" , True )
178+ _stream = True
175179 pipeline_response : PipelineResponse = await self ._client ._pipeline .run ( # pylint: disable=protected-access
176180 _request , stream = _stream , ** kwargs
177181 )
178182
179183 response = pipeline_response .http_response
180184
181185 if response .status_code not in [200 , 201 ]:
186+ try :
187+ await response .read () # Load the body in memory and close the socket
188+ except (StreamConsumedError , StreamClosedError ):
189+ pass
182190 map_error (status_code = response .status_code , response = response , error_map = error_map )
183191 error = self ._deserialize .failsafe_deserialize (_models .ErrorResponse , pipeline_response )
184192 raise HttpResponseError (response = response , model = error , error_format = ARMErrorFormat )
185193
186- if response .status_code == 200 :
187- deserialized = self ._deserialize ("CaCertificate" , pipeline_response )
188-
189- if response .status_code == 201 :
190- deserialized = self ._deserialize ("CaCertificate" , pipeline_response )
194+ deserialized = response .stream_download (self ._client ._pipeline , decompress = _decompress )
191195
192196 if cls :
193197 return cls (pipeline_response , deserialized , {}) # type: ignore
@@ -310,10 +314,11 @@ async def begin_create_or_update(
310314 params = _params ,
311315 ** kwargs
312316 )
317+ await raw_result .http_response .read () # type: ignore
313318 kwargs .pop ("error_map" , None )
314319
315320 def get_long_running_output (pipeline_response ):
316- deserialized = self ._deserialize ("CaCertificate" , pipeline_response )
321+ deserialized = self ._deserialize ("CaCertificate" , pipeline_response . http_response )
317322 if cls :
318323 return cls (pipeline_response , deserialized , {}) # type: ignore
319324 return deserialized
@@ -338,10 +343,10 @@ def get_long_running_output(pipeline_response):
338343 self ._client , raw_result , get_long_running_output , polling_method # type: ignore
339344 )
340345
341- async def _delete_initial ( # pylint: disable=inconsistent-return-statements
346+ async def _delete_initial (
342347 self , resource_group_name : str , namespace_name : str , ca_certificate_name : str , ** kwargs : Any
343- ) -> None :
344- error_map = {
348+ ) -> AsyncIterator [ bytes ] :
349+ error_map : MutableMapping [ int , Type [ HttpResponseError ]] = {
345350 401 : ClientAuthenticationError ,
346351 404 : ResourceNotFoundError ,
347352 409 : ResourceExistsError ,
@@ -353,7 +358,7 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements
353358 _params = case_insensitive_dict (kwargs .pop ("params" , {}) or {})
354359
355360 api_version : str = kwargs .pop ("api_version" , _params .pop ("api-version" , self ._config .api_version ))
356- cls : ClsType [None ] = kwargs .pop ("cls" , None )
361+ cls : ClsType [AsyncIterator [ bytes ] ] = kwargs .pop ("cls" , None )
357362
358363 _request = build_delete_request (
359364 resource_group_name = resource_group_name ,
@@ -364,17 +369,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements
364369 headers = _headers ,
365370 params = _params ,
366371 )
367- _request = _convert_request (_request )
368372 _request .url = self ._client .format_url (_request .url )
369373
370- _stream = False
374+ _decompress = kwargs .pop ("decompress" , True )
375+ _stream = True
371376 pipeline_response : PipelineResponse = await self ._client ._pipeline .run ( # pylint: disable=protected-access
372377 _request , stream = _stream , ** kwargs
373378 )
374379
375380 response = pipeline_response .http_response
376381
377382 if response .status_code not in [200 , 202 , 204 ]:
383+ try :
384+ await response .read () # Load the body in memory and close the socket
385+ except (StreamConsumedError , StreamClosedError ):
386+ pass
378387 map_error (status_code = response .status_code , response = response , error_map = error_map )
379388 error = self ._deserialize .failsafe_deserialize (_models .ErrorResponse , pipeline_response )
380389 raise HttpResponseError (response = response , model = error , error_format = ARMErrorFormat )
@@ -383,8 +392,12 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements
383392 if response .status_code == 202 :
384393 response_headers ["Location" ] = self ._deserialize ("str" , response .headers .get ("Location" ))
385394
395+ deserialized = response .stream_download (self ._client ._pipeline , decompress = _decompress )
396+
386397 if cls :
387- return cls (pipeline_response , None , response_headers ) # type: ignore
398+ return cls (pipeline_response , deserialized , response_headers ) # type: ignore
399+
400+ return deserialized # type: ignore
388401
389402 @distributed_trace_async
390403 async def begin_delete (
@@ -414,7 +427,7 @@ async def begin_delete(
414427 lro_delay = kwargs .pop ("polling_interval" , self ._config .polling_interval )
415428 cont_token : Optional [str ] = kwargs .pop ("continuation_token" , None )
416429 if cont_token is None :
417- raw_result = await self ._delete_initial ( # type: ignore
430+ raw_result = await self ._delete_initial (
418431 resource_group_name = resource_group_name ,
419432 namespace_name = namespace_name ,
420433 ca_certificate_name = ca_certificate_name ,
@@ -424,6 +437,7 @@ async def begin_delete(
424437 params = _params ,
425438 ** kwargs
426439 )
440+ await raw_result .http_response .read () # type: ignore
427441 kwargs .pop ("error_map" , None )
428442
429443 def get_long_running_output (pipeline_response ): # pylint: disable=inconsistent-return-statements
@@ -487,7 +501,7 @@ def list_by_namespace(
487501 api_version : str = kwargs .pop ("api_version" , _params .pop ("api-version" , self ._config .api_version ))
488502 cls : ClsType [_models .CaCertificatesListResult ] = kwargs .pop ("cls" , None )
489503
490- error_map = {
504+ error_map : MutableMapping [ int , Type [ HttpResponseError ]] = {
491505 401 : ClientAuthenticationError ,
492506 404 : ResourceNotFoundError ,
493507 409 : ResourceExistsError ,
@@ -508,7 +522,6 @@ def prepare_request(next_link=None):
508522 headers = _headers ,
509523 params = _params ,
510524 )
511- _request = _convert_request (_request )
512525 _request .url = self ._client .format_url (_request .url )
513526
514527 else :
@@ -524,7 +537,6 @@ def prepare_request(next_link=None):
524537 _request = HttpRequest (
525538 "GET" , urllib .parse .urljoin (next_link , _parsed_next_link .path ), params = _next_request_params
526539 )
527- _request = _convert_request (_request )
528540 _request .url = self ._client .format_url (_request .url )
529541 _request .method = "GET"
530542 return _request
0 commit comments