
    ]j                        d dl mZ d dlmZmZ d dlmZ d dlmZ e G d d             Z	e G d d             Z
e G d	 d
             Ze G d d             Ze G d d             Ze G d d             Z G d d      Zy)    )annotations)	dataclassfield)Any)command_builderc                       e Zd ZU dZdZded<   y)InstallParameterszInstallParameters.N
Any | Noneextension_data)__name__
__module____qualname____doc__r   __annotations__     _/home/ubuntu/.local/lib/python3.12/site-packages/selenium/webdriver/common/bidi/webextension.pyr	   r	      s    !%NJ%r   r	   c                  >    e Zd ZU dZ edd      Zded<   dZded<   y)	ExtensionPathzExtensionPath.pathFdefaultinitstrtypeN
str | Noner   r   r   r   r   r   r   r   r   r   r   r   r      s     f51D#1D*r   r   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
ExtensionArchivePathzExtensionArchivePath.archivePathFr   r   r   Nr   r   r   r   r   r   r   r      s     m%8D#8D*r   r   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
ExtensionBase64EncodedzExtensionBase64Encoded.base64Fr   r   r   Nr   value)r   r   r   r   r   r   r   r$   r   r   r   r"   r"   %   s     !hU3D#3E:r   r"   c                       e Zd ZU dZdZded<   y)InstallResultzInstallResult.Nr
   	extensionr   r   r   r   r'   r   r   r   r   r&   r&   -   s     Iz r   r&   c                       e Zd ZU dZdZded<   y)UninstallParameterszUninstallParameters.Nr
   r'   r(   r   r   r   r*   r*   4   s     Iz r   r*   c                  :    e Zd ZdZddZ	 	 	 d	 	 	 	 	 ddZd	dZy)
WebExtensionz#WebDriver BiDi webExtension module.c                    || _         y )N)_conn)selfconns     r   __init__zWebExtension.__init__>   s	    
r   Nc                v   |||dj                         D cg c]	  \  }}|| }}}t        |      dk7  rt        d|       |d|d}n|d|d}n	|J d|d	}d
|i}t        d|      }		 | j                  j                  |	      S c c}}w # t        $ r}
dt        |
      v rt        d      |
 d}
~
ww xY w)a  Install a web extension.

        Exactly one of the three keyword arguments must be provided.

        Args:
            path: Directory path to an unpacked extension (also accepted for
                signed ``.xpi`` / ``.crx`` archive files on Firefox).
            archive_path: File-system path to a packed extension archive.
            base64_value: Base64-encoded extension archive string.

        Returns:
            The raw result dict from the BiDi ``webExtension.install`` command
            (contains at least an ``"extension"`` key with the extension ID).

        Raises:
            ValueError: If more than one, or none, of the arguments is provided.
        )r   archive_pathbase64_valueN   zJExactly one of path, archive_path, or base64_value must be provided; got: r   )r   r   r    r#   )r   r$   extensionDatazwebExtension.installzMethod not availablezwebExtension.install failed with 'Method not available'. This likely means that web extension support is disabled. Enable unsafe extension debugging and/or set options.enable_webextensions in your WebDriver configuration.)	itemslen
ValueErrorr   r.   execute	Exceptionr   RuntimeError)r/   r   r3   r4   kvprovidedr   paramscmdes              r   installzWebExtension.installA   s	   2 lLeg
!Q 
 

 x=A\]e\fg  &,d;N%&3\JN+++&.FN!>24f=
	::%%c**'
(  	%Q/"7
  	s   B
/B 	B8B33B8c                    t        |t              r|j                  d      }n|}|t        d      d|i}t	        d|      }| j
                  j                  |      S )a[  Uninstall a web extension.

        Args:
            extension: Either the extension ID string returned by ``install``,
                or the full result dict returned by ``install`` (the
                ``"extension"`` value is extracted automatically).

        Raises:
            ValueError: If extension is not provided or is None.
        r'   zextension parameter is requiredzwebExtension.uninstall)
isinstancedictgetr9   r   r.   r:   )r/   r'   extension_idr@   rA   s        r   	uninstallzWebExtension.uninstallu   s_     i& )k :L$L>??|,6?zz!!#&&r   )returnNone)NNN)r   r   r3   r   r4   r   )r'   z
str | dict)r   r   r   r   r1   rC   rI   r   r   r   r,   r,   ;   s<    -
  #'#'	33 !3 !	3h'r   r,   N)
__future__r   dataclassesr   r   typingr   %selenium.webdriver.common.bidi.commonr   r	   r   r   r"   r&   r*   r,   r   r   r   <module>rP      s    # (  A
& & &          ! ! ! ! ! !O' O'r   