Skip to content

Commit 8999812

Browse files
authored
[Corehttp] Fix next-pylint errors (#33876)
Signed-off-by: Paul Van Eck <[email protected]>
1 parent 2aa3595 commit 8999812

File tree

5 files changed

+40
-33
lines changed

5 files changed

+40
-33
lines changed

sdk/core/corehttp/corehttp/runtime/_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def _format_url_section(template, **kwargs):
3636
This is used for API like Storage, where when Swagger has template section not defined as parameter.
3737
3838
:param str template: a string template to fill
39-
:keyword dict[str,str] kwargs: Template values as string
4039
:rtype: str
4140
:returns: Template completed
4241
"""

sdk/core/corehttp/corehttp/runtime/_pipeline_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _build_pipeline(
140140

141141
return Pipeline(transport, policies)
142142

143-
def send_request(self, request: HTTPRequestType, **kwargs: Any) -> HTTPResponseType:
143+
def send_request(self, request: HTTPRequestType, *, stream: bool = False, **kwargs: Any) -> HTTPResponseType:
144144
"""Method that runs the network request through the client's chained policies.
145145
146146
>>> from corehttp.rest import HttpRequest
@@ -155,6 +155,5 @@ def send_request(self, request: HTTPRequestType, **kwargs: Any) -> HTTPResponseT
155155
:return: The response of your network call. Does not do error handling on your response.
156156
:rtype: ~corehttp.rest.HttpResponse
157157
"""
158-
stream = kwargs.pop("stream", False) # want to add default value
159158
pipeline_response = self.pipeline.run(request, stream=stream, **kwargs)
160159
return pipeline_response.http_response

sdk/core/corehttp/corehttp/transport/aiohttp/_aiohttp.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#
2525
# --------------------------------------------------------------------------
2626
from __future__ import annotations
27-
from typing import Optional, TYPE_CHECKING, Type, cast
27+
from typing import Optional, TYPE_CHECKING, Type, cast, MutableMapping
2828
from types import TracebackType
2929

3030
import logging
@@ -109,7 +109,7 @@ def _build_ssl_config(self, cert, verify):
109109
110110
:param tuple cert: Cert information
111111
:param bool verify: SSL verification or path to CA file or directory
112-
:rtype: bool or str or :class:`ssl.SSLContext`
112+
:rtype: bool or str or ssl.SSLContext
113113
:return: SSL configuration
114114
"""
115115
ssl_ctx = None
@@ -145,21 +145,25 @@ def _get_request_data(self, request: RestHttpRequest):
145145
return form_data
146146
return request.content
147147

148-
async def send(self, request: RestHttpRequest, **config) -> RestAsyncHttpResponse:
148+
async def send(
149+
self,
150+
request: RestHttpRequest,
151+
*,
152+
stream: bool = False,
153+
proxies: Optional[MutableMapping[str, str]] = None,
154+
**config,
155+
) -> RestAsyncHttpResponse:
149156
"""Send the request using this HTTP sender.
150157
151158
Will pre-load the body into memory to be available with a sync method.
152159
Pass stream=True to avoid this behavior.
153160
154161
:param request: The HttpRequest object
155162
:type request: ~corehttp.rest.HttpRequest
156-
:keyword any config: Any keyword arguments
163+
:keyword bool stream: Defaults to False.
164+
:keyword MutableMapping proxies: dict of proxies to use based on protocol. Proxy is a dict (protocol, url).
157165
:return: The AsyncHttpResponse
158166
:rtype: ~corehttp.rest.AsyncHttpResponse
159-
160-
:keyword bool stream: Defaults to False.
161-
:keyword dict proxies: dict of proxy to used based on protocol. Proxy is a dict (protocol, url)
162-
:keyword str proxy: will define the proxy to use all the time
163167
"""
164168
await self.open()
165169
try:
@@ -168,14 +172,14 @@ async def send(self, request: RestHttpRequest, **config) -> RestAsyncHttpRespons
168172
# auto_decompress is introduced in aiohttp 3.7. We need this to handle aiohttp 3.6-.
169173
auto_decompress = False
170174

171-
proxies = config.pop("proxies", None)
172-
if proxies and "proxy" not in config:
175+
proxy = config.pop("proxy", None)
176+
if proxies and not proxy:
173177
# aiohttp needs a single proxy, so iterating until we found the right protocol
174178

175179
# Sort by longest string first, so "http" is not used for "https" ;-)
176180
for protocol in sorted(proxies.keys(), reverse=True):
177181
if request.url.startswith(protocol):
178-
config["proxy"] = proxies[protocol]
182+
proxy = proxies[protocol]
179183
break
180184

181185
response: Optional[RestAsyncHttpResponse] = None
@@ -194,7 +198,6 @@ async def send(self, request: RestHttpRequest, **config) -> RestAsyncHttpRespons
194198
if not request.content:
195199
config["skip_auto_headers"] = ["Content-Type"]
196200
try:
197-
stream_response = config.pop("stream", False)
198201
timeout = config.pop("connection_timeout", self.connection_config.get("connection_timeout"))
199202
read_timeout = config.pop("read_timeout", self.connection_config.get("read_timeout"))
200203
socket_timeout = aiohttp.ClientTimeout(sock_connect=timeout, sock_read=read_timeout)
@@ -205,6 +208,7 @@ async def send(self, request: RestHttpRequest, **config) -> RestAsyncHttpRespons
205208
data=self._get_request_data(request),
206209
timeout=socket_timeout,
207210
allow_redirects=False,
211+
proxy=proxy,
208212
**config,
209213
)
210214

