
    Eg                     v    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
  G d de
          ZdS )	    N)BinaryIO)List)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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                     t                                                       d| _        g | _        g | _        i | _        d | _        d S )N )super__init___binary_location_extension_files_extensions_experimental_options_debugger_address)self	__class__s    X/var/www/sysmax/venv/lib/python3.11/site-packages/selenium/webdriver/chromium/options.pyr   zChromiumOptions.__init__    sG     " "%'"!%    c                     | j         S )zQ
        :Returns: The location of the binary, otherwise an empty string
        r   r   s    r   binary_locationzChromiumOptions.binary_location(   s    
 $$r   valuec                     || _         dS )z
        Allows you to set where the chromium binary lives
        :Args:
         - value: path to the Chromium binary
        Nr   r   r   s     r   r   zChromiumOptions.binary_location/   s     !&r   c                     | j         S )zG
        :Returns: The address of the remote devtools instance
        r   r   s    r   debugger_addressz ChromiumOptions.debugger_address8   s    
 %%r   c                     || _         dS )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.
        :Args:
         - value: address of remote devtools instance if any (hostname[:port])
        Nr    r   s     r   r!   z ChromiumOptions.debugger_address?   s     "'r   c                     dt           dt          fd}g }| j        D ]H}t          |d          5 }|                     ||                     ddd           n# 1 swxY w Y   I|| j        z   S )zL
        :Returns: A list of encoded extensions that will be loaded
        	file_datar
   c                 t    t          j        |                                                               d          S )Nzutf-8)base64	b64encodereaddecode)r$   s    r   _decodez+ChromiumOptions.extensions.<locals>._decodeP   s-     #INN$4$455<<WEEEr   rbN)r   strr   openappendr   )r   r*   encoded_extensions	extensionfs        r   
extensionszChromiumOptions.extensionsJ   s    	Fx 	FC 	F 	F 	F 	F  . 	6 	6Ii&& 6!"))''!**5556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 "D$444s   AA	 A	r0   c                 0   |rt           j                            t           j                            |                    }t           j                            |          r| j                            |           dS 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   r0   extension_to_adds      r   add_extensionzChromiumOptions.add_extension]   s      	9!wrw/A/A)/L/LMMw~~.// E%,,-=>>>>>CDDD7888r   c                 \    |r| j                             |           dS 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
        r4   N)r   r.   r;   )r   r0   s     r   add_encoded_extensionz%ChromiumOptions.add_encoded_extensionm   s8      	9##I.....7888r   c                     | j         S )zM
        :Returns: A dictionary of experimental options for chromium
        )r   r   s    r   experimental_optionsz$ChromiumOptions.experimental_optionsy   s    
 ))r   namec                     |                                 dk    r-|dk    s|du r#t          j        t          d          d           || j        |<   dS )zAdds an experimental option which is passed to chromium.

        :Args:
          name: The experimental option name.
          value: The option value.
        w3cfalseFz<Manipulating `w3c` setting can have unintended consequences.   
stacklevelN)lowerwarningswarnUserWarningr   )r   rB   r   s      r   add_experimental_optionz'ChromiumOptions.add_experimental_option   s[     ::<<5  ew&6&6%5..M+&deerstttt+0"4(((r   c                 L    t          j        dt          d           d| j        v S )zL
        :Returns: True if the headless argument is set, else False
        zLheadless property is deprecated, instead check for '--headless' in argumentsrF   rG   
--headless)rJ   rK   DeprecationWarning
_argumentsr   s    r   headlesszChromiumOptions.headless   s5    
 	Z	
 	
 	
 	

 t..r   c                     t          j        dt          d           dh}|du r| j                            |           dS t          t          | j                  |z
            | _        dS )aP  Sets the headless argument Old headless uses a non-production
        browser and is set with `--headless`

        Native headless from v86 - v108 is set with `--headless=chrome`
        Native headless from v109+ is set with `--headless=new`
        :Args:
          value: boolean value indicating to set the headless option
        ziheadless property is deprecated, instead use add_argument('--headless') or add_argument('--headless=new')rF   rG   rO   TN)rJ   rK   rP   rQ   extendlistset)r   r   argss      r   rR   zChromiumOptions.headless   sv     	w	
 	
 	
 	

 ~D==O""4((((("3t#7#7$#>??DOOOr   c                 x   | j         }| j                                        }d|v r4|d         rt          j        dt
          d           nt          d          | j        r|                    | j                   | j	        |d<   | j
        r
| j
        |d<   | j        |d<   | j        r
| j        |d	<   ||| j        <   |S )
z
        Creates a capabilities with all the options that have been set
        :Returns: A dictionary with everything
        rD   z>Setting 'w3c: True' is redundant and will no longer be allowedrF   rG   z}setting w3c to False is not allowed, Please update to W3C Syntax: https://www.selenium.dev/blog/2022/legacy-protocol-support/r2   binaryrW   debuggerAddress)_capsrA   copyrJ   rK   rP   AttributeErrormobile_optionsupdater2   r   rQ   r!   KEY)r   capschrome_optionss      r   to_capabilitieszChromiumOptions.to_capabilities   s    
 z27799N""e$ 	TVhuv     %R  
  	7!!$"5666'+|$ 	<'+';N8$!%v  	F040EN,-'TXr   c                 >    t           j                                        S )N)r   CHROMEr\   r   s    r   default_capabilitiesz$ChromiumOptions.default_capabilities   s    ")..000r   )r
   N)__name__
__module____qualname__r`   r   propertyr,   r   setterr!   r   r2   r=   r?   dictrA   r   intrM   boolrR   rc   rf   __classcell__)r   s   @r   r	   r	      sf       
C& & & & & & % % % % X% &S &T & & & & &# & & & X& 'c 'd ' ' ' ' 5DI 5 5 5 X5$9s 9t 9 9 9 9 
9s 
9t 
9 
9 
9 
9 *d * * * X*	1C 	1c3dSVi>W8X 	1]a 	1 	1 	1 	1 	/$ 	/ 	/ 	/ X	/ _@d @t @ @ @ _@(    > 1d 1 1 1 X1 1 1 1 1r   r	   )r&   r5   rJ   typingr   r   r   .selenium.webdriver.common.desired_capabilitiesr   !selenium.webdriver.common.optionsr   r	    r   r   <module>rt      s   $  				                    N N N N N N 8 8 8 8 8 8p1 p1 p1 p1 p1j p1 p1 p1 p1 p1r   