
    Eg8                        d dl Z d dlZd dlZ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 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 ddlmZ ddlmZ  ej        e          ZdZ dZ! G d de          ZdS )    N)contextmanager)BytesIO)rmtree)DesiredCapabilities)DriverFinder)	WebDriver   )FirefoxBinary)FirefoxProfile)Options)FirefoxRemoteConnection)DEFAULT_EXECUTABLE_PATH)Servicezgeckodriver.logc                        e Zd ZdZdZddddededddedf	 d fdZd fdZ	ddZ
ed	             Zdd
Zed             ZddefdZddZdefdZdefdZdefdZdefdZ xZS )r   chromecontentNTreturnc                    |t           k    rt          j        dt          d           |s|
rt          j        dt          d           |rt          j        dt          d           d| _        |rt          j        dt          d           d| _        |t          k    rt          j        dt          d           |t          k    rt          j        d	t          d           |rt          j        d
t          d           |	| _        |s|
r|
}|st          j
                                        }|st                      }t          |          }|                    d          r|d         |_        |r&|j        r|j        | _        |j        r|j        | _        |r2t          |t                     rt#          |          }|| _        ||_        |r2t          |t                     rt%          |          }|| _        ||_        |                    d          r|j        sd|_        | j        st)          |||          | _        t+          j        | j        |          | j        _        | j                                         t3          | j        j        |j                  }t9                                          ||d           d| _        dS )ac  Starts a new local session of Firefox.

        Based on the combination and specificity of the various keyword
        arguments, a capabilities dictionary will be constructed that
        is passed to the remote end.

        The keyword arguments given to this constructor are helpers to
        more easily allow Firefox WebDriver sessions to be customised
        with different options.  They are mapped on to a capabilities
        dictionary that is passed on to the remote end.

        As some of the options, such as `firefox_profile` and
        `options.profile` are mutually exclusive, precedence is
        given from how specific the setting is.  `capabilities` is the
        least specific keyword argument, followed by `options`,
        followed by `firefox_binary` and `firefox_profile`.

        In practice this means that if `firefox_profile` and
        `options.profile` are both set, the selected profile
        instance will always come from the most specific variable.
        In this case that would be `firefox_profile`.  This will result in
        `options.profile` to be ignored because it is considered
        a less specific setting than the top-level `firefox_profile`
        keyword argument.  Similarly, if you had specified a
        `capabilities["moz:firefoxOptions"]["profile"]` Base64 string,
        this would rank below `options.profile`.

        :param firefox_profile: Deprecated: Instance of ``FirefoxProfile`` object
            or a string.  If undefined, a fresh profile will be created
            in a temporary location on the system.
        :param firefox_binary: Deprecated: Instance of ``FirefoxBinary`` or full
            path to the Firefox binary.  If undefined, the system default
            Firefox installation will  be used.
        :param capabilities: Deprecated: Dictionary of desired capabilities.
        :param proxy: Deprecated: The proxy settings to use when communicating with
            Firefox via the extension connection.
        :param executable_path: Deprecated: Full path to override which geckodriver
            binary to use for Firefox 47.0.1 and greater, which
            defaults to picking up the binary from the system path.
        :param options: Instance of ``options.Options``.
        :param service: (Optional) service instance for managing the starting and stopping of the driver.
        :param service_log_path: Deprecated: Where to log information from the driver.
        :param service_args: Deprecated: List of args to pass to the driver service
        :param desired_capabilities: Deprecated: alias of capabilities. In future
            versions of this library, this will replace 'capabilities'.
            This will make the signature consistent with RemoteWebDriver.
        :param keep_alive: Whether to configure remote_connection.RemoteConnection to use
             HTTP keep-alive.
        zDexecutable_path has been deprecated, please pass in a Service object   )
stacklevelz[capabilities and desired_capabilities have been deprecated, please pass in a Service objectzCfirefox_binary has been deprecated, please pass in a Service objectNzEfirefox_profile has been deprecated, please pass in an Options objectz=log_path has been deprecated, please pass in a Service objectzEservice_log_path has been deprecated, please pass in a Service objectzAservice_args has been deprecated, please pass in a Service objectbinaryacceptInsecureCertsF)service_argslog_path)remote_server_addrignore_proxyT)command_executoroptions
keep_alive)r   warningswarnDeprecationWarningr   profileDEFAULT_LOG_PATHDEFAULT_SERVICE_LOG_PATHservicer   FIREFOXcopyr   dictget
isinstancestrr
   r   accept_insecure_certsr   r   get_pathpathstartr   service_url_ignore_local_proxysuper__init__
