
    hg4                         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 j        e          Zd ZdZdZ G d d	e	          Z G d
 de          ZdS )    N)DesiredCapabilities)utils)Command)RemoteConnection)FirefoxBinary c                   P    e Zd ZddZd	dZd Zed             Zed             ZdS )
ExtensionConnectionN   c                    || _         || _        |}t          |          }| j        st                      | _        |sd}t	          j                    }|| j         _        | j                                          | j                                          | j        	                    | j         |           d||fz  }t          j        | |d           d S )Nz	127.0.0.1)timeoutzhttp://%s:%d/hubT)
keep_alive)profilebinaryintr   r   	free_portportupdate_preferencesadd_extensionlaunch_browserr   __init__)selfhostfirefox_profilefirefox_binaryr   HOSTPORT_URLs           h/var/www/fb-scrape/myenv/lib/python3.11/site-packages/selenium/webdriver/firefox/extension_connection.pyr   zExtensionConnection.__init__"   s    &$g,,{ 	*'//DK 	D   '')))""$$$""4<"AAA!T4L0!$4	) 	) 	) 	) 	) 	)    c                     |                      t          j        d|i           |                                 rDt                              d           t          j        d           |                                 Bd S d S )N	sessionIdzwaiting to quit   )executer   QUITis_connectableLOGGERinfotimesleep)r   r"   s     r   quitzExtensionConnection.quit9   s{    W\K#;<<<!!## 	KK)***JqMMM !!## 	 	 	 	 	r    c                 Z    |                      t          j        dt          j        i          S )z7Connects to the extension and retrieves the session id.desiredCapabilities)r$   r   NEW_SESSIONr   FIREFOXr   s    r   connectzExtensionConnection.connect?   s,    ||G/24G4OPR R 	Rr    c                 @    |                      dt          z             dS )z4Connects to an running browser and quit immediately.z%s/extensions/firefox/quitN)_requestr   r0   s    r   connect_and_quitz$ExtensionConnection.connect_and_quitD   s"     	2T9:::::r    c                 B    t          j        | j        j                   dS )z>Tries to connect to the extension but do not retrieve context.N)r   r&   r   r   r0   s    r   r&   z"ExtensionConnection.is_connectableI   s      	T\./////r    )Nr   )N)	__name__
__module____qualname__r   r+   r1   classmethodr4   r&    r    r   r
   r
   !   s        ) ) ) ).   R R R
 ; ; [; 0 0 [0 0 0r    r
   c                       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)r6   r7   r8   __doc__r:   r    r   r<   r<   O   s          	Dr    r<   )loggingr)   .selenium.webdriver.common.desired_capabilitiesr   selenium.webdriver.commonr   !selenium.webdriver.remote.commandr   +selenium.webdriver.remote.remote_connectionr   )selenium.webdriver.firefox.firefox_binaryr   	getLoggerr6   r'   r   r   r   r
   	Exceptionr<   r:   r    r   <module>rF      s   $   N N N N N N + + + + + + 5 5 5 5 5 5 H H H H H H C C C C C C		8	$	$	+0 +0 +0 +0 +0* +0 +0 +0\	 	 	 	 	y 	 	 	 	 	r    