88# --------------------------------------------------------------------------
99from io import IOBase
1010import sys
11- from typing import Any , AsyncIterable , Callable , Dict , IO , Optional , Type , TypeVar , Union , cast , overload
11+ from typing import Any , AsyncIterable , AsyncIterator , Callable , Dict , IO , Optional , Type , TypeVar , Union , cast , overload
1212import urllib .parse
1313
1414from azure .core .async_paging import AsyncItemPaged , AsyncList
1818 ResourceExistsError ,
1919 ResourceNotFoundError ,
2020 ResourceNotModifiedError ,
21+ StreamClosedError ,
22+ StreamConsumedError ,
2123 map_error ,
2224)
2325from azure .core .pipeline import PipelineResponse
24- from azure .core .pipeline .transport import AsyncHttpResponse
2526from azure .core .polling import AsyncLROPoller , AsyncNoPolling , AsyncPollingMethod
26- from azure .core .rest import HttpRequest
27+ from azure .core .rest import AsyncHttpResponse , HttpRequest
2728from azure .core .tracing .decorator import distributed_trace
2829from azure .core .tracing .decorator_async import distributed_trace_async
2930from azure .core .utils import case_insensitive_dict
3031from azure .mgmt .core .exceptions import ARMErrorFormat
3132from azure .mgmt .core .polling .async_arm_polling import AsyncARMPolling
3233
3334from ... import models as _models
34- from ..._vendor import _convert_request
3535from ...operations ._addons_operations import (
3636 build_create_or_update_request ,
3737 build_delete_request ,
@@ -104,7 +104,6 @@ def prepare_request(next_link=None):
104104 headers = _headers ,
105105 params = _params ,
106106 )
107- _request = _convert_request (_request )
108107 _request .url = self ._client .format_url (_request .url )
109108
110109 else :
@@ -120,7 +119,6 @@ def prepare_request(next_link=None):
120119 _request = HttpRequest (
121120 "GET" , urllib .parse .urljoin (next_link , _parsed_next_link .path ), params = _next_request_params
122121 )
123- _request = _convert_request (_request )
124122 _request .url = self ._client .format_url (_request .url )
125123 _request .method = "GET"
126124 return _request
@@ -190,7 +188,6 @@ async def get(
190188 headers = _headers ,
191189 params = _params ,
192190 )
193- _request = _convert_request (_request )
194191 _request .url = self ._client .format_url (_request .url )
195192
196193 _stream = False
@@ -205,7 +202,7 @@ async def get(
205202 error = self ._deserialize .failsafe_deserialize (_models .ErrorResponse , pipeline_response )
206203 raise HttpResponseError (response = response , model = error , error_format = ARMErrorFormat )
207204
208- deserialized = self ._deserialize ("Addon" , pipeline_response )
205+ deserialized = self ._deserialize ("Addon" , pipeline_response . http_response )
209206
210207 if cls :
211208 return cls (pipeline_response , deserialized , {}) # type: ignore
@@ -219,7 +216,7 @@ async def _create_or_update_initial(
219216 addon_name : str ,
220217 addon : Union [_models .Addon , IO [bytes ]],
221218 ** kwargs : Any
222- ) -> _models . Addon :
219+ ) -> AsyncIterator [ bytes ] :
223220 error_map : MutableMapping [int , Type [HttpResponseError ]] = {
224221 401 : ClientAuthenticationError ,
225222 404 : ResourceNotFoundError ,
@@ -233,7 +230,7 @@ async def _create_or_update_initial(
233230
234231 api_version : str = kwargs .pop ("api_version" , _params .pop ("api-version" , self ._config .api_version ))
235232 content_type : Optional [str ] = kwargs .pop ("content_type" , _headers .pop ("Content-Type" , None ))
236- cls : ClsType [_models . Addon ] = kwargs .pop ("cls" , None )
233+ cls : ClsType [AsyncIterator [ bytes ] ] = kwargs .pop ("cls" , None )
237234
238235 content_type = content_type or "application/json"
239236 _json = None
@@ -255,29 +252,30 @@ async def _create_or_update_initial(
255252 headers = _headers ,
256253 params = _params ,
257254 )
258- _request = _convert_request (_request )
259255 _request .url = self ._client .format_url (_request .url )
260256
261- _stream = False
257+ _decompress = kwargs .pop ("decompress" , True )
258+ _stream = True
262259 pipeline_response : PipelineResponse = await self ._client ._pipeline .run ( # pylint: disable=protected-access
263260 _request , stream = _stream , ** kwargs
264261 )
265262
266263 response = pipeline_response .http_response
267264
268265 if response .status_code not in [200 , 201 ]:
266+ try :
267+ await response .read () # Load the body in memory and close the socket
268+ except (StreamConsumedError , StreamClosedError ):
269+ pass
269270 map_error (status_code = response .status_code , response = response , error_map = error_map )
270271 error = self ._deserialize .failsafe_deserialize (_models .ErrorResponse , pipeline_response )
271272 raise HttpResponseError (response = response , model = error , error_format = ARMErrorFormat )
272273
273274 response_headers = {}
274- if response .status_code == 200 :
275- deserialized = self ._deserialize ("Addon" , pipeline_response )
276-
277275 if response .status_code == 201 :
278276 response_headers ["Retry-After" ] = self ._deserialize ("int" , response .headers .get ("Retry-After" ))
279277
280- deserialized = self . _deserialize ( "Addon" , pipeline_response )
278+ deserialized = response . stream_download ( self . _client . _pipeline , decompress = _decompress )
281279
282280 if cls :
283281 return cls (pipeline_response , deserialized , response_headers ) # type: ignore
@@ -390,10 +388,11 @@ async def begin_create_or_update(
390388 params = _params ,
391389 ** kwargs
392390 )
391+ await raw_result .http_response .read () # type: ignore
393392 kwargs .pop ("error_map" , None )
394393
395394 def get_long_running_output (pipeline_response ):
396- deserialized = self ._deserialize ("Addon" , pipeline_response )
395+ deserialized = self ._deserialize ("Addon" , pipeline_response . http_response )
397396 if cls :
398397 return cls (pipeline_response , deserialized , {}) # type: ignore
399398 return deserialized
@@ -418,9 +417,9 @@ def get_long_running_output(pipeline_response):
418417 self ._client , raw_result , get_long_running_output , polling_method # type: ignore
419418 )
420419
421- async def _delete_initial ( # pylint: disable=inconsistent-return-statements
420+ async def _delete_initial (
422421 self , resource_group_name : str , private_cloud_name : str , addon_name : str , ** kwargs : Any
423- ) -> None :
422+ ) -> AsyncIterator [ bytes ] :
424423 error_map : MutableMapping [int , Type [HttpResponseError ]] = {
425424 401 : ClientAuthenticationError ,
426425 404 : ResourceNotFoundError ,
@@ -433,7 +432,7 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements
433432 _params = case_insensitive_dict (kwargs .pop ("params" , {}) or {})
434433
435434 api_version : str = kwargs .pop ("api_version" , _params .pop ("api-version" , self ._config .api_version ))
436- cls : ClsType [None ] = kwargs .pop ("cls" , None )
435+ cls : ClsType [AsyncIterator [ bytes ] ] = kwargs .pop ("cls" , None )
437436
438437 _request = build_delete_request (
439438 resource_group_name = resource_group_name ,
@@ -444,17 +443,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements
444443 headers = _headers ,
445444 params = _params ,
446445 )
447- _request = _convert_request (_request )
448446 _request .url = self ._client .format_url (_request .url )
449447
450- _stream = False
448+ _decompress = kwargs .pop ("decompress" , True )
449+ _stream = True
451450 pipeline_response : PipelineResponse = await self ._client ._pipeline .run ( # pylint: disable=protected-access
452451 _request , stream = _stream , ** kwargs
453452 )
454453
455454 response = pipeline_response .http_response
456455
457456 if response .status_code not in [200 , 202 , 204 ]:
457+ try :
458+ await response .read () # Load the body in memory and close the socket
459+ except (StreamConsumedError , StreamClosedError ):
460+ pass
458461 map_error (status_code = response .status_code , response = response , error_map = error_map )
459462 error = self ._deserialize .failsafe_deserialize (_models .ErrorResponse , pipeline_response )
460463 raise HttpResponseError (response = response , model = error , error_format = ARMErrorFormat )
@@ -464,8 +467,12 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements
464467 response_headers ["Location" ] = self ._deserialize ("str" , response .headers .get ("Location" ))
465468 response_headers ["Retry-After" ] = self ._deserialize ("int" , response .headers .get ("Retry-After" ))
466469
470+ deserialized = response .stream_download (self ._client ._pipeline , decompress = _decompress )
471+
467472 if cls :
468- return cls (pipeline_response , None , response_headers ) # type: ignore
473+ return cls (pipeline_response , deserialized , response_headers ) # type: ignore
474+
475+ return deserialized # type: ignore
469476
470477 @distributed_trace_async
471478 async def begin_delete (
@@ -493,7 +500,7 @@ async def begin_delete(
493500 lro_delay = kwargs .pop ("polling_interval" , self ._config .polling_interval )
494501 cont_token : Optional [str ] = kwargs .pop ("continuation_token" , None )
495502 if cont_token is None :
496- raw_result = await self ._delete_initial ( # type: ignore
503+ raw_result = await self ._delete_initial (
497504 resource_group_name = resource_group_name ,
498505 private_cloud_name = private_cloud_name ,
499506 addon_name = addon_name ,
@@ -503,6 +510,7 @@ async def begin_delete(
503510 params = _params ,
504511 ** kwargs
505512 )
513+ await raw_result .http_response .read () # type: ignore
506514 kwargs .pop ("error_map" , None )
507515
508516 def get_long_running_output (pipeline_response ): # pylint: disable=inconsistent-return-statements
0 commit comments