a
    .c                     @   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)DesiredCapabilities)utils)Command)RemoteConnection)FirefoxBinary 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||f }t
 j|dd d S )Nz	127.0.0.1)timeoutzhttp://%s:%d/hubT)
keep_alive)profilebinaryintr   r   Z	free_portportZupdate_preferencesadd_extensionZlaunch_browsersuper__init__)selfhostZfirefox_profileZfirefox_binaryr
   HOSTPORT_URL	__class__ i/var/www/brookimports/venv/lib/python3.9/site-packages/selenium/webdriver/firefox/extension_connection.pyr   "   s    

zExtensionConnection.__init__c                 C   s4   |  tjd|i |  r0td td qd S )N	sessionIdzwaiting to quit   )executer   Z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.ZdesiredCapabilities)r   r   ZNEW_SESSIONr   ZFIREFOXr   r   r   r   connect>   s    zExtensionConnection.connectc                 C   s   |  dt  dS )z4Connects to an running browser and quit immediately.z%s/extensions/firefox/quitN)_requestr   r%   r   r   r   connect_and_quitC   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   r%   r   r   r   r   H   s    z"ExtensionConnection.is_connectable)Nr	   )N)
__name__
__module____qualname__r   r$   r&   classmethodr(   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)r)   r*   r+   __doc__r   r   r   r   r.   N   s   r.   )loggingr"   Z.selenium.webdriver.common.desired_capabilitiesr   Zselenium.webdriver.commonr   Z!selenium.webdriver.remote.commandr   Z+selenium.webdriver.remote.remote_connectionr   Z)selenium.webdriver.firefox.firefox_binaryr   	getLoggerr)   r    r   r   r   r   	Exceptionr.   r   r   r   r   <module>   s   
-