o
    US`cq                     @   sX   d dl Z 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 de
ZdS )    N)ListUnionBinaryIO)DesiredCapabilities)
ArgOptionsc                	       s2  e Zd ZdZd  fddZedefddZejdeddfd	dZedefd
dZ	e	jdeddfddZ	ede
e fddZdeddfddZdeddfddZedefddZdedeeeee
e f ddfddZedefddZejdeddfddZdefddZedefddZ  ZS )!ChromiumOptionszgoog:chromeOptionsreturnNc                    s,   t    d| _g | _g | _i | _d | _d S )N )super__init___binary_location_extension_files_extensions_experimental_options_debugger_addressself	__class__ N/usr/local/lib/python3.10/dist-packages/selenium/webdriver/chromium/options.pyr      s   

zChromiumOptions.__init__c                 C      | j S )zQ
        :Returns: The location of the binary, otherwise an empty string
        r   r   r   r   r   binary_location&      zChromiumOptions.binary_locationvaluec                 C   
   || _ dS )z
        Allows you to set where the chromium binary lives
        :Args:
         - value: path to the Chromium binary
        Nr   r   r   r   r   r   r   -   s   
c                 C   r   )zG
        :Returns: The address of the remote devtools instance
        r   r   r   r   r   debugger_address6   r   z ChromiumOptions.debugger_addressc                 C   r   )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   r   r   r   r   =   s   
	c              	   C   sd   dt dtfdd}g }| jD ]}t|d}||| W d   n1 s'w   Y  q|| j S )zL
        :Returns: A list of encoded extensions that will be loaded
        	file_datar   c                 S   s   t |  dS )Nzutf-8)base64	b64encodereaddecode)r    r   r   r   _decodeM   s   z+ChromiumOptions.extensions.<locals>._decoderbN)r   strr   openappendr   )r   r%   Zencoded_extensions	extensionfr   r   r   
extensionsH   s   

zChromiumOptions.extensionsr*   c                 C   sD   |rt jt j|}t j|r| j| dS tdtd)z
        Adds 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   r*   Zextension_to_addr   r   r   add_extensionZ   s   zChromiumOptions.add_extensionc                 C   s   |r
| j | dS td)z
        Adds 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
        r-   N)r   r)   r4   )r   r*   r   r   r   add_encoded_extensionk   s   z%ChromiumOptions.add_encoded_extensionc                 C   r   )zM
        :Returns: A dictionary of experimental options for chromium
        )r   r   r   r   r   experimental_optionsx   r   z$ChromiumOptions.experimental_optionsnamec                 C   s8   |  dkr|dks|du rttd || j|< dS )z
        Adds 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.N)lowerwarningswarnUserWarningr   )r   r8   r   r   r   r   add_experimental_option   s   z'ChromiumOptions.add_experimental_optionc                 C   s
   d| j v S )zL
        :Returns: True if the headless argument is set, else False
        
--headless)
_argumentsr   r   r   r   headless   s   
zChromiumOptions.headlessc                 C   s6   dh}|du r| j | dS tt| j | | _ dS )z
        Sets the headless argument
        :Args:
          value: boolean value indicating to set the headless option
        r@   TN)rA   extendlistset)r   r   argsr   r   r   rB      s   c                 C   s   | j }| j }d|v r|d rtjdtdd ntd| jr&|| j | j	|d< | j
r3| 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
        r9   z>Setting 'w3c: True' is redundant and will no longer be allowed   )
stacklevelz}setting w3c to False is not allowed, Please update to W3C Syntax: https://www.selenium.dev/blog/2022/legacy-protocol-support/r,   binaryrF   ZdebuggerAddress)Z_capsr7   copyr<   r=   DeprecationWarningAttributeErrorZmobile_optionsupdater,   r   rA   r   KEY)r   ZcapsZchrome_optionsr   r   r   to_capabilities   s(   





zChromiumOptions.to_capabilitiesc                 C   s
   t j S )N)r   ZCHROMErJ   r   r   r   r   default_capabilities   s   
z$ChromiumOptions.default_capabilities)r   N)__name__
__module____qualname__rN   r   propertyr'   r   setterr   r   r,   r5   r6   dictr7   r   intr?   boolrB   rO   rP   __classcell__r   r   r   r   r      s2    
&r   )r!   r.   r<   typingr   r   r   Z.selenium.webdriver.common.desired_capabilitiesr   Z!selenium.webdriver.common.optionsr   r   r   r   r   r   <module>   s   