Ë
    `§1hˆ%  ã                   óþ   — 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mZmZmZ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  ej@                  e!«      Z" G d„ de«      Z#y)é    N)ÚABCÚabstractmethod)ÚIOBase)Úsystem)ÚPIPE)Úsleep)ÚIOÚAnyÚListÚMappingÚOptionalÚUnionÚcast)Úrequest)ÚURLError)ÚWebDriverException)ÚSubprocessStdAlias)Úutilsc                   ó2  — e Zd ZdZ	 	 	 	 	 ddee   dedee   deee	e	f      dee   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e   fd„Zy)ÚServicea™  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`.
    :param 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                 ó¦  — t        |t        «      r"t        t        t	        |dd¬«      «      | _        n‘|t        j                  k(  r*t        t        t        t        t        f      d «      | _        nT|�|t        j                  k(  r8t        t        t        t        t        f      t        j                  «      | _        n|| _        |xs t        j                  «       | _        |j                  di «      | _        | j                   j                  dd«      | _        |xs t$        j&                  | _        || _        | j-                  «       xs || _        y )Nza+zutf-8)ÚencodingÚpopen_kwÚcreation_flagsr   )Ú
isinstanceÚstrr   r   Úopenr   Ú
subprocessÚSTDOUTr   r   ÚintÚDEVNULLr   Ú	free_portr   Úpopr   r    ÚosÚenvironr   ÚDRIVER_PATH_ENV_KEYÚenv_pathÚ_path)Úselfr   r   r   r   r   Úkwargss          ú_/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/selenium/webdriver/common/service.pyÚ__init__zService.__init__1   sô   € ô �j¤#Ô&Ü"¤6¬4°
¸DÈ7Ô+SÓTˆD�OØœ:×,Ñ,Ò,Ü"¤8¬E´#´v°+Ñ,>Ñ#?ÀÓFˆD�OØÐ :´×1CÑ1CÒ#CÜ"¤8¬E´#´v°+Ñ,>Ñ#?Ä×ASÑASÓTˆ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    r1   Úservice_urlzService.service_urlK   s#   € ð œ×-Ñ-¨k¸4¿9¹9ÓEÐFÐGÐGr3   c                 ó   — t        d«      ‚)z7A List of program arguments (excluding the executable).z2This method needs to be implemented in a sub class)ÚNotImplementedErrorr7   s    r1   Úcommand_line_argszService.command_line_argsP   s   € ô "Ð"VÓWÐWr3   c                 ó"   — | j                   xs dS )NÚ )r.   r7   s    r1   ÚpathzService.pathU   s   € à�z‰zÒ˜RÐr3   Úvaluec                 ó$   — t        |«      | _        y ©N)r"   r.   )r/   r?   s     r1   r>   zService.pathY   s   € ä˜“Zˆ�
r3   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                   › �«      ‚Œ_)
z³Starts 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{®Gáz„?gš™™™™™©?g      à?é   éF   zCan not connect to the Service )r.   r   Ú_start_processÚassert_process_still_runningÚis_connectabler   Úmin)r/   Úcounts     r1   ÚstartzService.start]   s“   € ð �:‰:ÐÜ$Ð%CÓDÐDØ×Ñ˜DŸJ™JÔ'àˆØØ×-Ñ-Ô/Ø×"Ñ"Ô$Øä”#�d˜T E™\Ñ)¨3Ó/Ô0Ø�Q‰JˆEØ˜Š{Ü(Ð+JÈ4Ï:É:È,Ð)WÓXÐXð r3   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     r1   rG   z$Service.assert_process_still_runnings   s;   € à—l‘l×'Ñ'Ó)ˆÙÜ$ x°·
±
¨|Ð;bÐcnÐboÐ%pÓqÐqð r3   c                 ó@   — t        j                  | j                  «      S )zfEstablishes a socket connection to determine if the service running
        on the port is accessible.)r   rH   r   r7   s    r1   rH   zService.is_connectabley   s   € ô ×#Ñ# D§I¡IÓ.Ð.r3   c                 óÂ   — 	 t        j                  | j                  › d�«       t	        d«      D ]  }| j                  «       s yt        d«       Œ! y# t        $ r Y yw xY w)zcDispatch an HTTP request to the shutdown endpoint for the service in
        an attempt to stop it.z	/shutdownNé   rD   )r   Úurlopenr8   r   ÚrangerH   r   )r/   Ú_s     r1   Úsend_remote_shutdown_commandz$Service.send_remote_shutdown_command~   s`   € ð	Ü�O‰O˜t×/Ñ/Ð0°	Ð:Ô;ô �r“ò 	ˆAØ×&Ñ&Ô(ÙÜ�!�Hñ	øô ò 	Ùð	ús   ‚"A Á	AÁAc                 óþ  — | j                   t        t        j                  hvrnt	        | j                   t
        «      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   Úcloser&   r*   rM   rN   rV   Ú	TypeErrorÚ_terminate_processr7   s    r1   ÚstopzService.stop‹   s¾   € ð �?‰?¤4¬×);Ñ);Ð"<Ñ<Ü˜$Ÿ/™/¬6Ô2Ø—‘×%Ñ%Õ'Ü˜DŸO™O¬SÔ1Ü—‘˜Ÿ™Ô)à�<‰<Ð#¨¯©×(9Ñ(9Ó(;Ð(Cð*Ø×1Ñ1Ô3ð ×'Ñ'Õ)ð )DÐ#øô ò Ùðûð ×'Ñ'Õ)ús$   Â8C Ã	C'Ã$C* Ã&C'Ã'C* Ã*C<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.T)Úexc_infoz"Error terminating service process.N)rM   ÚstdinÚstdoutÚstderrrX   ÚAttributeErrorÚ	terminateÚwaitr$   ÚTimeoutExpiredÚloggerÚerrorÚkillÚOSError)r/   r_   r`   ra   Ústreams        r1   rZ   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rA   )r[   Ú	Exceptionr7   s    r1   Ú__del__zService.__del__»   s"   € ð	Ø�I‰I�KøÜò 	Ùð	ús   ‚ “	žr>   c                 óL  — |g}|j                  | j                  «       «       | j                  j                  dt	        «       dk7  «      }	 d}t	        «       dk(  rOt        j                  «       }t
        j                  t
        j                  z  |_	        t
        j                  |_        t        j                  |f| j                  |t        t        t         t"        t$        t&           f      | j(                  «      t        t        t         t"        t$        t&           f      | j(                  «      t*        | j,                  |dœ| j                  ¤Ž| _        t0        j3                  d| j4                  | j.                  j6                  | j,                  | j(                  «       y# t8        $ r ‚ t:        $ rq}|j<                  t<        j>                  k(  rN| j4                  €tA        d«      ‚tA        dtB        jD                  jG                  | j4                  «      › d�«      |‚‚ d}~ww xY w)	zmCreates a subprocess by executing the command provided.

        :param cmd: full command to execute
        Ú	close_fdsÚWindowsN)r   ro   r`   ra   r_   ÚcreationflagsÚstartupinfozNStarted executable: `%s` in a child process with pid: %s using %s to output %srC   ú'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	   r
   r   r   r    rM   rf   Údebugr.   ÚpidrY   ri   ÚerrnoÚEACCESr   r*   r>   Úbasename)r/   r>   ÚcmdÚclose_file_descriptorsÚ
start_infoÚerrs         r1   rF   zService._start_processÆ   s¶  € ð
 ˆfˆØ�
‰
�4×)Ñ)Ó+Ô,Ø!%§¡×!2Ñ!2°;ÄÃÈIÑ@UÓ!VÐð"	ØˆJÜ‹x˜9Ò$Ü'×3Ñ3Ó5�
Ü%/×%BÑ%BÄZ×EdÑEdÑ%d�
Ô"Ü)3×);Ñ);�
Ô&ä%×+Ñ+Øð
à—H‘HØ0ÜœH¤U¬3´´3±¨<Ñ%8Ñ9¸4¿?¹?ÓKÜœH¤U¬3´´3±¨<Ñ%8Ñ9¸4¿?¹?ÓKÜØ"×1Ñ1Ø&ñ
ð —-‘-ñ
ˆDŒLô �L‰LØ`Ø—
‘
Ø—‘× Ñ Ø×#Ñ#Ø—‘õøô ò 	ØÜò 	Ø�y‰yœEŸL™LÒ(Ø—:‘:Ð%Ü,Ð-KÓLÐLÜ(ØœŸ™×(Ñ(¨¯©Ó4Ð5Ð5]Ð^óàðð ûð	ús   ÁEF  Æ H#Æ2A,HÈH#c                 ó\   — | j                   r t        j                  | j                   d «      S y rA   )r,   r*   Úgetenvr7   s    r1   r-   zService.env_pathò   s%   € Ø×#Ò#Ü—9‘9˜T×5Ñ5°tÓ<Ð<Ør3   )Nr   NNN)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   r&   r   r   r
   r2   Úpropertyr8   r   r   r;   r>   ÚsetterrK   rG   ÚboolrH   rV   r[   rZ   rm   rF   r-   © r3   r1   r   r   %   sE  „ ñ	ð *.ØØ37Ø+/Ø-1ñ8à! #™ð8ð ð8ð Ð/Ñ0ð	8ð
 �g˜c 3˜hÑ'Ñ(ð8ð & c™]ð8ð 
ó8ð4 ðH˜Sò Hó ðHð ðX 4¨¡9ò Xó ðXð ð �cò  ó ð ð 
‡[�[ð ˜#ð   $ò  ó ð óYó,rð/ ó /ó
ó*ó"Nó>	ð* 3ð *¨4ó *ðX˜( 3™-ô r3   r   )$r~   Úloggingr*   r$   Úabcr   r   Úior   Úplatformr   r   Útimer   Útypingr	   r
   r   r   r   r   r   Úurllibr   Úurllib.errorr   Úselenium.common.exceptionsr   Úselenium.typesr   Úselenium.webdriver.commonr   Ú	getLoggerr‡   rf   r   rŽ   r3   r1   ú<module>r›      sZ   ðó" Û Û 	Û ß #Ý Ý Ý Ý ß @× @Ñ @Ý Ý !å 9Ý -Ý +à	ˆ×	Ñ	˜8Ó	$€ôPˆcõ Pr3   