
    vKg
%                        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  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  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  S SKJr  S SKJr  \R6                  " \5      r " S S\5      rg)    N)ABC)abstractmethod)IOBase)system)PIPE)sleep)Optional)cast)request)URLError)WebDriverException)SubprocessStdAlias)utilsc                      \ rS rSrSr     SS\S\S\S\R                  \R                  \R                  \R                  4      S\S	S4S
 jjr\S	\4S j5       r\S	\R                   \   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	\	\   4S jrSrg)Service(   a  The abstract base class for all service objects.  Services typically
launch a child program in a new process as an interim process to
communicate with a browser.

:param executable: install path of the executable.
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
:param log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file.
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
Nexecutable_pathport
log_outputenvdriver_path_env_keyreturnc           	         [        U[        5      (       a  [        [        [	        USSS95      U l        OU[        R                  :X  a>  [        [        R                  [        R                  [        [        4      S 5      U l        OiUb  U[        R                  :X  aL  [        [        R                  [        R                  [        [        4      [        R                  5      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 )Nza+zutf-8)encodingpopen_kwcreation_flagsr   )
isinstancestrr
   r   openr   
subprocessSTDOUTtypingr	   UnionintDEVNULLr   	free_portr   popr   r   osenvironr   DRIVER_PATH_ENV_KEYenv_path_path)selfr   r   r   r   r   kwargss          a/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/selenium/webdriver/common/service.py__init__Service.__init__3   s    j#&&"64
D7+STDO:,,,"6??6<<V3L#MtTDO:1C1C#C"6??6<<V3L#MzOaOabDO(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_urlM   s#     --k499EFGGr2   c                     [        S5      e)z7A List of program arguments (excluding the executable).z2This method needs to be implemented in a sub class)NotImplementedErrorr6   s    r/   command_line_argsService.command_line_argsR   s     ""VWWr2   c                 ,    U R                   =(       d    S$ )N )r,   r6   s    r/   pathService.pathW   s    zzRr2   valuec                 $    [        U5      U l        g N)r   r,   )r-   rA   s     r/   r?   r@   [   s    Z
r2   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.

:Exceptions:
 - 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.start_   s     ::$%CDDDJJ'--/""$$#dTE\)3/0QJE{(+J4::,)WXX r2   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/   rI   $Service.assert_process_still_runningu   s;    ll'')$x

|;bcnbo%pqq r2   c                 B    [         R                  " U R                  5      $ )z^Establishes a socket connection to determine if the service running
on the port is accessible.)r   rJ   r   r6   s    r/   rJ   Service.is_connectable{   s     ##DII..r2   c                      [         R                  " U R                   S35        [	        S5       H%  nU R                  5       (       d    g[        S5        M'     g! [         a     gf = f)z[Dispatch an HTTP request to the shutdown endpoint for the service in
an attempt to stop it.z	/shutdownN   rF   )r   urlopenr7   r   rangerJ   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;  ay  [	        U R                   [
        5      (       a  U R                   R                  5         O?[	        U R                   [        5      (       a   [        R                  " U R                   5        U R                  b"   U R                  5         U R                  5         gg! [         a     Nf = f)zStops the service.N)r   r   r    r%   r   r   closer$   r(   rP   r[   	TypeError_terminate_processr6   s    r/   stopService.stop   s     ??4););"<<$//622%%'DOOS11)<<#113 ##% $  s   ,C 
CC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)rP   stdinstdoutstderrr^   AttributeError	terminatewaitr    TimeoutExpiredloggererrorkillOSError)r-   rf   rg   rh   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rC   )ra   	Exceptionr6   s    r/   __del__Service.__del__   s"    	IIK 		s    
  r?   c                    U/nUR                  U R                  5       5        U R                  R                  S[	        5       S:g  5      n Sn[	        5       S:X  aP  [
        R                  " 5       n[
        R                  [
        R                  -  Ul	        [
        R                  Ul        [
        R                  " U4U R                  U[        [        R                   [        R"                  [$        [        R&                  [        R(                     4      U R*                  5      [        [        R                   [        R"                  [$        [        R&                  [        R(                     4      U R*                  5      [,        U R.                  US.U R                  D6U l        [2        R5                  SU R6                  U R0                  R8                  U R.                  U R*                  5        g! [:         a    e [<         as  nUR>                  [>        R@                  :X  aO  U R6                  c  [C        S5      e[C        S[D        RF                  RI                  U R6                  5       S35      Uee SnAff = f)	z]Creates a subprocess by executing the command provided.

:param cmd: full command to execute
	close_fdsWindowsN)r   rx   rg   rh   rf   creationflagsstartupinfozNStarted executable: `%s` in a child process with pid: %s using %s to output %srE   'z(' executable may have wrong permissions.)%extendr;   r   r'   r   r    STARTUPINFOCREATE_NEW_CONSOLESTARTF_USESHOWWINDOWdwFlagsSW_HIDEwShowWindowPopenr   r
   r"   r	   r#   r$   IOAnyr   r   r   rP   rm   debugr,   pidr_   rp   errnoEACCESr   r(   r?   basename)r-   r?   cmdclose_file_descriptors
start_infoerrs         r/   rH   Service._start_process   s   
 f

4))+,!%!2!2;I@U!V"	Jx9$'335
%/%B%BZEdEd%d
")3););
&%++
HH0FOOFLLfii

>S9S,TUW[WfWfgFOOFLLfii

>S9S,TUW[WfWfg"11&
 --
DL LL`

  ##  	 	yyELL(::%,-KLL(((455]^ 	s   F'G3 3I:A.I55I:c                 D    [         R                  " U R                  S 5      $ rC   )r(   getenvr*   r6   s    r/   r+   Service.env_path   s    yy11488r2   )r*   r,   r   r   r   r   r   rP   )Nr   NNN)r   N)__name__
__module____qualname____firstlineno____doc__r   r$   r   r"   r	   Mappingr   r0   propertyr7   r   Listr;   r?   setterrM   rI   boolrJ   r[   ra   r`   ru   rH   r+   __static_attributes__ r2   r/   r   r   (   sM     $)-GK#'88 8 '	8
 __V^^FJJ

,BCD8 !8 
84 HS H H X6;;s#3 X X  c     
[[ #  $    Y,r/ /
& N>	*3 *4 *X9(3- 9r2   r   )r   loggingr(   r    r"   abcr   r   ior   platformr   r   timer   r	   r
   urllibr   urllib.errorr   selenium.common.exceptionsr   selenium.typesr   selenium.webdriver.commonr   	getLoggerr   rm   r   r   r2   r/   <module>r      s[   "   	            ! 9 - +			8	$L9c L9r2   