
    >fh                     V    d dl Z d dlZd dlmZmZmZ d dlmZ d dlm	Z	  G d de	      Z
y)    N)BinaryIOOptionalUnion)DesiredCapabilities)
ArgOptionsc            	           e Zd ZdZd fdZedefd       Zej                  deddfd       Zede	e   fd       Z
e
j                  deddfd	       Z
edee   fd
       ZdeddfdZdeddfdZedefd       Zdedeeeeee   f   ddfdZedefd       Zej                  deddfd       ZdefdZedefd       Z xZS )ChromiumOptionszgoog:chromeOptionsreturnNc                 v    t         |           d| _        g | _        g | _        i | _        d | _        d| _        y )N F)super__init___binary_location_extension_files_extensions_experimental_options_debugger_address_enable_webextensions)self	__class__s    V/var/www/zara/venv/lib/python3.12/site-packages/selenium/webdriver/chromium/options.pyr   zChromiumOptions.__init__   s>    %'+-&(RT"04+0"    c                     | j                   S )z@:Returns: The location of the binary, otherwise an empty string.)r   r   s    r   binary_locationzChromiumOptions.binary_location&   s     $$$r   valuec                 \    t        |t              st        | j                        || _        y)zAllows you to set where the chromium binary lives.

        Parameters:
        ----------
            value: path to the Chromium binary
        N)
isinstancestr	TypeErrorBINARY_LOCATION_ERRORr   r   r   s     r   r   zChromiumOptions.binary_location+   s'     %%D6677 %r   c                     | j                   S )z6:Returns: The address of the remote devtools instance.)r   r   s    r   debugger_addressz ChromiumOptions.debugger_address7   s     %%%r   c                 H    t        |t              st        d      || _        y)a  Allows you to set the address of the remote devtools instance that
        the ChromeDriver instance will try to connect to during an active wait.

        Parameters:
        ----------
            value: address of remote devtools instance if any (hostname[:port])
        z!Debugger Address must be a stringN)r   r   r    r   r"   s     r   r$   z ChromiumOptions.debugger_address<   s"     %%?@@!&r   c                     dt         dt        fd}g }| j                  D ].  }t        |d      5 }|j	                   ||             ddd       0 || j
                  z   S # 1 sw Y   IxY w)z;:Returns: A list of encoded extensions that will be loaded.	file_datar
   c                 f    t        j                  | j                               j                  d      S )Nzutf-8)base64	b64encodereaddecode)r'   s    r   _decodez+ChromiumOptions.extensions.<locals>._decodeM   s'     ##INN$45<<WEEr   rbN)r   r   r   openappendr   )r   r-   encoded_extensions	extensionfs        r   
extensionszChromiumOptions.extensionsI   s    	Fx 	FC 	F  .. 	6Ii& 6!"))'!*56 6	6 "D$4$4446 6s   AA(	r2   c                     |rt         j                  j                  t         j                  j                  |            }t         j                  j	                  |      r| j
                  j                  |       yt        d      t        d      )zAdds the path to the extension to a list that will be used to
        extract it to the ChromeDriver.

        Parameters:
        ----------
            extension: path to the \*.crx file
        z#Path to the extension doesn't existargument can not be nullN)	ospathabspath
expanduserexistsr   r0   OSError
ValueError)r   r2   extension_to_adds      r   add_extensionzChromiumOptions.add_extensionZ   sg     !wwrww/A/A)/LMww~~./%%,,-=>CDD788r   c                 T    |r| j                   j                  |       yt        d      )zAdds Base64 encoded string with extension data to a list that will
        be used to extract it to the ChromeDriver.

        Parameters:
        ----------
            extension: Base64 encoded string with extension data
        r6   N)r   r0   r=   )r   r2   s     r   add_encoded_extensionz%ChromiumOptions.add_encoded_extensionk   s'     ##I.788r   c                     | j                   S )z<:Returns: A dictionary of experimental options for chromium.r   r   s    r   experimental_optionsz$ChromiumOptions.experimental_optionsx   s     )))r   namec                 "    || j                   |<   y)zAdds an experimental option which is passed to chromium.

        Parameters:
        ----------
          name: The experimental option name.
          value: The option value.
        NrC   )r   rE   r   s      r   add_experimental_optionz'ChromiumOptions.add_experimental_option}   s     ,1""4(r   c                     | j                   S )z:Returns: Whether webextension support is enabled for Chromium-based browsers.
        True if webextension support is enabled, False otherwise.
        )r   r   s    r   enable_webextensionsz$ChromiumOptions.enable_webextensions   s    
 )))r   c                     || _         |r,ddg}|D ]"  }|| j                  vs| j                  |       $ yddg}|D ],  }|| j                  v s| j                  j                  |       . y)a  Enables or disables webextension support for Chromium-based browsers.

        Parameters:
        ----------
            value : bool
                True to enable webextension support, False to disable.

        Notes:
        -----
        - When enabled, this automatically adds the required Chromium flags:
            - --enable-unsafe-extension-debugging
            - --remote-debugging-pipe
        - When disabled, this removes BOTH flags listed above, even if they were manually added via add_argument()
          before enabling webextensions.
        - Enabling --remote-debugging-pipe makes the connection b/w chromedriver
          and the browser use a pipe instead of a port, disabling many CDP functionalities
          like devtools
        z#--enable-unsafe-extension-debuggingz--remote-debugging-pipeN)r   
_argumentsadd_argumentremove)r   r   required_flagsflagflags_to_removes        r   rI   z$ChromiumOptions.enable_webextensions   s~    ( &+"CE^_N& ,t.%%d+,
  EF_`O' 14??*OO**401r   c                 f   | j                   }| j                  j                         }| j                  r|j	                  | j                         | j
                  |d<   | j                  r| j                  |d<   | j                  |d<   | j                  r| j                  |d<   ||| j                  <   |S )zCreates a capabilities with all the options that have been set

        Returns:
        -------
            dict : a dictionary with all set options
        r4   binaryargsdebuggerAddress)
_capsrD   copymobile_optionsupdater4   r   rK   r$   KEY)r   capschrome_optionss      r   to_capabilitieszChromiumOptions.to_capabilities   s     zz22779!!$"5"56'+|$'+';';N8$!%v  040E0EN,-'TXXr   c                 >    t         j                  j                         S )N)r   CHROMErV   r   s    r   default_capabilitiesz$ChromiumOptions.default_capabilities   s    "))..00r   )r
   N)__name__
__module____qualname__rY   r   propertyr   r   setterr   r$   listr4   r?   rA   dictrD   r   intrG   boolrI   r\   r_   __classcell__)r   s   @r   r	   r	      s   
C1 % % % 	&S 	&T 	& 	& &(3- & & 
'c 
'd 
' 
' 5DI 5 5 9s 9t 9"9s 9t 9 *d * *1C 1c3dSVi>W8X 1]a 1 *d * *   1$ 14 1 !1B , 1d 1 1r   r	   )r)   r7   typingr   r   r   .selenium.webdriver.common.desired_capabilitiesr   !selenium.webdriver.common.optionsr   r	    r   r   <module>rn      s'   $  	 , , N 8n1j n1r   