@@ -143,6 +143,14 @@ class RemoteConnection:
143143 )
144144 _ca_certs = os .getenv ("REQUESTS_CA_BUNDLE" ) if "REQUESTS_CA_BUNDLE" in os .environ else certifi .where ()
145145
146+ system = platform .system ().lower ()
147+ if system == "darwin" :
148+ system = "mac"
149+
150+ # Class variables for headers
151+ extra_headers = None
152+ user_agent = f"selenium/{ __version__ } (python { system } )"
153+
146154 @classmethod
147155 def get_timeout (cls ):
148156 """:Returns:
@@ -196,14 +204,10 @@ def get_remote_connection_headers(cls, parsed_url, keep_alive=False):
196204 - keep_alive (Boolean) - Is this a keep-alive connection (default: False)
197205 """
198206
199- system = platform .system ().lower ()
200- if system == "darwin" :
201- system = "mac"
202-
203207 headers = {
204208 "Accept" : "application/json" ,
205209 "Content-Type" : "application/json;charset=UTF-8" ,
206- "User-Agent" : f"selenium/ { __version__ } (python { system } )" ,
210+ "User-Agent" : cls . user_agent ,
207211 }
208212
209213 if parsed_url .username :
@@ -213,6 +217,9 @@ def get_remote_connection_headers(cls, parsed_url, keep_alive=False):
213217 if keep_alive :
214218 headers .update ({"Connection" : "keep-alive" })
215219
220+ if cls .extra_headers :
221+ headers .update (cls .extra_headers )
222+
216223 return headers
217224
218225 def _get_proxy_url (self ):
@@ -236,7 +243,12 @@ def _separate_http_proxy_auth(self):
236243
237244 def _get_connection_manager (self ):
238245 pool_manager_init_args = {"timeout" : self .get_timeout ()}
239- if self ._ca_certs :
246+ pool_manager_init_args .update (self ._init_args_for_pool_manager .get ("init_args_for_pool_manager" , {}))
247+
248+ if self ._ignore_certificates :
249+ pool_manager_init_args ["cert_reqs" ] = "CERT_NONE"
250+ urllib3 .disable_warnings (urllib3 .exceptions .InsecureRequestWarning )
251+ elif self ._ca_certs :
240252 pool_manager_init_args ["cert_reqs" ] = "CERT_REQUIRED"
241253 pool_manager_init_args ["ca_certs" ] = self ._ca_certs
242254
@@ -252,9 +264,18 @@ def _get_connection_manager(self):
252264
253265 return urllib3 .PoolManager (** pool_manager_init_args )
254266
255- def __init__ (self , remote_server_addr : str , keep_alive : bool = False , ignore_proxy : bool = False ):
267+ def __init__ (
268+ self ,
269+ remote_server_addr : str ,
270+ keep_alive : bool = False ,
271+ ignore_proxy : bool = False ,
272+ ignore_certificates : bool = False ,
273+ init_args_for_pool_manager : dict = None ,
274+ ):
256275 self .keep_alive = keep_alive
257276 self ._url = remote_server_addr
277+ self ._ignore_certificates = ignore_certificates
278+ self ._init_args_for_pool_manager = init_args_for_pool_manager or {}
258279
259280 # Env var NO_PROXY will override this part of the code
260281 _no_proxy = os .environ .get ("no_proxy" , os .environ .get ("NO_PROXY" ))
@@ -280,6 +301,16 @@ def __init__(self, remote_server_addr: str, keep_alive: bool = False, ignore_pro
280301 self ._conn = self ._get_connection_manager ()
281302 self ._commands = remote_commands
282303
304+ extra_commands = {}
305+
306+ def add_command (self , name , method , url ):
307+ """Register a new command."""
308+ self ._commands [name ] = (method , url )
309+
310+ def get_command (self , name : str ):
311+ """Retrieve a command if it exists."""
312+ return self ._commands .get (name )
313+
283314 def execute (self , command , params ):
284315 """Send a command to the remote server.
285316
@@ -291,7 +322,7 @@ def execute(self, command, params):
291322 - params - A dictionary of named parameters to send with the command as
292323 its JSON payload.
293324 """
294- command_info = self ._commands [ command ]
325+ command_info = self ._commands . get ( command ) or self . extra_commands . get ( command )
295326 assert command_info is not None , f"Unrecognised command { command } "
296327 path_string = command_info [1 ]
297328 path = string .Template (path_string ).substitute (params )
0 commit comments