o
    Vh                     @   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mZ d dlm	Z	 d dl
mZ d dlmZ eeZG dd dZdS )    N)Path)List)WebDriverException)BaseOptionsc                   @   sN   e Zd ZdZedefddZdedefddZ	ede
e d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.
    returnc                  C   s   t d } durt| S ddddddd}tjdv rt nd}|tj|f}|du r8td	tj d
| tjdv rDt	dtj |dkrJdnd}tt
j||} |  s`t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
        SE_MANAGER_PATHNmacoswindowslinux))darwinany)win32r   )cygwinr   )r   x86_64)freebsdr   )openbsdr   )r   r   r   r   z/Unsupported platform/architecture combination: /)r   r   zFSelenium Manager binary may not be compatible with %s; verify settingszselenium-manager.exezselenium-managerz2Unable to obtain working Selenium Manager binary; z$Selenium Manager binary found at: %s)osgetenvr   sysplatformmachinegetr   loggerwarning__file__parentjoinpathis_filedebug)pathdirsarch	directoryfile r&   g/home/air/yokohama/back/venv/lib/python3.10/site-packages/selenium/webdriver/common/selenium_manager.py
get_binary&   s*   		
zSeleniumManager.get_binaryoptionsc           
      C   s   |j d }t|  d|g}|jr|d |t|j t|dd}|r2|d |t| |j}|rP|js=|jrP|d |jrH|jn|j}|| | 	|}|d }|d	 }	t
d
|	 t|jdrq|rq||_d|_|	S )zDetermines the path of the correct driver.

        :Args:
         - browser: which browser to get the driver path for.
        :Returns: The driver path to use
        browserNamez	--browserz--browser-versionbinary_locationNz--browser-pathz--proxybrowser_pathdriver_pathzUsing driver at: %s)capabilitiesstrr(   browser_versionappendgetattrproxy
http_proxy	ssl_proxyrunr   r    hasattr	__class__r+   )
selfr)   browserargsr+   r3   valueoutputr,   r-   r&   r&   r'   driver_locationO   s,   





zSeleniumManager.driver_locationr;   c           	   
   C   sV  t  tjkr| d | d | d | d | d d| }t d| z3tjdkr;t	j
| d	t	jd
}nt	j
| d	d}|jdd}|jdd}t|}|d }W n tyr } ztd| |d}~ww |d D ]"}|d dkrt |d  |d dks|d dkrt |d  qw|jrt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--debugz--language-bindingpythonz--outputjson zExecuting process: %sr   T)capture_outputcreationflags)rB   zutf-8
resultzUnsuccessful command executed: NlogslevelWARNmessageDEBUGINFOz.
)r   getEffectiveLevelloggingrJ   r1   joinr    r   r   
subprocessr6   CREATE_NO_WINDOWstdoutdecoderstripstderrr@   loads	Exceptionr   r   
returncode)	r;   commandcompleted_procrQ   rT   r=   rE   erritemr&   r&   r'   r6   v   s:   







zSeleniumManager.runN)__name__
__module____qualname____doc__staticmethodr   r(   r   r/   r>   r   dictr6   r&   r&   r&   r'   r       s    ('r   )r@   rM   r   r   rO   r   pathlibr   typingr   selenium.commonr   !selenium.webdriver.common.optionsr   	getLoggerr\   r   r   r&   r&   r&   r'   <module>   s   
