Ë
    cQbjÜ&  ã                   óæ   — d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZ  ej4                  e«      Z G d„ de«      Zy)é    N)ÚABCÚabstractmethod)ÚMapping)ÚIOBase)ÚPIPE)Úsleep)ÚIOÚAny)Úrequest)ÚURLError)ÚWebDriverException)Úutilsc                   óD  — e Zd ZdZ	 	 	 	 	 ddedz  dedeez  ee   z  dz  deeef   dz  dedz  ddfd	„Z	e
defd
„«       Zedee   fd„«       Ze
defd„«       Zej                   deddfd„«       Zdd„Zdd„Zdefd„Zdd„Zdd„Zdd„Zdd„Zdeddfd„Zdedz  fd„Zy)ÚServiceaÈ  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                 ó"  — d| _         |  t        |t        «      rt        |dd¬«      | _        d| _         nM|t
        j                  k(  rd | _        n2|�|t
        j                  k(  rt
        j                  | _        n|| _        |xs t        j                  «       | _
        |j                  di «      | _        | j                  j                  dd«      | _        |xs t        j                  | _        || _        | j%                  «       xs || _        y )	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          úT/var/www/html/venv/lib/python3.12/site-packages/selenium/webdriver/common/service.pyÚ__init__zService.__init__4   sÖ   € ð !&ˆÔÙÜ�j¤#Ô&Ü" :¨t¸gÔFˆDŒOØ$(ˆDÕ!Øœ:×,Ñ,Ò,Ø"ˆD�OØÐ :´×1CÑ1CÒ#CÜ(×0Ñ0ˆD�Oà(ˆDŒOàÒ-œEŸO™OÓ-ˆŒ	àŸ
™
 :¨rÓ2ˆŒØ"Ÿm™m×/Ñ/Ð0@À!ÓDˆÔØÒ$œ"Ÿ*™*ˆŒØ#6ˆÔ Ø—]‘]“_Ò7¨ˆ�
ó    c                 óH   — dt        j                  d| j                  «      › �S )zGets the url of the Service.zhttp://Ú	localhost)r   Újoin_host_portr   ©r)   s    r+   Úservice_urlzService.service_urlQ   s#   € ð œ×-Ñ-¨k¸4¿9¹9ÓEÐFÐGÐGr-   c                 ó   — t        d«      ‚)z7A List of program arguments (excluding the executable).z2This method needs to be implemented in a sub class)ÚNotImplementedErrorr1   s    r+   Úcommand_line_argszService.command_line_argsV   s   € ô "Ð"VÓWÐWr-   c                 ó"   — | j                   xs dS )NÚ )r(   r1   s    r+   ÚpathzService.path[   s   € à�z‰zÒ˜RÐr-   Úvaluec                 ó$   — t        |«      | _        y ©N)r   r(   )r)   r9   s     r+   r8   zService.path_   s   € ä˜“Zˆ�
r-   c                 ó¶  — | j                   €t        d«      ‚| j                  | j                   «       d}	 	 | j                  «        | j	                  «       ryt        t        dd|z  z   d«      «       |dz  }|d	k(  rt        d
| j                   › �«      ‚Œ_# t        $ r9 	 | j                  «        ‚ # t        $ r t        j                  dd¬«       Y ‚ w xY ww xY w)z³Starts 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   Tg{®Gáz„?gš™™™™™©?g      à?é   éF   zCan not connect to the Service z,Error stopping service after a failed start.©Úexc_info)r(   r   Ú_start_processÚassert_process_still_runningÚis_connectabler   ÚminÚBaseExceptionÚstopÚ	ExceptionÚloggerÚerror)r)   Úcounts     r+   ÚstartzService.startc   så   € ð �:‰:ÐÜ$Ð%CÓDÐDØ×Ñ˜DŸJ™JÔ'àˆð	ØØ×1Ñ1Ô3Ø×&Ñ&Ô(Øä”c˜$ ¨¡Ñ-¨sÓ3Ô4Ø˜‘
�Ø˜B’;Ü,Ð/NÈtÏzÉzÈlÐ-[Ó\Ð\ð øô ò 	ð\Ø—	‘	”ð øô ò \Ü—‘ÐKÐVZ�Õ[Øð\úð	ús5   ¶!B Á>B Â	CÂ B1Â0CÂ1 CÃCÃCÃCc                 ór   — | j                   j                  «       }|rt        d| j                  › d|› �«      ‚y)z1Check if the underlying process is still running.zService z' unexpectedly exited. Status code was: N)ÚprocessÚpollr   r(   )r)   Úreturn_codes     r+   rC   z$Service.assert_process_still_running€   s;   € à—l‘l×'Ñ'Ó)ˆÙÜ$ x°·
±
¨|Ð;bÐcnÐboÐ%pÓqÐqð r-   c                 ó@   — t        j                  | j                  «      S )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   r1   s    r+   rD   zService.is_connectable†   s   € ô ×'Ñ'¨¯	©	Ó2Ð2r-   c                 óÒ   — 	 t        j                  | j                  › d�d¬«       t        d«      D ]  }| j                  «       s yt        d«       Œ! y# t        t        f$ r Y yw xY w)zFDispatch an HTTP request to the shutdown endpoint to stop the service.z	/shutdowné
   )ÚtimeoutNé   r>   )r   Úurlopenr2   r   ÚTimeoutErrorÚrangerD   r   )r)   Ú_s     r+   Úsend_remote_shutdown_commandz$Service.send_remote_shutdown_command�   sg   € ð	Ü�O‰O˜t×/Ñ/Ð0°	Ð:ÀBÕGô �r“ò 	ˆAØ×&Ñ&Ô(ÙÜ�!�Hñ	øô œ,Ð'ò 	Ùð	ús   ‚$A ÁA&Á%A&c                 ó  — | j                   t        t        j                  hvrzt	        | j                   t
        «      r'| j                  r| j                   j                  «        n9t	        | j                   t        «      rt        j                  | j                   «       | j                  �=| j                  j                  «       €"	 | j                  «        | j                  «        yyy# t        $ r Y Œw xY w# | j                  «        w xY w)zStops the service.N)r   r   r   r!   r   r   r   ÚcloseÚintr$   rN   rO   r[   Ú	TypeErrorÚ_terminate_processr1   s    r+   rG   zService.stopœ   sÄ   € à�?‰?¤4¬×);Ñ);Ð"<Ñ<Ü˜$Ÿ/™/¬6Ô2°t×7LÒ7LØ—‘×%Ñ%Õ'Ü˜DŸO™O¬SÔ1Ü—‘˜Ÿ™Ô)à�<‰<Ð#¨¯©×(9Ñ(9Ó(;Ð(Cð*Ø×1Ñ1Ô3ð ×'Ñ'Õ)ð )DÐ#øô ò Ùðûð ×'Ñ'Õ)ús$   ÃC' Ã'	C3Ã0C6 Ã2C3Ã3C6 Ã6Dc                 ó*  — 	 | j                   j                  | j                   j                  | j                   j                  }}}|||fD ]  }	 |j	                  «        Œ | j                   j                  «        	 | j                   j                  d«       y# t
        $ r Y ŒXw xY w# t        j                  $ r4 t        j                  dd¬«       | j                   j                  «        Y yw xY w# t        $ r t        j                  dd¬«       Y yw xY w)a#  Terminate 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.Tr@   z"Error terminating service process.N)rN   ÚstdinÚstdoutÚstderrr]   ÚAttributeErrorÚ	terminateÚwaitr   ÚTimeoutExpiredrI   rJ   ÚkillÚOSError)r)   rc   rd   re   Ústreams        r+   r`   zService._terminate_process¬   sý   € ð	Nà—‘×"Ñ"Ø—‘×#Ñ#Ø—‘×#Ñ#ð "�6ˆEð
   ¨Ð/ò �ðØ—L‘L•Nðð
 �L‰L×"Ñ"Ô$ð$Ø—‘×!Ñ! "Õ%øô	 &ò Ùðûô
 ×,Ñ,ò $Ü—‘ØjØ!ð ô ð —‘×!Ñ!Ö#ð$ûô ò 	NÜ�L‰LÐ=ÈˆLÖMð	NúsU   ‚A
