Skip to content

Commit

Permalink
regenerate
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft committed Apr 27, 2021
1 parent ad4424f commit 93decd7
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def send_request(self, http_request, **kwargs):
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
if kwargs.pop("stream_response", False):
return _StreamContextManager(
client=self._client,
client=self._client._pipeline,
request=request_copy,
)
pipeline_response = self._client._pipeline.run(request_copy._internal_request, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def send_request(self, http_request: HttpRequest, **kwargs: Any) -> AsyncH
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
if kwargs.pop("stream_response", False):
return _AsyncStreamContextManager(
client=self._client,
client=self._client._pipeline,
request=request_copy,
)
pipeline_response = await self._client._pipeline.run(request_copy._internal_request, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,10 @@ def reason(self):
def content(self):
# type: (...) -> bytes
"""Returns the response content in bytes"""
raise NotImplementedError()
try:
return self._content
except AttributeError:
raise ResponseNotReadError()

@property
def url(self):
Expand Down Expand Up @@ -491,22 +494,14 @@ def _validate_streaming_access(self):

class HttpResponse(_HttpResponseBase):

@property
def content(self):
# type: (...) -> bytes
try:
return self._content
except AttributeError:
raise ResponseNotReadError()

def close(self):
# type: (...) -> None
self.is_closed = True
self._internal_response.internal_response.close()

def __exit__(self, *args):
# type: (...) -> None
self._internal_response.internal_response.__exit__(*args)
self.close()

def read(self):
# type: (...) -> bytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
Sequence[Tuple[str, FileType]]
]

from azure.core.pipeline import Pipeline
from azure.core.pipeline import Pipeline, AsyncPipeline
from azure.core.pipeline.transport import (
HttpRequest as _PipelineTransportHttpRequest,
)
Expand Down Expand Up @@ -214,7 +214,7 @@ def _parse_lines_from_text(text):
class _StreamContextManagerBase:
def __init__(
self,
client: Union[_PipelineClient, _AsyncPipelineClient],
pipeline: Union[Pipeline, AsyncPipeline],
request: "HttpRequest",
**kwargs
):
Expand All @@ -226,7 +226,7 @@ def __init__(
Heavily inspired from httpx, we want the same behavior for it to feel consistent for users
"""
self.client = client
self.pipeline = pipeline
self.request = request
self.kwargs = kwargs

Expand All @@ -237,7 +237,7 @@ def close(self):
class _StreamContextManager(_StreamContextManagerBase):
def __enter__(self) -> "HttpResponse":
"""Actually make the call only when we enter. For sync stream_response calls"""
pipeline_transport_response = self.client._pipeline.run(
pipeline_transport_response = self.pipeline.run(
self.request._internal_request,
stream=True,
**self.kwargs
Expand All @@ -258,12 +258,12 @@ def close(self):
class _AsyncStreamContextManager(_StreamContextManagerBase):
async def __aenter__(self) -> "AsyncHttpResponse":
"""Actually make the call only when we enter. For async stream_response calls."""
if not isinstance(self.client, _AsyncPipelineClient):
if not isinstance(self.pipeline, AsyncPipeline):
raise TypeError(
"Only sync calls should enter here. If you mean to do a sync call, "
"Only async calls should enter here. If you mean to do a sync call, "
"make sure to use 'with' instead."
)
pipeline_transport_response = (await self.client._pipeline.run(
pipeline_transport_response = (await self.pipeline.run(
self.request._internal_request,
stream=True,
**self.kwargs
Expand Down Expand Up @@ -446,11 +446,6 @@ def reason(self) -> str:
"""Returns the reason phrase for the response"""
return self._internal_response.reason

@property
def content(self) -> bytes:
"""Returns the response content in bytes"""
raise NotImplementedError()

@property
def url(self) -> str:
"""Returns the URL that resulted in this response"""
Expand Down Expand Up @@ -529,6 +524,14 @@ def raise_for_status(self) -> None:
if self.status_code >= 400:
raise HttpResponseError(response=self)

@property
def content(self) -> bytes:
"""Return the response's content in bytes."""
try:
return self._content
except AttributeError:
raise ResponseNotReadError()

def __repr__(self) -> str:
content_type_str = (
", Content-Type: {}".format(self.content_type) if self.content_type else ""
Expand All @@ -545,19 +548,12 @@ def _validate_streaming_access(self) -> None:

class HttpResponse(_HttpResponseBase):

@property
def content(self):
# type: (...) -> bytes
try:
return self._content
except AttributeError:
raise ResponseNotReadError()

def close(self) -> None:
self.is_closed = True
self._internal_response.internal_response.close()

def __exit__(self, *args) -> None:
self.is_closed = True
self._internal_response.internal_response.__exit__(*args)

def read(self) -> bytes:
Expand Down Expand Up @@ -619,13 +615,6 @@ def iter_raw(self, chunk_size: int = None) -> Iterator[bytes]:

class AsyncHttpResponse(_HttpResponseBase):

@property
def content(self) -> bytes:
try:
return self._content
except AttributeError:
raise ResponseNotReadError()

async def _close_stream(self) -> None:
self.is_stream_consumed = True
await self.close()
Expand Down Expand Up @@ -686,6 +675,7 @@ async def close(self) -> None:
await asyncio.sleep(0)

async def __aexit__(self, *args) -> None:
self.is_closed = True
await self._internal_response.internal_response.__aexit__(*args)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def build_create_azure_key_vault_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def build_create_azure_key_vault_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def build_create_or_update_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def build_create_or_update_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def build_create_or_update_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def build_create_or_update_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def build_create_or_update_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def build_create_or_update_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def build_create_or_update_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def build_create_or_update_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def build_create_or_update_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def build_create_or_update_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def build_create_trigger_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def build_create_trigger_request(

# Construct headers
header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any]
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')
if content_type is not None:
header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str')
header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str')

return HttpRequest(
method="PUT",
Expand Down

0 comments on commit 93decd7

Please sign in to comment.