@@ -214,7 +218,7 @@ async def send(self, request: RestHttpRequest, **config) -> RestAsyncHttpRespons
214218
block_size=self.connection_config.get("data_block_size"),
215219
decompress=not auto_decompress,
216220
)
217-
if not stream_response:
221+
if not stream:
218222
await _handle_non_stream_rest_response(response)
219223

220224
except aiohttp.client_exceptions.ClientResponseError as err:

sdk/core/corehttp/corehttp/transport/httpx/_httpx.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __enter__(self) -> "HttpXTransport":
8080
def __exit__(self, *args) -> None:
8181
self.close()
8282

83-
def send(self, request: HttpRequest, **kwargs) -> HttpResponse:
83+
def send(self, request: HttpRequest, *, stream: bool = False, **kwargs) -> HttpResponse:
8484
"""Send a request and get back a response.
8585
8686
:param request: The request object to be sent.
@@ -90,7 +90,6 @@ def send(self, request: HttpRequest, **kwargs) -> HttpResponse:
9090
:rtype: ~corehttp.rest.HttpResponse
9191
"""
9292
self.open()
93-
stream_response = kwargs.pop("stream", False)
9493
connect_timeout = kwargs.pop("connection_timeout", self.connection_config.get("connection_timeout"))
9594
read_timeout = kwargs.pop("read_timeout", self.connection_config.get("read_timeout"))
9695
# not needed here as its already handled during init
@@ -112,9 +111,9 @@ def send(self, request: HttpRequest, **kwargs) -> HttpResponse:
112111
# Cast for typing since we know it's not None after the open call
113112
client = cast(httpx.Client, self.client)
114113
try:
115-
if stream_response:
114+
if stream:
116115
req = client.build_request(**parameters)
117-
response = client.send(req, stream=stream_response)
116+
response = client.send(req, stream=stream)
118117
else:
119118
response = client.request(**parameters)
120119
except (httpx.ReadTimeout, httpx.ProtocolError) as err:
@@ -123,7 +122,7 @@ def send(self, request: HttpRequest, **kwargs) -> HttpResponse:
123122
raise ServiceRequestError(err, error=err) from err
124123

125124
retval = HttpXTransportResponse(request, response)
126-
if not stream_response:
125+
if not stream:
127126
_handle_non_stream_rest_response(retval)
128127
return retval
129128

@@ -169,7 +168,7 @@ async def __aenter__(self) -> "AsyncHttpXTransport":
169168
async def __aexit__(self, *args) -> None:
170169
await self.close()
171170