C/ ÁBÁC/ Á:B% Â	B"ÂC/ Â!B"Â"C/ Â%AC,Ã)C/ Ã+C,Ã,C/ Ã/ DÄDc                 óD   — 	 | j                  «        y # t        $ r Y y w xY wr;   )rG   rH   r1   s    r+   Ú__del__zService.__del__Ë   s"   € ð	Ø�I‰I�KøÜò 	Ùð	ús   ‚ “	žr8   c                 óÀ  — |g}|j                  | j                  «       «       | j                  j                  dt        j
                  dk7  «      }	 d}t        j
                  dk(  rOt        j                  «       }t        j                  t        j                  z  |_
        t        j                  |_        t        j                  |f| j                  || j                  | j                  t         | j"                  |dœ| j                  ¤Ž| _        t&        j)                  d| j*                  | j$                  j,                  | j"                  | j                  «       y# t.        $ r ‚ t0        $ rq}|j2                  t2        j4                  k(  rN| j*                  €t7        d«      ‚t7        dt8        j:                  j=                  | j*                  «      › d�«      |‚‚ d}~ww xY w)	zyCreates a subprocess by executing the command provided.

        Args:
            path: full command to execute
        Ú	close_fdsÚwin32N)r   rp   rd   re   rc   ÚcreationflagsÚstartupinfozNStarted executable: `%s` in a child process with pid: %s using %s to output %sr=   ú'z(' executable may have wrong permissions.)Úextendr5   r   r#   ÚsysÚplatformr   ÚSTARTUPINFOÚCREATE_NEW_CONSOLEÚSTARTF_USESHOWWINDOWÚdwFlagsÚSW_HIDEÚwShowWindowÚPopenr   r   r   r   rN   rI   Údebugr(   Úpidr_   rk   ÚerrnoÚEACCESr   r$   r8   Úbasename)r)   r8   ÚcmdÚclose_file_descriptorsÚ
