o
    M,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                	       s6  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	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                    s2   t    d| _g | _g | _i | _d| _d| _dS )z1Initialize ChromiumOptions with default settings. NF)super__init___binary_location_extension_files_extensions_experimental_options_debugger_address_enable_webextensionsself	__class__ o/var/www/www-root/data/www/bot.pdev.uz/venv/lib/python3.10/site-packages/selenium/webdriver/chromium/options.pyr      s   

zChromiumOptions.__init__c                 C      | j S )z]
        Returns:
            The location of the binary, otherwise an empty string.
        )r   r   r   r   r   binary_location'      zChromiumOptions.binary_locationvaluec                 C   s   t |ts
t| j|| _dS )zzAllows you to set where the chromium binary lives.

        Args:
            value: Path to the Chromium binary.
        N)
isinstancestr	TypeErrorBINARY_LOCATION_ERRORr   r   r   r   r   r   r   /   s   


c                 C   r   )zS
        Returns:
            The address of the remote devtools instance.
        )r   r   r   r   r   debugger_address:   r   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!   B   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 )zX
        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   _decodeU   s   z+ChromiumOptions.extensions.<locals>._decoderbN)r   r   r   openappendr   )r   r'   encoded_extensions	extensionfr   r   r   
extensionsN   s   

zChromiumOptions.extensionsr,   c                 C   sD   |rt jt j|}t j|r| j| dS tdtd)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,   extension_to_addr   r   r   add_extensionb   s   zChromiumOptions.add_extensionc                 C   s   |r
| j | dS td)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*   r6   )r   r,   r   r   r   add_encoded_extensionr   s   z%ChromiumOptions.add_encoded_extensionc                 C   r   )zY
        Returns:
            A dictionary of experimental options for chromium.
        r   r   r   r   r   experimental_options~   r   z$ChromiumOptions.experimental_optionsnamec                 C   s   || j |< dS )zAdds an experimental option which is passed to chromium.

        Args:
            name: The experimental option name.
            value: The option value.
        Nr:   )r   r<   r   r   r   r   add_experimental_option   s   z'ChromiumOptions.add_experimental_optionc                 C   r   )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`   || _ |rddg}|D ]}|| jvr| | qdS ddg}|D ]}|| jv r-| j| q dS )a  Enables or disables webextension support for Chromium-based browsers.

        Args:
            value: 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   required_flagsflagflags_to_remover   r   r   r>      s   


c                 C   sd   | j }| j }| jr|| j | j|d< | jr| j|d< | j|d< | jr+| j|d< ||| j	< |S )zCreates a capabilities with all the options that have been set.

        Returns:
            A dictionary with all set options.
        r.   binaryargsdebuggerAddress)
_capsr;   copymobile_optionsupdater.   r   r?   r!   KEY)r   capschrome_optionsr   r   r   to_capabilities   s   





zChromiumOptions.to_capabilitiesc                 C   s
   t j S )N)r   CHROMErI   r   r   r   r   default_capabilities   s   
z$ChromiumOptions.default_capabilities)r   N)__name__
__module____qualname__rL   r   propertyr   r   setterr   r!   listr.   r8   r9   dictr;   r   intr=   boolr>   rO   rQ   __classcell__r   r   r   r   r      s2    

&	r   )r#   r0   typingr   r   r   .selenium.webdriver.common.desired_capabilitiesr   !selenium.webdriver.common.optionsr   r   r   r   r   r   <module>   s   