_is_remote)selffirefox_profilefirefox_binarycapabilitiesproxyexecutable_pathr   service_log_pathr   r&   desired_capabilitiesr   r   executor	__class__s                 Y/var/www/sysmax/venv/lib/python3.11/site-packages/selenium/webdriver/firefox/webdriver.pyr4   zWebDriver.__init__0   s9   B 555MVXjwx     	/ 	Mm"   
  	MUWivw     	MW"   
 '''MOQcpq   
 777MW"   
  	MSUgtu      	0 4 	0/L 	>.6;;==L 	 iiGL))H%% 	4)(3GN  	/~ -%n /&  	,.#.. ?!.~!>!>(DK+GN 	./3// B"0"A"A*DL-GO 566 	2g>[ 	2,1G)| 	j"?XhiiiDL(1$,HH*#|7gFa
 
 
 	(GPTUUU    c                    	 t                                                       n# t          $ r Y nw xY w| j                                         | j        rj	 t          | j        j                   | j        j        rt          | j        j                   n*# t          $ r t          
                    d           Y nw xY w|                                  dS )z3Quits the driver and close every associated window.z(Unable to remove profile specific paths.N)r3   quit	Exceptionr&   stopr#   r   r/   
tempfolderlogger	exception_close_binary_file_handle)r6   r?   s    r@   rC   zWebDriver.quit   s    	GGLLNNNN 	 	 	D	 	< 	MMt|()))<* 44<2333 M M M  !KLLLLLM 	&&(((((s    $ 
11>B $B;:B;c                 
   	 t          | j        t                    r:t          | j        j        d          r"| j        j                                         dS dS dS # t          $ r t                              d           Y dS w xY w)zAttempts to close the underlying file handles for `FirefoxBinary`
        instances if they are used and open.

        To keep inline with other cleanup raising here is swallowed and
        will not cause a runtime error.
        closez=Unable to close open file handle for firefox binary log file.N)	r+   r   r
   hasattr	_log_filerK   rD   rG   rH   r6   s    r@   rI   z#WebDriver._close_binary_file_handle   s    	^$+}55 24;0':: 2K)//111112 22 2 	^ 	^ 	^\]]]]]]	^s   AA $BBc                     | j         S )N)r#   rN   s    r@   r7   zWebDriver.firefox_profile   s
    |rA   c                 6    |                      dd|i           d S )NSET_CONTEXTcontextexecute)r6   rR   s     r@   set_contextzWebDriver.set_context   s!    ]Y$899999rA   c              #      K   |                      d                              d          }|                     |           	 dV  |                     |           dS # |                     |           w xY w)a  Sets the context that Selenium commands are running in using a
        `with` statement. The state of the context on the server is saved
        before entering the block, and restored upon exiting it.

        :param context: Context, may be one of the class properties
            `CONTEXT_CHROME` or `CONTEXT_CONTENT`.

        Usage example::

            with selenium.context(selenium.CONTEXT_CHROME):
                # chrome scope
                ... do stuff ...
        GET_CONTEXTvalueN)rT   poprU   )r6   rR   initial_contexts      r@   rR   zWebDriver.context   s}       ,,}5599'BB!!!	.EEE_-----D_----s   A A3Fc           	      &   t           j                            |          rt                      }t	          |          dz   }t          j        |dt
          j                  5 }t          j        |          D ]I\  }}}|D ]@}	t           j        	                    ||	          }
|
                    |
|
|d                    AJ	 ddd           n# 1 swxY w Y   t          j        |                                                              d          }nat          |d          5 }t          j        |                                                              d          }ddd           n# 1 swxY w Y   ||d}|                     d|          d         S )	a5  Installs Firefox addon.

        Returns identifier of installed addon. This identifier can later
        be used to uninstall addon.

        :param path: Absolute path to the addon that will be installed.

        :Usage:
            ::

                driver.install_addon('/path/to/firebug.xpi')
        r	   wNzUTF-8rb)addon	temporaryINSTALL_ADDONrX   )osr/   isdirr   lenzipfileZipFileZIP_DEFLATEDwalkjoinwritebase64	b64encodegetvaluedecodeopenreadrT   )r6   r/   r_   fp	path_rootzippedbasedirsfilesfylefilenamer^   filepayloads                 r@   install_addonzWebDriver.install_addon  s    7== 	FBD		AIS'*>?? E6)+ E E%D$ % E E#%7<<d#;#;Xx	

/CDDDDEEE E E E E E E E E E E E E E E
 $R[[]]33::7CCEEdD!! FT(55<<WEEF F F F F F F F F F F F F F F "	::||OW55g>>s%    ACCC!:E''E+.E+c                 6    |                      dd|i           dS )zUninstalls Firefox addon using its identifier.

        :Usage:
            ::

                driver.uninstall_addon('addon@foo.com')
        UNINSTALL_ADDONidNrS   )r6   
identifiers     r@   uninstall_addonzWebDriver.uninstall_addon,  s$     	&z(:;;;;;rA   c                 b   |                                                     d          st          j        dt                     |                                 }	 t          |d          5 }|                    |           ddd           n# 1 swxY w Y   n# t          $ r Y ~dS w xY w~n# ~w xY wdS )a  Saves a full document screenshot of the current window to a PNG
        image file. Returns False if there is any IOError, else returns True.
        Use full paths in your filename.

        :Args:
         - filename: The full path you wish to save your screenshot to. This
           should end with a `.png` extension.

        :Usage:
            ::

                driver.get_full_page_screenshot_as_file('/Screenshots/foo.png')
        z.pngz^name used for saved screenshot does not match file type. It should end with a `.png` extensionwbNFT)	lowerendswithr    r!   UserWarningget_full_page_screenshot_as_pngrn   ri   OSError)r6   rw   pngfs       r@    get_full_page_screenshot_as_filez*WebDriver.get_full_page_screenshot_as_file6  s    ~~((00 	Ms   2244	h%%                	 	 		 GGGGtsN   B 'B	=B 	BB BB B) 
B$B) #B$$B) )B,c                 ,    |                      |          S )a  Saves a full document screenshot of the current window to a PNG
        image file. Returns False if there is any IOError, else returns True.
        Use full paths in your filename.

        :Args:
         - filename: The full path you wish to save your screenshot to. This
           should end with a `.png` extension.

        :Usage:
            ::

                driver.save_full_page_screenshot('/Screenshots/foo.png')
        )r   )r6   rw   s     r@   save_full_page_screenshotz#WebDriver.save_full_page_screenshotS  s     44X>>>rA   c                 t    t          j        |                                                     d                    S )zGets the full document screenshot of the current window as a binary
        data.

        :Usage:
            ::

                driver.get_full_page_screenshot_as_png()
        ascii)rj   	b64decode"get_full_page_screenshot_as_base64encoderN   s    r@   r   z)WebDriver.get_full_page_screenshot_as_pngc  s0      G G I I P PQX Y YZZZrA   c                 8    |                      d          d         S )zGets the full document screenshot of the current window as a base64
        encoded string which is useful in embedded images in HTML.

        :Usage:
            ::

                driver.get_full_page_screenshot_as_base64()
        FULL_PAGE_SCREENSHOTrX   rS   rN   s    r@   r   z,WebDriver.get_full_page_screenshot_as_base64n  s     ||233G<<rA   )r   N)F)__name__
__module____qualname__CONTEXT_CHROMECONTEXT_CONTENTr   r%   r$   r4   rC   rI   propertyr7   rU   r   rR   r,   rz   r   boolr   r   bytesr   r   __classcell__)r?   s   @r@   r   r   ,   s       NO /1!![  
[  [  [  [  [  [ z) ) ) ) ) )(^ ^ ^ ^   X
: : : : . . ^.*? ?c ? ? ? ?<< < < <D    :?T ? ? ? ? 	[ 	[ 	[ 	[ 	[	=C 	= 	= 	= 	= 	= 	= 	= 	=rA   r   )"rj   loggingra   r    rd   
contextlibr   ior   shutilr   .selenium.webdriver.common.desired_capabilitiesr   'selenium.webdriver.common.driver_finderr   #selenium.webdriver.remote.webdriverr   RemoteWebDriverr8   r
   r7   r   r   r   remote_connectionr   r&   r   r   	getLoggerr   rG   r$   r%    rA   r@   <module>r      sj  "   				   % % % % % %             N N N N N N @ @ @ @ @ @ L L L L L L ) ) ) ) ) ) + + + + + +       6 6 6 6 6 6 , , , , , ,      		8	$	$  , K= K= K= K= K= K= K= K= K= K=rA   