start_infoÚerrs         r+   rB   zService._start_processÖ   s‰  € ð ˆfˆØ�
‰
�4×)Ñ)Ó+Ô,Ø!%§¡×!2Ñ!2°;ÄÇÁÐPWÑ@WÓ!XÐð"	ØˆJÜ�|‰|˜wÒ&Ü'×3Ñ3Ó5�
Ü%/×%BÑ%BÄZ×EdÑEdÑ%d�
Ô"Ü)3×);Ñ);�
Ô&ä%×+Ñ+Øð
à—H‘HØ0Ø—‘Ø—‘ÜØ"×1Ñ1Ø&ñ
ð —-‘-ñ
ˆDŒLô �L‰LØ`Ø—
‘
Ø—‘× Ñ Ø×#Ñ#Ø—‘õøô ò 	ØÜò 	Ø�y‰yœEŸL™LÒ(Ø—:‘:Ð%Ü,Ð-KÓLÐLÜ(ØœŸ™×(Ñ(¨¯©Ó4Ð5Ð5]Ð^óàðð ûð	ús   ÁDE ÅGÅ,A,GÇGc                 ó\   — | j                   r t        j                  | j                   d «      S y r;   )r&   r$   Úgetenvr1   s    r+   r'   zService.env_path  s%   € Ø×#Ò#Ü—9‘9˜T×5Ñ5°tÓ<Ð<Ør-   )Nr   NNN)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r^   r	   r
   r   r,   Úpropertyr2   r   Úlistr5   r8   ÚsetterrL   rC   ÚboolrD   r[   rG   r`   rn   rB   r'   © r-   r+   r   r   &   sP  „ ñð '+ØØ15Ø(,Ø*.ñ8à˜t™ð8ð ð8ð ˜#‘I  3¡Ñ'¨$Ñ.ð	8ð
 �S˜#�XÑ Ñ%ð8ð ! 4™Zð8ð 
ó8ð: ðH˜Sò Hó ðHð ðX 4¨¡9ò Xó ðXð ð �cò  ó ð ð 
‡[�[ð ˜#ð   $ò  ó ð óó:rð3 ó 3ó
ó*ó Nó>	ð+ 3ð +¨4ó +ðZ˜# ™*ô r-   r   )r�   Úloggingr$   r   rv   Úabcr   r   Úcollections.abcr   Úior   r   Útimer   Útypingr	   r
   Úurllibr   Úurllib.errorr   Úselenium.common.exceptionsr   Úselenium.webdriver.commonr   Ú	getLoggerrŠ   rI   r   r’   r-   r+   ú<module>rž      sT   ðó$ Û Û 	Û Û 
ß #Ý #Ý Ý Ý ß Ý Ý !å 9Ý +à	ˆ×	Ñ	˜8Ó	$€ô`ˆcõ `r-   