U
    OfO                     @   sx   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 d dlm	Z	 d dl
mZ G d	d
 d
eZdS )    N)BinaryIO)Dict)List)Optional)Union)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	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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__ G/tmp/pip-unpacked-wheel-ds5t_0qj/selenium/webdriver/chromium/options.pyr   !   s    
zChromiumOptions.__init__c                 C   s   | j S )z@: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   t |tst| j|| _dS )zyAllows you to set where the chromium binary lives.

        :Args:
         - value: path to the Chromium binary
        N)
isinstancestr	TypeErrorZBINARY_LOCATION_ERRORr   r   r   r   r   r   r   .   s    

c                 C   s   | j S )z6:Returns: The address of the remote devtools instance.)r   r   r   r   r   debugger_address9   s    z ChromiumOptions.debugger_addressc                 C   s   t |tstd|| _dS )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   r   r   r   r   >   s    
c              
   C   sN   t tddd}g }| jD ](}t|d}||| W 5 Q R X q|| j S )z;: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   _decodeN   s    z+ChromiumOptions.extensions.<locals>._decoderb)r   r   r   openappendr   )r   r%   Zencoded_extensions	extensionfr   r   r   
extensionsJ   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 )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   r)   Zextension_to_addr   r   r   add_extension[   s    
zChromiumOptions.add_extensionc                 C   s   |r| j | ntddS )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
        r,   N)r   r(   r3   )r   r)   r   r   r   add_encoded_extensionk   s    z%ChromiumOptions.add_encoded_extensionc                 C   s   | j S )z<:Returns: A dictionary of experimental options for chromium.r   r   r   r   r   experimental_optionsw   s    z$ChromiumOptions.experimental_options)namer   r
   c                 C   s   || j |< dS )zAdds an experimental option which is passed to chromium.

        :Args:
          name: The experimental option name.
          value: The option value.
        Nr6   )r   r8   r   r   r   r   add_experimental_option|   s    z'ChromiumOptions.add_experimental_optionc                 C   sd   | j }| j }| jr"|| j | j|d< | jr<| j|d< | j|d< | jrV| j|d< ||| j	< |S )znCreates a capabilities with all the options that have been set
        :Returns: A dictionary with everything.r+   binaryargsZdebuggerAddress)
Z_capsr7   copyZmobile_optionsupdater+   r   Z
_argumentsr   KEY)r   ZcapsZchrome_optionsr   r   r   to_capabilities   s    





zChromiumOptions.to_capabilitiesc                 C   s
   t j S )N)r   ZCHROMEr<   r   r   r   r   default_capabilities   s    z$ChromiumOptions.default_capabilities)__name__
__module____qualname__r>   r   propertyr   r   setterr   r   r   r+   r4   r5   dictr7   r   intr9   r?   r@   __classcell__r   r   r   r   r	      s(   
"	r	   )r!   r-   typingr   r   r   r   r   Z.selenium.webdriver.common.desired_capabilitiesr   Z!selenium.webdriver.common.optionsr   r	   r   r   r   r   <module>   s   