@@ -148,6 +148,14 @@ class RemoteConnection:
148148 )
149149 _ca_certs = os .getenv ("REQUESTS_CA_BUNDLE" ) if "REQUESTS_CA_BUNDLE" in os .environ else certifi .where ()
150150
151+ system = platform .system ().lower ()
152+ if system == "darwin" :
153+ system = "mac"
154+
155+ # Class variables for headers
156+ extra_headers = None
157+ user_agent = f"selenium/{ __version__ } (python { system } )"
158+
151159 @classmethod
152160 def get_timeout (cls ):
153161 """:Returns:
@@ -201,14 +209,10 @@ def get_remote_connection_headers(cls, parsed_url, keep_alive=False):
201209 - keep_alive (Boolean) - Is this a keep-alive connection (default: False)
202210 """
203211
204- system = platform .system ().lower ()
205- if system == "darwin" :
206- system = "mac"
207-
208212 headers = {
209213 "Accept" : "application/json" ,
210214 "Content-Type" : "application/json;charset=UTF-8" ,
211- "User-Agent" : f"selenium/ { __version__ } (python { system } )" ,
215+ "User-Agent" : cls . user_agent ,
212216 }
213217
214218 if parsed_url .username :
@@ -218,6 +222,9 @@ def get_remote_connection_headers(cls, parsed_url, keep_alive=False):
218222 if keep_alive :
219223 headers .update ({"Connection" : "keep-alive" })
220224
225+ if cls .extra_headers :
226+ headers .update (cls .extra_headers )
227+
221228 return headers
222229
223230 def _get_proxy_url (self ):
@@ -241,7 +248,12 @@ def _separate_http_proxy_auth(self):
241248
242249 def _get_connection_manager (self ):
243250 pool_manager_init_args = {"timeout" : self .get_timeout ()}
244- if self ._ca_certs :
251+ pool_manager_init_args .update (self ._init_args_for_pool_manager .get ("init_args_for_pool_manager" , {}))
252+
253+ if self ._ignore_certificates :
254+ pool_manager_init_args ["cert_reqs" ] = "CERT_NONE"
255+ urllib3 .disable_warnings (urllib3 .exceptions .InsecureRequestWarning )
256+ elif self ._ca_certs :
245257 pool_manager_init_args ["cert_reqs" ] = "CERT_REQUIRED"
246258 pool_manager_init_args ["ca_certs" ] = self ._ca_certs
247259
@@ -257,9 +269,18 @@ def _get_connection_manager(self):
257269
258270 return urllib3 .PoolManager (** pool_manager_init_args )
259271
260- def __init__ (self , remote_server_addr : str , keep_alive : bool = False , ignore_proxy : bool = False ):
272+ def __init__ (
273+ self ,
274+ remote_server_addr : str ,
275+ keep_alive : bool = False ,
276+ ignore_proxy : bool = False ,
277+ ignore_certificates : bool = False ,
278+ init_args_for_pool_manager : dict = None ,
279+ ):
261280 self .keep_alive = keep_alive
262281 self ._url = remote_server_addr
282+ self ._ignore_certificates = ignore_certificates
283+ self ._init_args_for_pool_manager = init_args_for_pool_manager or {}
263284
264285 # Env var NO_PROXY will override this part of the code
265286 _no_proxy = os .environ .get ("no_proxy" , os .environ .get ("NO_PROXY" ))
@@ -285,6 +306,16 @@ def __init__(self, remote_server_addr: str, keep_alive: bool = False, ignore_pro
285306 self ._conn = self ._get_connection_manager ()
286307 self ._commands = remote_commands
287308
309+ extra_commands = {}
310+
311+ def add_command (self , name , method , url ):
312+ """Register a new command."""
313+ self ._commands [name ] = (method , url )
314+
315+ def get_command (self , name : str ):
316+ """Retrieve a command if it exists."""
317+ return self ._commands .get (name )
318+
288319 def execute (self , command , params ):
289320 """Send a command to the remote server.
290321
@@ -296,7 +327,7 @@ def execute(self, command, params):
296327 - params - A dictionary of named parameters to send with the command as
297328 its JSON payload.
298329 """
299- command_info = self ._commands [ command ]
330+ command_info = self ._commands . get ( command ) or self . extra_commands . get ( command )
300331 assert command_info is not None , f"Unrecognised command { command } "
301332 path_string = command_info [1 ]
302333 path = string .Template (path_string ).substitute (params )
0 commit comments