a
    xd
                     @   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   Z	free_portportZupdate_preferencesadd_extensionZlaunch_browsersuper__init__)selfhostZfirefox_profileZfirefox_binaryr
   HOSTPORT_URL	__class__ g/var/www/html/Ranjet/env/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   |  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   r(   r   r   r   r    G   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   r0   M   s   r0   )loggingr#   Zselenium.webdriver.commonr   Z.selenium.webdriver.common.desired_capabilitiesr   Z)selenium.webdriver.firefox.firefox_binaryr   Z!selenium.webdriver.remote.commandr   Z+selenium.webdriver.remote.remote_connectionr   	getLoggerr+   r!   r   r   r   r   	Exceptionr0   r   r   r   r   <module>   s   
,