172-
async def send(self, request: HttpRequest, **kwargs) -> AsyncHttpResponse:
171+
async def send(self, request: HttpRequest, *, stream: bool = False, **kwargs) -> AsyncHttpResponse:
173172
"""Send the request using this HTTP sender.
174173
175174
:param request: The request object to be sent.
@@ -179,7 +178,6 @@ async def send(self, request: HttpRequest, **kwargs) -> AsyncHttpResponse:
179178
:rtype: ~corehttp.rest.AsyncHttpResponse
180179
"""
181180
await self.open()
182-
stream_response = kwargs.pop("stream", False)
183181
connect_timeout = kwargs.pop("connection_timeout", self.connection_config.get("connection_timeout"))
184182
read_timeout = kwargs.pop("read_timeout", self.connection_config.get("read_timeout"))
185183
# not needed here as its already handled during init
@@ -198,9 +196,9 @@ async def send(self, request: HttpRequest, **kwargs) -> AsyncHttpResponse:
198196
response = None
199197
client = cast(httpx.AsyncClient, self.client)
200198
try:
201-
if stream_response:
199+
if stream:
202200
req = client.build_request(**parameters)
203-
response = await client.send(req, stream=stream_response)
201+
response = await client.send(req, stream=stream)
204202
else:
205203
response = await client.request(**parameters)
206204
except (httpx.ReadTimeout, httpx.ProtocolError) as err:
@@ -209,6 +207,6 @@ async def send(self, request: HttpRequest, **kwargs) -> AsyncHttpResponse:
209207
raise ServiceRequestError(err, error=err) from err
210208

211209
retval = AsyncHttpXTransportResponse(request, response)
212-
if not stream_response:
210+
if not stream:
213211
await _handle_non_stream_rest_response_async(retval)
214212
return retval

sdk/core/corehttp/corehttp/transport/requests/_requests_basic.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#
2525
# --------------------------------------------------------------------------
2626
import logging
27-
from typing import Optional, Union, TypeVar, cast, TYPE_CHECKING
27+
from typing import Optional, Union, TypeVar, cast, MutableMapping, TYPE_CHECKING
2828
from urllib3.util.retry import Retry
2929
from urllib3.exceptions import (
3030
ProtocolError,
@@ -118,17 +118,22 @@ def close(self):
118118
self._session_owner = False
119119
self.session = None
120120

121-
def send(self, request: "RestHttpRequest", **kwargs) -> "RestHttpResponse":
121+
def send(
122+
self,
123+
request: "RestHttpRequest",
124+
*,
125+
stream: bool = False,
126+
proxies: Optional[MutableMapping[str, str]] = None,
127+
**kwargs
128+
) -> "RestHttpResponse":
122129
"""Send request object according to configuration.
123130
124131
:param request: The request object to be sent.
125132
:type request: ~corehttp.rest.HttpRequest
133+
:keyword bool stream: Defaults to False.
134+
:keyword MutableMapping proxies: dict of proxies to use based on protocol. Proxy is a dict (protocol, url).
126135
:return: An HTTPResponse object.
127136
:rtype: ~corehttp.rest.HttpResponse
128-
129-
:keyword requests.Session session: will override the driver session and use yours.
130-
Should NOT be done unless really required. Anything else is sent straight to requests.
131-
:keyword dict proxies: will define the proxy to use. Proxy is a dict (protocol, url)
132137
"""
133138
self.open()
134139
response = None
@@ -154,6 +159,8 @@ def send(self, request: "RestHttpRequest", **kwargs) -> "RestHttpResponse":
154159
timeout=timeout,
155160
cert=kwargs.pop("connection_cert", self.connection_config.get("connection_cert")),
156161
allow_redirects=False,
162+
stream=stream,
163+
proxies=proxies,
157164
**kwargs
158165
)
159166
response.raw.enforce_content_length = True
@@ -189,6 +196,6 @@ def send(self, request: "RestHttpRequest", **kwargs) -> "RestHttpResponse":
189196
internal_response=response,
190197
block_size=self.connection_config.get("data_block_size"),
191198
)
192-
if not kwargs.get("stream"):
199+
if not stream:
193200
_handle_non_stream_rest_response(retval)
194201
return retval

0 commit comments

Comments
 (0)