
    ,i"                         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  G d
 de      Zy)    N)contextmanager)BytesIO)Optional)DriverFinder)Options)FirefoxRemoteConnection)Service)	WebDriverc            	            e Zd ZdZdZdZ	 	 	 ddee   dee   de	ddf fd	Z
d f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d Zd Zd Z xZS )r
   z=Controls the GeckoDriver and allows you to drive the browser.chromecontentNoptionsservice
keep_alivereturnc                 <   |r|n	t               | _        |r|n	t               }t        | j                  |      }|j	                         r|j	                         |_        d|_        | j                  j                         xs |j                         | j                  _	        | j                  j                          t        | j                  j                  ||j                        }	 t        | =  ||       d| _        y# t         $ r | j#                           w xY w)a  Creates a new instance of the Firefox driver. Starts the service and
        then creates new instance of Firefox driver.

        Args:
            options: Instance of ``options.Options``.
            service: (Optional) service instance for managing the starting and stopping of the driver.
            keep_alive: Whether to configure remote_connection.RemoteConnection to use HTTP keep-alive.
        N)remote_server_addrr   ignore_proxy)command_executorr   F)r	   r   r   r   get_browser_pathbinary_locationbrowser_versionenv_pathget_driver_pathpathstartr   service_url_ignore_local_proxysuper__init__	Exceptionquit
