
    'h                     d    S SK r S SKrS SKr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5      r
g)    N)SeleniumManagerc                   j  ^  \ rS rSrSrSS jr\S 5       r\S 5       r\R                  S 5       r\S 5       r
\
R                  U 4S j5       r
\S	 5       r\R                  U 4S
 j5       r\S 5       r\R                  S 5       r\S 5       r\R                  S 5       rSS jrSS jrS rS rSrU =r$ )Server   a  Manage a Selenium Grid (Remote) Server in standalone mode.

This class contains functionality for downloading the server and starting/stopping it.

For more information on Selenium Grid, see:
    - https://www.selenium.dev/documentation/grid/getting_started/

Parameters:
-----------
host : str
    Hostname or IP address to bind to (determined automatically if not specified)
port : int or str
    Port to listen on (4444 if not specified)
path : str
    Path/filename of existing server .jar file (Selenium Manager is used if not specified)
version : str
    Version of server to download (latest version if not specified)
log_level : str
    Logging level to control logging output ("INFO" if not specified)
    Available levels: "SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST"
env: collections.abc.Mapping
    Mapping that defines the environment variables for the server process
c                     U(       a  U(       a  [        S5      eXl        X l        X0l        X@l        XPl        X`l        S U l        g )NzCNot allowed to specify a version when using an existing server path)	TypeErrorhostportpathversion	log_levelenvprocess)selfr	   r
   r   r   r   r   s          i/var/www/home/psychics-availability/venv/lib/python3.13/site-packages/selenium/webdriver/remote/server.py__init__Server.__init__7   s8    Gabb			"    c                 ^    U R                   b  U R                   OSnSU SU R                   S3$ )N	localhostzhttp://:z/status)r	   r
   )r   r	   s     r   
status_urlServer.status_urlC   s/     II1tyy{a		{'22r   c                     U R                   $ N)_pathr   s    r   r   Server.pathH       zzr   c                     U(       a2  [         R                  R                  U5      (       d  [        SU 35      eXl        g )Nz"Can't find server .jar located at )osr   existsOSErrorr   )r   r   s     r   r   r   L   s/    t,,>tfEFF
r   c                     U R                   $ r   )_portr   s    r   r
   Server.portR   r   r   c                    >  [        U5      nSUs=::  a  S::  d  O  [        S5      eXl        g ! [         a    [        TR                   SU S35      ef = f)Nz".__init__() got an invalid port: ''r   i  zport must be 0-65535)int
ValueErrorr   __name__r%   )r   r
   	__class__s     r   r
   r&   V   sh    	^t9D T"U"344
	  	^y1122TUYTZZ[\]]	^s	   / &Ac                     U R                   $ r   )_versionr   s    r   r   Server.version`   s    }}r   c                    > U(       a@  [         R                  " S[        U5      5      (       d  [        TR                   SU S35      eXl        g )Nz^\d+\.\d+\.\d+$z%.__init__() got an invalid version: 'r(   )rematchstrr   r+   r.   )r   r   r,   s     r   r   r/   d   sD    88.G==9#5#5"66[\c[dde fggr   c                     U R                   $ r   )
_log_levelr   s    r   r   Server.log_levelk   s    r   c                 X    SnX;  a  [        SSR                  U5       35      eXl        g )N)SEVEREWARNINGINFOCONFIGFINEFINERFINESTzlog_level must be one of: z, )r   joinr5   )r   r   levelss      r   r   r6   o   s/    S"869J8KLMM#r   c                     U R                   $ r   )_envr   s    r   r   
Server.envv   s    yyr   c                 ~    Ub4  [        U[        R                  R                  5      (       d  [	        S5      eXl        g )Nz.env must be a mapping of environment variables)
isinstancecollectionsabcMappingr   rB   )r   r   s     r   r   rC   z   s.    ?:c;??3J3J#K#KLMM	r   c                 n   [         R                   " 5       n[         R                   " 5       U-
  U:  a+   [        R                  R                  U R                  5        gg! [        R
                  R                   a    [         R                  " S5         Of = f[         R                   " 5       U-
  U:  a  M  NZ)NTg?F)timeurllibrequesturlopenr   errorURLErrorsleep)r   timeoutstarts      r   _wait_for_serverServer._wait_for_server   s~    		iikE!G+ &&t7  <<((  

3 	 iikE!G+s   )A 4BBc                 h    S/nUb  UR                  U5        [        5       R                  U5      S   $ )zaDownload the server if it doesn't already exist.

Latest version is downloaded unless specified.
z--griddriver_path)appendr   binary_paths)r   r   argss      r   download_if_neededServer.download_if_needed   s6    
 zKK  --d3MBBr   c                    U R                   c  U R                  U R                  5      OU R                   n[        R                  " S5      nUc  [        S5      eUSUSS[        U R                  5      SU R                  SS	S
S	/nU R                  b  UR                  SU R                  /5        U R                  b  U R                  OSn [        R                  " [        R                  [        R                  5       nUR                  X@R                  45        SSS5        [        SU R                   35      e! , (       d  f       N&= f! [          a    [#        S5        [$        R&                  " X0R(                  S9U l        [#        SU R*                  R,                   35        U R/                  5       (       d  [1        SU R2                   35      e[#        S5         U R*                  $ f = f)zStart the server.

Selenium Manager will detect the server location and download it if necessary,
unless an existing server path was specified.
NjavazJCan't find java on system PATH. JRE is required to run the Selenium serverz-jar
standalonez--portz--log-levelz--selenium-managertruez--enable-managed-downloadsz--hostr   zDSelenium server is already running, or something else is using port zStarting Selenium server...)r   z$Selenium server running as process: z)Timed out waiting for Selenium server at zSelenium server is ready)r   rZ   r   shutilwhichr#   r3   r
   r   r	   extendsocketAF_INETSOCK_STREAMconnectConnectionErrorConnectionRefusedErrorprint
subprocessPopenr   r   pidrS   TimeoutErrorr   )r   r   	java_pathcommandr	   socks         r   rR   Server.start   s    9=		8It&&t||4tyyLL(	fgg 		NNN (
 99 NNHdii01 II1tyy{
	.v~~v/A/ABddII./ C!$himirirhs"tuu CB & 	./0%++GBDL89I9I8JKL((**"%NtN_#`aa,-||	.s+   
3E =D: E :
EE BG+*G+c                     U R                   c  [        S5      eU R                   R                  5       c4  U R                   R                  5         U R                   R	                  5         SU l         [        S5        g)zStop the server.NzSelenium server isn't runningz#Selenium server has been terminated)r   RuntimeErrorpoll	terminatewaitri   r   s    r   stopServer.stop   s[    <<>??||  "*&&(!!#DL78r   )rB   r5   r   r%   r.   r   r	   r   r   r
   r   r   )Ni\  NNr:   N)
   r   )r+   
__module____qualname____firstlineno____doc__r   propertyr   r   setterr
   r   r   r   rS   rZ   rR   rw   __static_attributes____classcell__)r,   s   @r   r   r      s   0
 3 3   
[[ 
   
[[    ^^      $ $   	ZZ 
C*X	9 	9r   r   )rF   r!   r1   r`   rc   rj   rJ   rK   *selenium.webdriver.common.selenium_managerr   r    r   r   <module>r      s.   $  	 	      Fk9 k9r   