
    Y j%                         S SK r S SKrS SKrS SKrS SKrS SKJrJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  S SKJrJr  S SKJr  S S	KJr  S S
KJr  S SKJr  \R4                  " \5      r " S S\5      rg)    N)ABCabstractmethod)Mapping)IOBase)PIPE)sleep)IOAny)request)URLError)WebDriverException)utilsc                   j   \ rS rSrSr     SS\S-  S\S\\-  \\   -  S-  S\	\\4   S-  S\S-  S	S4S
 jjr
\S	\4S j5       r\S	\\   4S j5       r\S	\4S j5       r\R"                  S\S	S4S j5       rSS jrSS jrS	\4S jrSS jrSS jrSS jrSS jrS\S	S4S jrS	\S-  4S jrSrg)Service&   a  Abstract base class for all service objects that manage driver processes.

Services typically launch a child program in a new process as an interim process to
communicate with a browser.

Args:
    executable_path: (Optional) Install path of the executable.
    port: (Optional) Port for the service to run on, defaults to 0 where the operating system will decide.
    log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file.
    env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
    driver_path_env_key: (Optional) Environment variable to use to get the path to the driver executable.
Nexecutable_pathport
log_outputenvdriver_path_env_keyreturnc                 H   SU l         U   [        U[        5      (       a  [        USSS9U l        SU l         OOU[
        R                  :X  a  S U l        O3Ub  U[
        R                  :X  a  [
        R                  U l        OX0l        U=(       d    [        R                  " 5       U l
        UR                  S0 5      U l        U R                  R                  SS5      U l        U=(       d    [        R                  U l        XPl        U R%                  5       =(       d    UU l        g )	NFza+zutf-8)encodingTpopen_kwcreation_flagsr   )_owns_log_output
isinstancestropenr   
subprocessSTDOUTDEVNULLr   	free_portr   popr   r   osenvironr   DRIVER_PATH_ENV_KEYenv_path_path)selfr   r   r   r   r   kwargss          r/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/selenium/webdriver/common/service.py__init__Service.__init__4   s     !&j#&&":tgFDO$(D!:,,,"DO:1C1C#C(00DO(O-EOO-	

:r2"mm//0@!D$"**#6 ]]_7
    c                 J    S[         R                  " SU R                  5       3$ )zGets the url of the Service.zhttp://	localhost)r   join_host_portr   r*   s    r,   service_urlService.service_urlQ   s#     --k499EFGGr/   c                     [        S5      e)z7A List of program arguments (excluding the executable).z2This method needs to be implemented in a sub class)NotImplementedErrorr3   s    r,   command_line_argsService.command_line_argsV   s     ""VWWr/   c                 ,    U R                   =(       d    S$ )N )r)   r3   s    r,   pathService.path[   s    zzRr/   valuec                 $    [        U5      U l        g N)r   r)   )r*   r>   s     r,   r<   r=   _   s    Z
r/   c                 :   U R                   c  [        S5      eU R                  U R                   5        Sn U R                  5         U R	                  5       (       a  g[        [        SSU-  -   S5      5        US-  nUS:X  a  [        S	U R                    35      eMf  )
zStarts the Service.

Raises:
    WebDriverException: Raised either when it can't start the service
        or when it can't connect to the service
NService path cannot be None.r   g{Gz?g?g      ?   F   zCan not connect to the Service )r)   r   _start_processassert_process_still_runningis_connectabler   min)r*   counts     r,   startService.startc   s     ::$%CDDDJJ'--/""$$#dTE\)3/0QJE{(+J4::,)WXX r/   c                 |    U R                   R                  5       nU(       a  [        SU R                   SU 35      eg)z1Check if the underlying process is still running.zService z' unexpectedly exited. Status code was: N)processpollr   r)   )r*   return_codes     r,   rF   $Service.assert_process_still_runningy   s;    ll'')$x

|;bcnbo%pqq r/   c                 B    [         R                  " U R                  5      $ )a  Check if the service is ready via the W3C WebDriver /status endpoint.

This makes an HTTP request to the /status endpoint and verifies if it is ready to accept new sessions.

Returns:
    True if the service is ready to accept new sessions, False otherwise.
)r   is_url_connectabler   r3   s    r,   rG   Service.is_connectable   s     ''		22r/   c                      [         R                  " U R                   S35        [	        S5       H%  nU R                  5       (       d    g[        S5        M'     g! [         a     gf = f)zFDispatch an HTTP request to the shutdown endpoint to stop the service.z	/shutdownN   rC   )r   urlopenr4   r   rangerG   r   )r*   _s     r,   send_remote_shutdown_command$Service.send_remote_shutdown_command   s^    	OOt//0	:; rA&&((!H   		s   #A 
A'&A'c                 @   U R                   [        [        R                  1;  a  [	        U R                   [
        5      (       a,  U R                  (       a  U R                   R                  5         O?[	        U R                   [        5      (       a   [        R                  " U R                   5        U R                  b>  U R                  R                  5       c"   U R                  5         U R                  5         ggg! [         a     Nf = f! U R                  5         f = f)zStops the service.N)r   r   r    r"   r   r   r   closeintr%   rM   rN   rY   	TypeError_terminate_processr3   s    r,   stopService.stop   s    ??4););"<<$//622t7L7L%%'DOOS11)<<#(9(9(;(C*113 '') )D#   '')s$   C; ;
DD DD Dc                 &    U R                   R                  U R                   R                  U R                   R                  p2nXU4 H  n UR	                  5         M     U R                   R                  5          U R                   R                  S5        g! [
         a     M\  f = f! [        R                   a1    [        R                  SSS9  U R                   R                  5          gf = f! [         a    [        R                  SSS9   gf = f)zTerminate the child process.

On POSIX this attempts a graceful SIGTERM followed by a SIGKILL,
on a Windows OS kill is an alias to terminate.  Terminating does
not raise itself if something has gone wrong but (currently)
silently ignores errors here.
<   zTService process refused to terminate gracefully with SIGTERM, escalating to SIGKILL.T)exc_infoz"Error terminating service process.N)rM   stdinstdoutstderrr\   AttributeError	terminatewaitr    TimeoutExpiredloggererrorkillOSError)r*   re   rf   rg   streams        r,   r_   Service._terminate_process   s    	N""#### "E
  /LLN 0
 LL""$$!!"%	 & 
 ,, $j!   !!#$  	NLL=LM	NsU   AC/ BC/ :B' 
B$ C/ #B$$C/ 'AC,)C/ +C,,C/ /DDc                 F     U R                  5         g ! [         a     g f = fr@   )r`   	Exceptionr3   s    r,   __del__Service.__del__   s"    	IIK 		s    
  r<   c                    U/nUR                  U R                  5       5        U R                  R                  S[        R
                  S:g  5      n Sn[        R
                  S:X  aP  [        R                  " 5       n[        R                  [        R                  -  Ul
        [        R                  Ul        [        R                  " U4U R                  UU R                  U R                  [         U R"                  US.U R                  D6U l        [&        R)                  SU R*                  U R$                  R,                  U R"                  U R                  5        g! [.         a    e [0         as  nUR2                  [2        R4                  :X  aO  U R*                  c  [7        S5      e[7        S[8        R:                  R=                  U R*                  5       S35      Uee SnAff = f)	zaCreates a subprocess by executing the command provided.

Args:
    path: full command to execute
	close_fdswin32N)r   rw   rf   rg   re   creationflagsstartupinfozNStarted executable: `%s` in a child process with pid: %s using %s to output %srB   'z(' executable may have wrong permissions.)extendr8   r   r$   sysplatformr    STARTUPINFOCREATE_NEW_CONSOLESTARTF_USESHOWWINDOWdwFlagsSW_HIDEwShowWindowPopenr   r   r   r   rM   rl   debugr)   pidr^   ro   errnoEACCESr   r%   r<   basename)r*   r<   cmdclose_file_descriptors
start_infoerrs         r,   rE   Service._start_process   s    f

4))+,!%!2!2;PW@W!X"	J||w&'335
%/%B%BZEdEd%d
")3););
&%++
HH0"11&
 --
DL LL`

  ##  	 	yyELL(::%,-KLL(((455]^ 	s   DE G$1A.GG$c                 h    U R                   (       a!  [        R                  " U R                   S 5      $ g r@   )r'   r%   getenvr3   s    r,   r(   Service.env_path   s%    ##99T55t<<r/   )	r'   r   r)   r   r   r   r   r   rM   )Nr   NNN)r   N)__name__
__module____qualname____firstlineno____doc__r   r]   r	   r
   r   r-   propertyr4   r   listr8   r<   setterrJ   rF   boolrG   rY   r`   r_   rt   rE   r(   __static_attributes__ r/   r,   r   r   &   sQ    '+15(,*.8t8 8 #I3'$.	8
 S#X%8 !4Z8 
8: HS H H X49 X X  c     
[[ #  $    Y,r3 3
* N>	+3 +4 +Z#* r/   r   )r   loggingr%   r    r}   abcr   r   collections.abcr   ior   r   timer   typingr	   r
   urllibr   urllib.errorr   selenium.common.exceptionsr   selenium.webdriver.commonr   	getLoggerr   rl   r   r   r/   r,   <module>r      sR   $   	  
 # #      ! 9 +			8	$Yc Yr/   