
    ?OOfR                         d dl Z 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 d dlm	Z	 d dl
mZ  ej                  e      Z G d d      Zy)    N)Path)List)WebDriverExceptionc                   r    e Zd ZdZdedefdZedefd       Z	edee
   defd       Zedee   fd       Zy	)
SeleniumManagerzWrapper for getting information from the Selenium Manager binaries.

    This implementation is still in beta, and may change.
    argsreturnc                 R   t        | j                               g|z   }t        j                         t        j
                  k(  r|j                  d       |j                  d       |j                  d       |j                  d       |j                  d       | j                  |      S )zDetermines the locations of the requested assets.

        :Args:
         - args: the commands to send to the selenium manager binary.
        :Returns: dictionary of assets and their path
        z--debugz--language-bindingpythonz--outputjson)str_get_binaryloggergetEffectiveLevelloggingDEBUGappend_run)selfr   s     k/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/selenium/webdriver/common/selenium_manager.pybinary_pathszSeleniumManager.binary_paths%   s     D$$&'(4/##%6KK	"()HJFyy    c                     t        j                  d      x} "t        j                  d|        t	        |       } nddddddd}t
        j                  dv rt        j                         nd}t
        j                  d	v r$t        j                  d
t
        j                         |j                  t
        j                  |f      }|t        dt
        j                   d|       t	        t              j                  j                  |      } | j                         st        d|        t        j                  d|        | S )zDetermines the path of the correct Selenium Manager binary.

        :Returns: The Selenium Manager executable location

        :Raises: WebDriverException if the platform is unsupported
        SE_MANAGER_PATHz2Selenium Manager set by env SE_MANAGER_PATH to: %szmacos/selenium-managerzwindows/selenium-manager.exezlinux/selenium-manager))darwinany)win32r   )cygwinr   )linuxx86_64)freebsdr    )openbsdr    )r   r!   r"   r   )r!   r"   zFSelenium Manager binary may not be compatible with %s; verify settingsz/Unsupported platform/architecture combination: /z2Unable to obtain working Selenium Manager binary; z$Selenium Manager binary found at: %s)osgetenvr   debugr   sysplatformmachinewarninggetr   __file__parentjoinpathis_file)pathallowedarchlocations       r   r   zSeleniumManager._get_binary7   s    II/00D=LLMtT:D $<"@#A%='?'?G *-9X)X8##%^cD||55giliuiuv{{CLL$#78H(+Z[^[g[gZhhijnio)pqq>((11(;D||~$'YZ^Y_%`aa;TBr   c           
         dj                  |       }t        j                  d|       	 t        j                  dk(  r't        j                  | dt
        j                        }nt        j                  | d      }|j                  j                  d      j                  d      }|j                  j                  d      j                  d      }|d	k7  rt        j                  |      ng i d
}t         j#                  |d          |d   }|j$                  r!t        d| d|j$                   d| d|       |S # t        $ r}t        d|       |d}~ww xY w)zExecutes the Selenium Manager Binary.

        :Args:
         - args: the components of the command being executed.
        :Returns: The log string containing the driver location.
         zExecuting process: %sr   T)capture_outputcreationflags)r6   zutf-8
 )logsresultzUnsuccessful command executed: Nr:   r;   z; code: )joinr   r&   r'   r(   
subprocessrunCREATE_NO_WINDOWstdoutdecoderstripstderrr   loads	Exceptionr   r   _process_logs
returncode)r   commandcompleted_procr@   rC   outputerrr;   s           r   r   zSeleniumManager._run^   sG    ((4.,g6		[||w&!+TYcYtYt!u!+T!J#**11':AA$GF#**11':AA$GF+1R<TZZ'bTV=WF 	%%fVn5!$$$1'(>C\C\B]]_`f_ggijpiqr    	[$'Fwi%PQWZZ	[s   CD9 9	EEE	log_itemsc                     | D ]C  }|d   dk(  rt         j                  |d          $|d   dv s,t         j                  |d          E y )NlevelWARNmessage)r   INFO)r   r*   r&   )rL   items     r   rF   zSeleniumManager._process_logs{   sJ     	.DG}&tI/g"33T)_-		.r   N)__name__
__module____qualname____doc__r   dictr   staticmethodr   r   r   r   rF    r   r   r   r      s{    
 $ $ $ $ $L 49   8 .d . .r   r   )r   r   r$   r(   r=   r'   pathlibr   typingr   selenium.commonr   	getLoggerrS   r   r   rY   r   r   <module>r^      s@   "   	   
   .			8	$b. b.r   