_is_remote)selfr   r   r   finderexecutor	__class__s         s/var/www/system.tvplus.app.br/jogos/scrap/venv/lib/python3.12/site-packages/selenium/webdriver/firefox/webdriver.pyr    zWebDriver.__init__&   s     #*wwy$'')dllG4""$&,&=&=&?G#&*G# LL113Ov7M7M7O*#||77! 44
	GhH
  	  	IIK	s   'D   Dc                     	 t         |           | j                  j	                          y# t        $ r Y &w xY w# | j                  j	                          w xY w)z=Closes the browser and shuts down the GeckoDriver executable.N)r   r"   r!   r   stop)r$   r'   s    r(   r"   zWebDriver.quitN   sJ    	 GLN
 LL	  		 LLs   , 	8; 8; Ac                 ,    | j                  dd|i       y)zSets the context that Selenium commands are running in.

        Args:
            context: Context to set, should be one of CONTEXT_CHROME or CONTEXT_CONTENT.
        SET_CONTEXTcontextNexecute)r$   r-   s     r(   set_contextzWebDriver.set_contextX   s     	]Y$89    c              #      K   | j                  d      j                  d      }| j                  |       	 d | j                  |       y# | j                  |       w xY w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.

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

        Example:
            with selenium.context(selenium.CONTEXT_CHROME):
                # chrome scope
                ... do stuff ...
        GET_CONTEXTvalueN)r/   popr0   )r$   r-   initial_contexts      r(   r-   zWebDriver.context`   sS      ,,}599'B!	._-D_-s   2A!A A!AA!c           	         t         j                  j                  |      rt               }t         j                  j	                  |      }t        |      dz   }t        j                  |dt        j                  d      5 }t        j                  |      D ]B  \  }}}|D ]7  }	t         j                  j                  ||	      }
|j                  |
|
|d        9 D 	 ddd       t        j                  |j                               j                  d      }nGt!        |d      5 }t        j                  |j#                               j                  d      }ddd       |d}| j%                  d	|      d
   S # 1 sw Y   xY w# 1 sw Y   /xY w)a  Installs Firefox addon.

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

        Args:
            path: Absolute path to the addon that will be installed.
            temporary: Allows you to load browser extensions temporarily during a session.

        Returns:
            Identifier of installed addon.

        Example:
            driver.install_addon("/path/to/firebug.xpi")
           wF)strict_timestampsNzUTF-8rb)addon	temporaryINSTALL_ADDONr4   )osr   isdirr   normpathlenzipfileZipFileZIP_DEFLATEDwalkjoinwritebase64	b64encodegetvaluedecodeopenreadr/   )r$   r   r=   fp	path_rootzippedbase_filesfylefilenamer<   filepayloads                 r(   install_addonzWebDriver.install_addonv   sU   " 77==B77##D)DD	AIS'*>*>RWX E\b&(ggdm END!U % E#%77<<d#;Xx	
/CDEEE
 $$R[[]3::7CEdD! FT((5<<WEF "	:||OW5g>>E EF Fs   >AE6!3F6E?Fc                 ,    | j                  dd|i       y)zUninstalls Firefox addon using its identifier.

        Args:
            identifier: The addon identifier to uninstall.

        Example:
            driver.uninstall_addon("addon@foo.com")
        UNINSTALL_ADDONidNr.   )r$   
identifiers     r(   uninstall_addonzWebDriver.uninstall_addon   s     	&z(:;r1   c                 *   |j                         j                  d      st        j                  dt               | j                         }	 t        |d      5 }|j                  |       ddd       ~y# 1 sw Y   xY w# t        $ r Y ~yw xY w# ~w xY w)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.

        Example:
            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endswithwarningswarnUserWarningget_full_page_screenshot_as_pngrM   rH   OSError)r$   rV   pngfs       r(    get_full_page_screenshot_as_filez*WebDriver.get_full_page_screenshot_as_file   s     ~~((0MMp 224	h% 
   		 s<   A? A3)A? 3A<8A? ?	BB BB Bc                 $    | j                  |      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.

        Example:
            driver.save_full_page_screenshot("/Screenshots/foo.png")
        )rj   )r$   rV   s     r(   save_full_page_screenshotz#WebDriver.save_full_page_screenshot   s     44X>>r1   c                 f    t        j                  | j                         j                  d            S )zGets the full document screenshot of the current window as a binary
        data.

        Returns:
            Binary data of the screenshot.

        Example:
            driver.get_full_page_screenshot_as_png()
        ascii)rI   	b64decode"get_full_page_screenshot_as_base64encoder$   s    r(   rf   z)WebDriver.get_full_page_screenshot_as_png   s*      G G I P PQX YZZr1   c                 *    | j                  d      d   S )a   Gets the full document screenshot of the current window as a base64
        encoded string which is useful in embedded images in HTML.

        Returns:
            Base64 encoded string of the screenshot.

        Example:
            driver.get_full_page_screenshot_as_base64()
        FULL_PAGE_SCREENSHOTr4   r.   rr   s    r(   rp   z,WebDriver.get_full_page_screenshot_as_base64   s     ||23G<<r1   c                     t         )zBDownload file functionality is not implemented for Firefox driver.NotImplementedErrorr$   argskwargss      r(   download_filezWebDriver.download_file       !!r1   c                     t         )zKGet downloadable files functionality is not implemented for Firefox driver.rv   rx   s      r(   get_downloadable_filesz WebDriver.get_downloadable_files   r|   r1   c                     t         )zNDelete downloadable files functionality is not implemented for Firefox driver.rv   rx   s      r(   delete_downloadable_filesz#WebDriver.delete_downloadable_files   r|   r1   )NNT)r   N)F)__name__
__module____qualname____doc__CONTEXT_CHROMECONTEXT_CONTENTr   r   r	   boolr    r"   r0   r   r-   strrY   r^   rj   rl   bytesrf   rp   r{   r~   r   __classcell__)r'   s   @r(   r
   r
       s    GNO &*%)	& '"&  '"&  	& 
 
& P : . .*"?c "?H	<D 6?T ?
[ 
[
=C 
="""r1   r
   )rI   r?   rc   rC   
contextlibr   ior   typingr   'selenium.webdriver.common.driver_finderr   "selenium.webdriver.firefox.optionsr   ,selenium.webdriver.firefox.remote_connectionr   "selenium.webdriver.firefox.servicer	   #selenium.webdriver.remote.webdriverr
   RemoteWebDriver r1   r(   <module>r      s9   "  	   %   @ 6 P 6 LP" P"r1   