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 ._access_policy_assignment_operations import (
3636 build_create_update_request ,
3737 build_delete_request ,
@@ -73,7 +73,7 @@ async def _create_update_initial(
7373 access_policy_assignment_name : str ,
7474 parameters : Union [_models .RedisCacheAccessPolicyAssignment , IO [bytes ]],
7575 ** kwargs : Any
76- ) -> _models . RedisCacheAccessPolicyAssignment :
76+ ) -> AsyncIterator [ bytes ] :
7777 error_map : MutableMapping [int , Type [HttpResponseError ]] = {
7878 401 : ClientAuthenticationError ,
7979 404 : ResourceNotFoundError ,
@@ -87,7 +87,7 @@ async def _create_update_initial(
8787
8888 api_version : str = kwargs .pop ("api_version" , _params .pop ("api-version" , self ._config .api_version ))
8989 content_type : Optional [str ] = kwargs .pop ("content_type" , _headers .pop ("Content-Type" , None ))
90- cls : ClsType [_models . RedisCacheAccessPolicyAssignment ] = kwargs .pop ("cls" , None )
90+ cls : ClsType [AsyncIterator [ bytes ] ] = kwargs .pop ("cls" , None )
9191
9292 content_type = content_type or "application/json"
9393 _json = None
@@ -109,26 +109,26 @@ async def _create_update_initial(
109109 headers = _headers ,
110110 params = _params ,
111111 )
112- _request = _convert_request (_request )
113112 _request .url = self ._client .format_url (_request .url )
114113
115- _stream = False
114+ _decompress = kwargs .pop ("decompress" , True )
115+ _stream = True
116116 pipeline_response : PipelineResponse = await self ._client ._pipeline .run ( # pylint: disable=protected-access
117117 _request , stream = _stream , ** kwargs
118118 )
119119
120120 response = pipeline_response .http_response
121121
122122 if response .status_code not in [200 , 201 ]:
123+ try :
124+ await response .read () # Load the body in memory and close the socket
125+ except (StreamConsumedError , StreamClosedError ):
126+ pass
123127 map_error (status_code = response .status_code , response = response , error_map = error_map )
124128 error = self ._deserialize .failsafe_deserialize (_models .ErrorResponse , pipeline_response )
125129 raise HttpResponseError (response = response , model = error , error_format = ARMErrorFormat )
126130
127- if response .status_code == 200 :
128- deserialized = self ._deserialize ("RedisCacheAccessPolicyAssignment" , pipeline_response )
129-
130- if response .status_code == 201 :
131- deserialized = self ._deserialize ("RedisCacheAccessPolicyAssignment" , pipeline_response )
131+ deserialized = response .stream_download (self ._client ._pipeline , decompress = _decompress )
132132
133133 if cls :
134134 return cls (pipeline_response , deserialized , {}) # type: ignore
@@ -250,10 +250,11 @@ async def begin_create_update(
250250 params = _params ,
251251 ** kwargs
252252 )
253+ await raw_result .http_response .read () # type: ignore
253254 kwargs .pop ("error_map" , None )
254255
255256 def get_long_running_output (pipeline_response ):
256- deserialized = self ._deserialize ("RedisCacheAccessPolicyAssignment" , pipeline_response )
257+ deserialized = self ._deserialize ("RedisCacheAccessPolicyAssignment" , pipeline_response . http_response )
257258 if cls :
258259 return cls (pipeline_response , deserialized , {}) # type: ignore
259260 return deserialized
@@ -275,9 +276,9 @@ def get_long_running_output(pipeline_response):
275276 self ._client , raw_result , get_long_running_output , polling_method # type: ignore
276277 )
277278
278- async def _delete_initial ( # pylint: disable=inconsistent-return-statements
279+ async def _delete_initial (
279280 self , resource_group_name : str , cache_name : str , access_policy_assignment_name : str , ** kwargs : Any
280- ) -> None :
281+ ) -> AsyncIterator [ bytes ] :
281282 error_map : MutableMapping [int , Type [HttpResponseError ]] = {
282283 401 : ClientAuthenticationError ,
283284 404 : ResourceNotFoundError ,
@@ -290,7 +291,7 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements
290291 _params = case_insensitive_dict (kwargs .pop ("params" , {}) or {})
291292
292293 api_version : str = kwargs .pop ("api_version" , _params .pop ("api-version" , self ._config .api_version ))
293- cls : ClsType [None ] = kwargs .pop ("cls" , None )
294+ cls : ClsType [AsyncIterator [ bytes ] ] = kwargs .pop ("cls" , None )
294295
295296 _request = build_delete_request (
296297 resource_group_name = resource_group_name ,
@@ -301,17 +302,21 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements
301302 headers = _headers ,
302303 params = _params ,
303304 )
304- _request = _convert_request (_request )
305305 _request .url = self ._client .format_url (_request .url )
306306
307- _stream = False
307+ _decompress = kwargs .pop ("decompress" , True )
308+ _stream = True
308309 pipeline_response : PipelineResponse = await self ._client ._pipeline .run ( # pylint: disable=protected-access
309310 _request , stream = _stream , ** kwargs
310311 )
311312
312313 response = pipeline_response .http_response
313314
314315 if response .status_code not in [200 , 202 , 204 ]:
316+ try :
317+ await response .read () # Load the body in memory and close the socket
318+ except (StreamConsumedError , StreamClosedError ):
319+ pass
315320 map_error (status_code = response .status_code , response = response , error_map = error_map )
316321 error = self ._deserialize .failsafe_deserialize (_models .ErrorResponse , pipeline_response )
317322 raise HttpResponseError (response = response , model = error , error_format = ARMErrorFormat )
@@ -320,8 +325,12 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements
320325 if response .status_code == 202 :
321326 response_headers ["Location" ] = self ._deserialize ("str" , response .headers .get ("Location" ))
322327
328+ deserialized = response .stream_download (self ._client ._pipeline , decompress = _decompress )
329+
323330 if cls :
324- return cls (pipeline_response , None , response_headers ) # type: ignore
331+ return cls (pipeline_response , deserialized , response_headers ) # type: ignore
332+
333+ return deserialized # type: ignore
325334
326335 @distributed_trace_async
327336 async def begin_delete (
@@ -349,7 +358,7 @@ async def begin_delete(
349358 lro_delay = kwargs .pop ("polling_interval" , self ._config .polling_interval )
350359 cont_token : Optional [str ] = kwargs .pop ("continuation_token" , None )
351360 if cont_token is None :
352- raw_result = await self ._delete_initial ( # type: ignore
361+ raw_result = await self ._delete_initial (
353362 resource_group_name = resource_group_name ,
354363 cache_name = cache_name ,
355364 access_policy_assignment_name = access_policy_assignment_name ,
@@ -359,6 +368,7 @@ async def begin_delete(
359368 params = _params ,
360369 ** kwargs
361370 )
371+ await raw_result .http_response .read () # type: ignore
362372 kwargs .pop ("error_map" , None )
363373
364374 def get_long_running_output (pipeline_response ): # pylint: disable=inconsistent-return-statements
@@ -422,7 +432,6 @@ async def get(
422432 headers = _headers ,
423433 params = _params ,
424434 )
425- _request = _convert_request (_request )
426435 _request .url = self ._client .format_url (_request .url )
427436
428437 _stream = False
@@ -437,7 +446,7 @@ async def get(
437446 error = self ._deserialize .failsafe_deserialize (_models .ErrorResponse , pipeline_response )
438447 raise HttpResponseError (response = response , model = error , error_format = ARMErrorFormat )
439448
440- deserialized = self ._deserialize ("RedisCacheAccessPolicyAssignment" , pipeline_response )
449+ deserialized = self ._deserialize ("RedisCacheAccessPolicyAssignment" , pipeline_response . http_response )
441450
442451 if cls :
443452 return cls (pipeline_response , deserialized , {}) # type: ignore
@@ -486,7 +495,6 @@ def prepare_request(next_link=None):
486495 headers = _headers ,
487496 params = _params ,
488497 )
489- _request = _convert_request (_request )
490498 _request .url = self ._client .format_url (_request .url )
491499
492500 else :
@@ -502,7 +510,6 @@ def prepare_request(next_link=None):
502510 _request = HttpRequest (
503511 "GET" , urllib .parse .urljoin (next_link , _parsed_next_link .path ), params = _next_request_params
504512 )
505- _request = _convert_request (_request )
506513 _request .url = self ._client .format_url (_request .url )
507514 _request .method = "GET"
508515 return _request
0 commit comments