o
    5@Hh[                     @   s`   d dl Z d dlm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)NoSuchDriverException)BaseOptions)SeleniumManager)Servicec                   @   s`   e Zd ZdZdededdfddZ	 defdd	Zdefd
dZ	de
fddZdefddZdS )DriverFinderzA Driver finding class responsible for obtaining the correct driver and
    associated browser.

    :param service: instance of the driver service class.
    :param options: instance of the browser options class.
    serviceoptionsreturnNc                 C   s   || _ || _ddd| _d S )N )driver_pathbrowser_path)_service_options_paths)selfr   r	    r   g/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/selenium/webdriver/common/driver_finder.py__init__$   s   zDriverFinder.__init__c                 C      |   d S )Nr   _binary_pathsr   r   r   r   get_browser_path.      zDriverFinder.get_browser_pathc                 C   r   )Nr   r   r   r   r   r   get_driver_path1   r   zDriverFinder.get_driver_pathc              
   C   s
  | j d r| j S | jjd }z`| jj}|r2td|| t| s)t	d| || j d< W | j S t
 |  }t|d  rJ|d | j d< n	t	d|d  t|d  rf|d | j d< W | j S t	d|d   ty } z
d| }t||d }~ww )	Nr   browserNamezKSkipping Selenium Manager; path to %s driver specified in Service class: %szThe path is not a valid file: z%The driver path is not a valid file: r   z&The browser path is not a valid file: zUnable to obtain driver for )r   r   capabilitiesr   pathloggerdebugr   is_file
ValueErrorr   binary_paths_to_args	Exceptionr   )r   browserr   outputerrmsgr   r   r   r   4   s4   


zDriverFinder._binary_pathsc                 C   s   d| j jd g}| j jr|d |t| j j t| j dd }|r/|d |t| | j j}|rN|js;|jrN|d |jrF|jn|j}|| |S )Nz	--browserr   z--browser-versionbinary_locationz--browser-pathz--proxy)	r   r   browser_versionappendstrgetattrproxy
http_proxy	ssl_proxy)r   argsr*   r/   valuer   r   r   r$   Q   s   



zDriverFinder._to_args)__name__
__module____qualname____doc__r   r   r   r-   r   r   dictr   listr$   r   r   r   r   r      s    r   )loggingpathlibr   selenium.common.exceptionsr   !selenium.webdriver.common.optionsr   *selenium.webdriver.common.selenium_managerr   !selenium.webdriver.common.servicer   	getLoggerr4   r   r   r   r   r   r   <module>   s   
