a
    5ñ»jO  ã                   @   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__© úIE:\soccer\ml_env\Lib\site-packages\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 )zú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])
        z!Debugger Address must be a stringN)r   r   r   r   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 )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ÚrbN)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 )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_extension[   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(   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 )z¢Adds 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   