a
    .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                       s(  e Zd ZdZdd fddZeedddZejeddd	dZeedd
dZ	e	jeddddZ	ee
e dddZeddddZeddddZeedddZeeeeee
e f ddddZeedddZejeddddZedddZeedddZ  ZS ) ChromiumOptionszgoog:chromeOptionsN)returnc                    s,   t    d| _g | _g | _i | _d | _d S )N )super__init___binary_location_extension_files_extensions_experimental_options_debugger_addressself	__class__ ]/var/www/brookimports/venv/lib/python3.9/site-packages/selenium/webdriver/chromium/options.pyr      s    
zChromiumOptions.__init__c                 C   s   | j S )zQ
        :Returns: The location of the binary, otherwise an empty string
        r   r   r   r   r   binary_location&   s    zChromiumOptions.binary_location)valuer   c                 C   s
   || _ 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   s   | j S )zG
        :Returns: The address of the remote devtools instance
        r   r   r   r   r   debugger_address6   s    z ChromiumOptions.debugger_addressc                 C   s
   || _ 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   r   r   r   r   =   s    	c              	   C   sb   t tddd}g }| jD ]<}t|d}||| W d   q1 sL0    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.extensions)r'   r   c                 C   sH   |r<t jt j|}t j|r2| j| qDtdntddS )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 | ntddS )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&   r1   )r   r'   r   r   r   add_encoded_extensionk   s    z%ChromiumOptions.add_encoded_extensionc                 C   s   | j S )zM
        :Returns: A dictionary of experimental options for chromium
        )r   r   r   r   r   experimental_optionsx   s    z$ChromiumOptions.experimental_options)namer   r   c                 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   r5   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   s4   dh}|du r| j | ntt| j | | _ dS )z
        Sets the headless argument
        :Args:
          value: boolean value indicating to set the headless option
        r=   TN)r>   extendlistset)r   r   argsr   r   r   r?      s    c                 C   s   | j }| j }d|v r:|d r2tjdtdd ntd| jrL|| j | j	|d< | j
rf| 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
        r6   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)   binaryrC   ZdebuggerAddress)Z_capsr4   copyr9   r:   DeprecationWarningAttributeErrorZmobile_optionsupdater)   r   r>   r   KEY)r   ZcapsZchrome_optionsr   r   r   to_capabilities   s(    





zChromiumOptions.to_capabilitiesc                 C   s
   t j S )N)r   ZCHROMErG   r   r   r   r   default_capabilities   s    z$ChromiumOptions.default_capabilities)__name__
__module____qualname__rK   r   propertyr$   r   setterr   r   r)   r2   r3   dictr4   r   intr<   boolr?   rL   rM   __classcell__r   r   r   r   r      s0   
"r   )r   r+   r9   typingr   r   r   Z.selenium.webdriver.common.desired_capabilitiesr   Z!selenium.webdriver.common.optionsr   r   r   r   r   r   <module>   s   