2020import platform
2121import socket
2222import string
23+ import warnings
2324from base64 import b64encode
2425from urllib import parse
2526
2930from selenium import __version__
3031
3132from . import utils
33+ from .client_config import ClientConfig
3234from .command import Command
3335from .errorhandler import ErrorCode
3436
@@ -211,12 +213,6 @@ def get_remote_connection_headers(cls, parsed_url, keep_alive=False):
211213
212214 return headers
213215
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-
220216 def _identify_http_proxy_auth (self ):
221217 url = self ._proxy_url
222218 url = url [url .find (":" ) + 3 :]
@@ -248,31 +244,40 @@ def _get_connection_manager(self):
248244
249245 return urllib3 .PoolManager (** pool_manager_init_args )
250246
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 (remote_server_addr , keep_alive )
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+
263+ if not keep_alive :
264+ warnings .warn (
265+ "setting keep_alive in RemoteConnection() is deprecated, " "set in ClientConfig instance insttead" ,
266+ DeprecationWarning ,
267+ stacklevel = 2 ,
268+ )
269+
270+ if ignore_proxy :
271+ warnings .warn (
272+ "setting keep_alive in RemoteConnection() is deprecated, " "set in ClientConfig instance insttead" ,
273+ DeprecationWarning ,
274+ stacklevel = 2 ,
275+ )
276+ self ._proxy_url = None
277+ else :
278+ self ._proxy_url = self ._client_config .get_proxy_url ()
279+
280+ if self ._client_config .keep_alive :
276281 self ._conn = self ._get_connection_manager ()
277282 self ._commands = remote_commands
278283
@@ -296,7 +301,7 @@ def execute(self, command, params):
296301 for word in substitute_params :
297302 del params [word ]
298303 data = utils .dump_json (params )
299- url = f"{ self ._url } { path } "
304+ url = f"{ self ._client_config . remote_server_addr } { path } "
300305 return self ._request (command_info [0 ], url , body = data )
301306
302307 def _request (self , method , url , body = None ):
@@ -312,12 +317,11 @@ def _request(self, method, url, body=None):
312317 """
313318 LOGGER .debug ("%s %s %s" , method , url , body )
314319 parsed_url = parse .urlparse (url )
315- headers = self .get_remote_connection_headers (parsed_url , self .keep_alive )
316- response = None
320+ headers = self .get_remote_connection_headers (parsed_url , self ._client_config .keep_alive )
317321 if body and method not in ("POST" , "PUT" ):
318322 body = None
319323
320- if self .keep_alive :
324+ if self ._client_config . keep_alive :
321325 response = self ._conn .request (method , url , body = body , headers = headers )
322326 statuscode = response .status
323327 else :
0 commit comments