Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
msyyc committed May 23, 2024
1 parent dccdd16 commit c97c28c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ def call_request_builder(self, builder: OperationType, is_paging: bool = False)

@property
def deserialize_for_stream_res(self) -> str:
if self.code_model.options["version_tolerant"]:
if not self.code_model.is_legacy:
return "response.iter_bytes()"
return (
"(await response.load_body()) or response._content # pylint: disable=protected-access"
Expand Down Expand Up @@ -929,7 +929,10 @@ def response_headers_and_deserialization(
deserialized = f"{'await ' if self.async_mode else ''}response.read()"
else:
stream_logic = False
deserialized = self.deserialize_for_stream_res
if self.code_model.options["version_tolerant"]:
deserialized = "response.iter_bytes()"
else:
deserialized = f"response.stream_download(self._client.{self.pipeline_name})"
deserialize_code.append(f"deserialized = {deserialized}")
elif response.type:
pylint_disable = ""
Expand Down Expand Up @@ -984,9 +987,7 @@ def response_headers_and_deserialization(
def handle_error_response(self, builder: OperationType) -> List[str]:
async_await = "await " if self.async_mode else ""
retval = [f"if response.status_code not in {str(builder.success_status_codes)}:"]
need_download = (
builder.has_stream_kwargs and self.async_mode and not self.code_model.options["version_tolerant"]
)
need_download = builder.has_stream_kwargs and self.async_mode
if not self.code_model.need_request_converter or need_download:
load_func = "load_body" if need_download else "read"
retval.extend(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async def error_stream(self, **kwargs: Any) -> AsyncIterator[bytes]:
error = self._deserialize.failsafe_deserialize(_models.Error, pipeline_response)
raise HttpResponseError(response=response, model=error)

deserialized = (await response.load_body()) or response._content # pylint: disable=protected-access
deserialized = response.stream_download(self._client._pipeline)

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def get_file(self, **kwargs: Any) -> AsyncIterator[bytes]:
error = self._deserialize.failsafe_deserialize(_models.Error, pipeline_response)
raise HttpResponseError(response=response, model=error)

deserialized = (await response.load_body()) or response._content # pylint: disable=protected-access
deserialized = response.stream_download(self._client._pipeline)

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore
Expand Down Expand Up @@ -144,7 +144,7 @@ async def get_file_large(self, **kwargs: Any) -> AsyncIterator[bytes]:
error = self._deserialize.failsafe_deserialize(_models.Error, pipeline_response)
raise HttpResponseError(response=response, model=error)

deserialized = (await response.load_body()) or response._content # pylint: disable=protected-access
deserialized = response.stream_download(self._client._pipeline)

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore
Expand Down Expand Up @@ -191,7 +191,7 @@ async def get_empty_file(self, **kwargs: Any) -> AsyncIterator[bytes]:
error = self._deserialize.failsafe_deserialize(_models.Error, pipeline_response)
raise HttpResponseError(response=response, model=error)

deserialized = (await response.load_body()) or response._content # pylint: disable=protected-access
deserialized = response.stream_download(self._client._pipeline)

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async def upload_file(self, file_content: IO[bytes], file_name: str, **kwargs: A
error = self._deserialize.failsafe_deserialize(_models.Error, pipeline_response)
raise HttpResponseError(response=response, model=error)

deserialized = (await response.load_body()) or response._content # pylint: disable=protected-access
deserialized = response.stream_download(self._client._pipeline)

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore
Expand Down Expand Up @@ -166,7 +166,7 @@ async def upload_file_via_body(self, file_content: IO[bytes], **kwargs: Any) ->
error = self._deserialize.failsafe_deserialize(_models.Error, pipeline_response)
raise HttpResponseError(response=response, model=error)

deserialized = (await response.load_body()) or response._content # pylint: disable=protected-access
deserialized = response.stream_download(self._client._pipeline)

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore
Expand Down Expand Up @@ -223,7 +223,7 @@ async def upload_files(self, file_content: List[IO[bytes]], **kwargs: Any) -> As
error = self._deserialize.failsafe_deserialize(_models.Error, pipeline_response)
raise HttpResponseError(response=response, model=error)

deserialized = (await response.load_body()) or response._content # pylint: disable=protected-access
deserialized = response.stream_download(self._client._pipeline)

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore
Expand Down

0 comments on commit c97c28c

Please sign in to comment.