o
    5@Hh                     @   s|   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Zd dlmZ d dl	m
Z
mZ d dlmZ eeZG dd dZdS )    N)Path)ListOptional)WebDriverExceptionc                   @   sd   e Zd ZdZdedefddZedefddZ	edee
 defdd	Zed
ee fddZdS )SeleniumManagerzWrapper for getting information from the Selenium Manager binaries.

    This implementation is still in beta, and may change.
    argsreturnc                 C   s\   t |  g| }t tjkr|d |d |d |d |d | |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    r   j/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/selenium/webdriver/common/selenium_manager.pybinary_paths&   s   





zSeleniumManager.binary_pathsc                  C   s  t tjd} td}|dur| |} d}td }dur,t	
d| t |}nF|  r3| }n?ddddddd	}tjd
v rEt nd}tjdv rSt	dtj |tj|f}|du rjtdtj d| t tj|}|du sz| std| t	
d| |S )zDetermines the path of the correct Selenium Manager binary.

        :Returns: The Selenium Manager executable location

        :Raises: WebDriverException if the platform is unsupported
        zselenium-managerEXEN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)r   __file__parentjoinpath	sysconfigget_config_varwith_suffixosgetenvr   debugexistssysplatformmachinewarninggetr   is_file)compiled_pathexepathenv_pathallowedarchlocationr   r   r   r   8   s8   	


	
zSeleniumManager._get_binaryc              
   C   s   d | }td| z8tjdkrtj| dtjd}ntj| dd}|j	d
d}|j	d
d}|d	kr=t|ng i d
}W n tyW } ztd| |d}~ww t|d  |d }|jrwtd| d|j d| d| |S )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)r:   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_procrD   rG   outputerrr?   r   r   r   r   h   s(   

 zSeleniumManager._run	log_itemsc                 C   sD   | D ]}|d dkrt |d  q|d dv rt |d  qd S )NlevelWARNmessage)r   INFO)r   r/   r*   )rP   itemr   r   r   rJ      s   zSeleniumManager._process_logsN)__name__
__module____qualname____doc__r   dictr   staticmethodr   r   r   r   rJ   r   r   r   r   r       s    /r   )r
   r   r(   r-   rA   r,   r%   pathlibr   typingr   r   selenium.commonr   	getLoggerrV   r   r   r   r   r   r   <module>   s   
