
    Y j                     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                     ^  \ rS rSrSr        SS jr\S 5       r\R                  S 5       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 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/

Args:
    host: Hostname or IP address to bind to (determined automatically if not specified).
    port: Port to listen on (4444 if not specified).
    path: Path/filename of existing server .jar file (Selenium Manager is used if not specified).
    version: Version of server to download (latest version if not specified).
    log_level: Logging level to control logging output ("INFO" if not specified).
        Available levels: "SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST".
    env: Mapping that defines the environment variables for the server process.
    java_path: Path to the java executable to run the server.
c	                     U(       a  U(       a  [        S5      eXl        X l        X0l        X@l        XPl        X`l        Xpl        Xl        S U l	        g )NzCNot allowed to specify a version when using an existing server path)
	TypeErrorhostportpathversion	log_levelenv	java_pathstartup_timeoutprocess)	selfr	   r
   r   r   r   r   r   r   s	            q/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/selenium/webdriver/remote/server.py__init__Server.__init__1   sE     Gabb			"".    c                     U R                   $ N)_startup_timeoutr   s    r   r   Server.startup_timeoutI   s    $$$r   c                 $    [        U5      U l        g r   )intr   )r   timeouts     r   r   r   M   s     #Gr   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_urlQ   s/     II1tyy{a		{'22r   c                     U R                   $ r   )_pathr   s    r   r   Server.pathV       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&   Z   s/    t,,>tfEFF
r   c                     U R                   $ r   )_portr   s    r   r
   Server.port`   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)r   
ValueErrorr   __name__r-   )r   r
   	__class__s     r   r
   r.   d   sh    	^t9D T"U"344
	  	^y1122TUYTZZ[\]]	^s	   / &Ac                     U R                   $ r   )_versionr   s    r   r   Server.versionn   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: 'r0   )rematchstrr   r2   r5   )r   r   r3   s     r   r   r6   r   sD    88.G==9#5#5"66[\c[dde fggr   c                     U R                   $ r   )
_log_levelr   s    r   r   Server.log_levely       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   joinr<   )r   r   levelss      r   r   r=   }   s/    S"869J8KLMM#r   c                     U R                   $ r   )_envr   s    r   r   
Server.env   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   rJ   )r   r   s     r   r   rK      s.    ?:c;??3J3J#K#KLMM	r   c                     U R                   $ r   )
_java_pathr   s    r   r   Server.java_path   r>   r   c                     U(       a2  [         R                  R                  U5      (       d  [        SU 35      eXl        g )Nz&Can't find java executable located at )r)   r   r*   r+   rR   )r   r   s     r   r   rS      s/    RWW^^I66B9+NOO#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   r   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U R                  =(       d    [        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 R1                  U R2                  S9(       d  [5        SU R6                   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: )r   z)Timed out waiting for Selenium server at zSelenium server is ready)r   re   r   r   shutilwhichr+   r:   r
   r   r	   extendsocketAF_INETSOCK_STREAMconnectConnectionErrorConnectionRefusedErrorprint
subprocessPopenr   r   pidr^   r   TimeoutErrorr"   )r   r   r   commandr	   socks         r   r]   Server.start   s    9=		8It&&t||4tyyNN:fll6&:	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((1E1E(F"%NtN_#`aa,-||	.s+   3E E- E 
EE BHH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waitrt   r   s    r   stopServer.stop   s[    <<>??||  "*&&(!!#DL78r   )rJ   rR   r<   r%   r-   r   r5   r   r	   r   r   r   r
   r   r   r   )Ni\  NNrB   NN
   )r   r   )r2   
__module____qualname____firstlineno____doc__r   propertyr   setterr"   r   r
   r   r   r   r   r^   re   r]   r   __static_attributes____classcell__)r3   s   @r   r   r      s   ( 0 % % - - 3 3   
[[ 
   
[[    ^^      $ $   	ZZ 
   $ $
C*X	9 	9r   r   )rN   r)   r8   rk   rn   ru   rV   rW   *selenium.webdriver.common.selenium_managerr   r    r   r   <module>r      s.   $  	 	      FC9 C9r   