
    $)f                     f    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	  G d de	      Z
y)	    N)BinaryIO)List)Union)DesiredCapabilities)
ArgOptionsc            	       H    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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defdZedefd       Z xZS )ChromiumOptionszgoog:chromeOptionsreturnNc                 h    t         |           d| _        g | _        g | _        i | _        d | _        y )N )super__init___binary_location_extension_files_extensions_experimental_options_debugger_address)self	__class__s    `/var/www/html/flask-app/venv/lib/python3.12/site-packages/selenium/webdriver/chromium/options.pyr   zChromiumOptions.__init__   s6     " "%'"!%    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)zyAllows you to set where the chromium binary lives.

        :Args:
         - 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)zAllows you to set the address of the remote devtools instance that
        the ChromeDriver instance will try to connect to during an active wait.

        :Args:
         - 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>._decodeL   s'     ##INN$45<<WEEr   rbN)r   r   r   openappendr   )r   r,   encoded_extensions	extensionfs        r   
extensionszChromiumOptions.extensionsH   s    	Fx 	FC 	F  .. 	6Ii& 6!"))'!*56 6	6 "D$4$4446 6s   AA(	r1   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.

        :Args:
         - extension: path to the \*.crx file
        z#Path to the extension doesn't existargument can not be nullN)	ospathabspath
expanduserexistsr   r/   OSError
ValueError)r   r1   extension_to_adds      r   add_extensionzChromiumOptions.add_extensionY   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.

        :Args:
         - extension: Base64 encoded string with extension data
        r5   N)r   r/   r<   )r   r1   s     r   add_encoded_extensionz%ChromiumOptions.add_encoded_extensioni   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_optionsu   s     )))r   namec                 "    || j                   |<   y)zAdds an experimental option which is passed to chromium.

        :Args:
          name: The experimental option name.
          value: The option value.
        NrB   )r   rD   r   s      r   add_experimental_optionz'ChromiumOptions.add_experimental_optionz   s     ,1""4(r   c                 f   | j                   }| j                  j                         }| j                  r|j	                  | j                         | j
                  |d<   | j                  r| j                  |d<   | j                  |d<   | j                  r| j                  |d<   ||| j                  <   |S )znCreates a capabilities with all the options that have been set
        :Returns: A dictionary with everything.r3   binaryargsdebuggerAddress)
_capsrC   copymobile_optionsupdater3   r   
_argumentsr#   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   CHROMErL   r   s    r   default_capabilitiesz$ChromiumOptions.default_capabilities   s    "))..00r   )r
   N)__name__
__module____qualname__rP   r   propertyr   r   setterr#   r   r3   r>   r@   dictrC   r   intrF   rS   rV   __classcell__)r   s   @r   r	   r	      sH   
C& % % % &S &T & & &# & & 	'c 	'd 	' 	' 5DI 5 5 9s 9t 9 
9s 
9t 
9 *d * *1C 1c3dSVi>W8X 1]a 1 $ 1d 1 1r   r	   )r(   r6   typingr   r   r   .selenium.webdriver.common.desired_capabilitiesr   !selenium.webdriver.common.optionsr   r	    r   r   <module>rc      s*   $  	    N 8{1j {1r   