o
    ҷh
                     @   s   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	 d dl
mZ e eZd ZdZdZG dd	 d	eZG d
d deZdS )    N)utils)DesiredCapabilities)FirefoxBinary)Command)RemoteConnection c                       sH   e Zd Zd fdd	ZdddZdd Zed	d
 Zedd Z  Z	S )ExtensionConnectionN   c                    s   || _ || _|}t|}| jst | _|sd}t }|| j _| j   | j   | jj	| j |d d| d| d}t
 j|dd d S )Nz	127.0.0.1)timeoutzhttp://:z/hubT)
keep_alive)profilebinaryintr   r   	free_portportupdate_preferencesadd_extensionlaunch_browsersuper__init__)selfhostfirefox_profilefirefox_binaryr
   HOSTPORT_URL	__class__ b/var/www/html/venv/lib/python3.10/site-packages/selenium/webdriver/firefox/extension_connection.pyr   "   s   

zExtensionConnection.__init__c                 C   s>   |  tjd|i |  rtd td |  sd S d S )N	sessionIdzwaiting to quit   )executer   QUITis_connectableLOGGERinfotimesleep)r   r"   r    r    r!   quit8   s
   

zExtensionConnection.quitc                 C   s   |  tjdtjiS )z7Connects to the extension and retrieves the session id.desiredCapabilities)r$   r   NEW_SESSIONr   FIREFOX)r   r    r    r!   connect>   s   zExtensionConnection.connectc                 C   s   |  t d dS )z4Connects to an running browser and quit immediately.z/extensions/firefox/quitN)_requestr   clsr    r    r!   connect_and_quitB   s   z$ExtensionConnection.connect_and_quitc                 C   s   t | jj dS )z>Tries to connect to the extension but do not retrieve context.N)r   r&   r   r   r1   r    r    r!   r&   G   s   z"ExtensionConnection.is_connectable)Nr	   )N)
__name__
__module____qualname__r   r+   r/   classmethodr3   r&   __classcell__r    r    r   r!   r   !   s    

r   c                   @   s   e Zd ZdZdS )ExtensionConnectionErrorziAn internal error occurred int the extension.

    Might be caused by bad input or bugs in webdriver
    N)r4   r5   r6   __doc__r    r    r    r!   r9   M   s    r9   )loggingr)   selenium.webdriver.commonr   .selenium.webdriver.common.desired_capabilitiesr   )selenium.webdriver.firefox.firefox_binaryr   !selenium.webdriver.remote.commandr   +selenium.webdriver.remote.remote_connectionr   	getLoggerr4   r'   r   r   r   r   	Exceptionr9   r    r    r    r!   <module>   s   
,