20
20
import platform
21
21
import socket
22
22
import string
23
+ import warnings
23
24
from base64 import b64encode
24
25
from urllib import parse
25
26
29
30
from selenium import __version__
30
31
31
32
from . import utils
33
+ from .client_config import ClientConfig
32
34
from .command import Command
33
35
from .errorhandler import ErrorCode
34
36
@@ -211,12 +213,6 @@ def get_remote_connection_headers(cls, parsed_url, keep_alive=False):
211
213
212
214
return headers
213
215
214
- def _get_proxy_url (self ):
215
- if self ._url .startswith ("https://" ):
216
- return os .environ .get ("https_proxy" , os .environ .get ("HTTPS_PROXY" ))
217
- if self ._url .startswith ("http://" ):
218
- return os .environ .get ("http_proxy" , os .environ .get ("HTTP_PROXY" ))
219
-
220
216
def _identify_http_proxy_auth (self ):
221
217
url = self ._proxy_url
222
218
url = url [url .find (":" ) + 3 :]
@@ -248,31 +244,42 @@ def _get_connection_manager(self):
248
244
249
245
return urllib3 .PoolManager (** pool_manager_init_args )
250
246
251
- def __init__ (self , remote_server_addr : str , keep_alive : bool = False , ignore_proxy : bool = False ):
252
- self .keep_alive = keep_alive
253
- self ._url = remote_server_addr
254
-
255
- # Env var NO_PROXY will override this part of the code
256
- _no_proxy = os .environ .get ("no_proxy" , os .environ .get ("NO_PROXY" ))
257
- if _no_proxy :
258
- for npu in _no_proxy .split ("," ):
259
- npu = npu .strip ()
260
- if npu == "*" :
261
- ignore_proxy = True
262
- break
263
- n_url = parse .urlparse (npu )
264
- remote_add = parse .urlparse (self ._url )
265
- if n_url .netloc :
266
- if remote_add .netloc == n_url .netloc :
267
- ignore_proxy = True
268
- break
269
- else :
270
- if n_url .path in remote_add .netloc :
271
- ignore_proxy = True
272
- break
273
-
274
- self ._proxy_url = self ._get_proxy_url () if not ignore_proxy else None
275
- if keep_alive :
247
+ def __init__ (
248
+ self ,
249
+ remote_server_addr : str ,
250
+ keep_alive : bool = True ,
251
+ ignore_proxy : bool = False ,
252
+ client_config : ClientConfig = None ,
253
+ ):
254
+ self ._client_config = client_config or ClientConfig ()
255
+
256
+ if remote_server_addr :
257
+ warnings .warn (
258
+ "setting keep_alive in RemoteConnection() is deprecated, " "set in ClientConfig instance insttead" ,
259
+ DeprecationWarning ,
260
+ stacklevel = 2 ,
261
+ )
262
+ self ._client_config .remote_server_addr = remote_server_addr
263
+
264
+ if not keep_alive :
265
+ warnings .warn (
266
+ "setting keep_alive in RemoteConnection() is deprecated, " "set in ClientConfig instance insttead" ,
267
+ DeprecationWarning ,
268
+ stacklevel = 2 ,
269
+ )
270
+ self ._client_config .keep_alive = keep_alive
271
+
272
+ if ignore_proxy :
273
+ warnings .warn (
274
+ "setting keep_alive in RemoteConnection() is deprecated, " "set in ClientConfig instance insttead" ,
275
+ DeprecationWarning ,
276
+ stacklevel = 2 ,
277
+ )
278
+ self ._proxy_url = None
279
+ else :
280
+ self ._proxy_url = self ._client_config .get_proxy_url ()
281
+
282
+ if self ._client_config .keep_alive :
276
283
self ._conn = self ._get_connection_manager ()
277
284
self ._commands = remote_commands
278
285
@@ -296,7 +303,7 @@ def execute(self, command, params):
296
303
for word in substitute_params :
297
304
del params [word ]
298
305
data = utils .dump_json (params )
299
- url = f"{ self ._url } { path } "
306
+ url = f"{ self ._client_config . remote_server_addr } { path } "
300
307
return self ._request (command_info [0 ], url , body = data )
301
308
302
309
def _request (self , method , url , body = None ):
@@ -312,12 +319,11 @@ def _request(self, method, url, body=None):
312
319
"""
313
320
LOGGER .debug ("%s %s %s" , method , url , body )
314
321
parsed_url = parse .urlparse (url )
315
- headers = self .get_remote_connection_headers (parsed_url , self .keep_alive )
316
- response = None
322
+ headers = self .get_remote_connection_headers (parsed_url , self ._client_config .keep_alive )
317
323
if body and method not in ("POST" , "PUT" ):
318
324
body = None
319
325
320
- if self .keep_alive :
326
+ if self ._client_config . keep_alive :
321
327
response = self ._conn .request (method , url , body = body , headers = headers )
322
328
statuscode = response .status
323
329
else :
0 commit comments