a
    &h                     @   sP   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)BinaryIO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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                    s2   t    d| _g | _g | _i | _d | _d| _d S )N F)super__init___binary_location_extension_files_extensions_experimental_options_debugger_address_enable_webextensionsself	__class__ h/var/www/html/swiplay.fr/scambot/venv/lib/python3.9/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 )zAllows you to set where the chromium binary lives.

        Parameters:
        ----------
            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_address7   s    z ChromiumOptions.debugger_addressc                 C   s   t |tstd|| _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.

        Parameters:
        ----------
            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   _decodeM   s    z+ChromiumOptions.extensions.<locals>._decoderbN)r   r   r   openappendr   )r   r$   Zencoded_extensions	extensionfr   r   r   
extensionsI   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.

        Parameters:
        ----------
            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 )zAdds Base64 encoded string with extension data to a list that will
        be used to extract it to the ChromeDriver.

        Parameters:
        ----------
            extension: Base64 encoded string with extension data
        r+   N)r   r'   r2   )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_optionsx   s    z$ChromiumOptions.experimental_options)namer   r   c                 C   s   || j |< dS )zAdds an experimental option which is passed to chromium.

        Parameters:
        ----------
          name: The experimental option name.
          value: The option value.
        Nr5   )r   r7   r   r   r   r   add_experimental_option}   s    z'ChromiumOptions.add_experimental_optionc                 C   s   | j S )z:Returns: Whether webextension support is enabled for Chromium-based browsers.
        True if webextension support is enabled, False otherwise.
        )r   r   r   r   r   enable_webextensions   s    z$ChromiumOptions.enable_webextensionsc                 C   s^   || _ |r2ddg}|D ]}|| jvr| | qn(ddg}|D ]}|| jv r>| j| q>dS )a  Enables or disables webextension support for Chromium-based browsers.

        Parameters:
        ----------
            value : bool
                True to enable webextension support, False to disable.

        Notes:
        -----
        - When enabled, this automatically adds the required Chromium flags:
            - --enable-unsafe-extension-debugging
            - --remote-debugging-pipe
        - When disabled, this removes BOTH flags listed above, even if they were manually added via add_argument()
          before enabling webextensions.
        - Enabling --remote-debugging-pipe makes the connection b/w chromedriver
          and the browser use a pipe instead of a port, disabling many CDP functionalities
          like devtools
        z#--enable-unsafe-extension-debuggingz--remote-debugging-pipeN)r   
_argumentsadd_argumentremove)r   r   Zrequired_flagsflagZflags_to_remover   r   r   r9      s    

c                 C   sd   | j }| j }| jr"|| j | j|d< | jr<| j|d< | j|d< | jrV| j|d< ||| j	< |S )zCreates a capabilities with all the options that have been set

        Returns:
        -------
            dict : a dictionary with all set options
        r*   binaryargsZdebuggerAddress)
Z_capsr6   copyZmobile_optionsupdater*   r   r:   r   KEY)r   Zcapschrome_optionsr   r   r   to_capabilities   s    





zChromiumOptions.to_capabilitiesc                 C   s
   t j S )N)r   CHROMEr@   r   r   r   r   default_capabilities   s    z$ChromiumOptions.default_capabilities)__name__
__module____qualname__rB   r   propertyr   r   setterr   r   listr*   r3   r4   dictr6   r   intr8   boolr9   rD   rF   __classcell__r   r   r   r   r      s0   	"
!r   )r    r,   typingr   r   r   .selenium.webdriver.common.desired_capabilitiesr   Z!selenium.webdriver.common.optionsr   r   r   r   r   r   <module>   s
   