
    ]j+                       d dl mZ d dlmZmZ d dlmZ d dlmZ 	 	 	 	 	 	 d"dZ		 d#	 	 	 	 	 	 	 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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e G d d             Z G d  d!      Zy)%    )annotations)	dataclassfield)Any)command_builderc                D    | du rd|t        |      dS ddS | du rddiS y)aa  Transform download parameters into download_behavior object.

    Args:
        allowed: Whether downloads are allowed
        destination_folder: Destination folder for downloads (accepts str or
            pathlib.Path; will be coerced to str)

    Returns:
        Dictionary representing the download_behavior object, or None if allowed is None
    TallowedN)typedestinationFolderFr
   denied)str)r	   destination_folders     Z/home/ubuntu/.local/lib/python3.12/site-packages/selenium/webdriver/common/bidi/browser.pytransform_download_paramsr      sR     $ =O<Z%7!8	
 	
 ae	
 	
 
E	!!    Nc                J    | du r|st        d      | du r|rt        d      yy)a  Validate download behavior parameters.

    Args:
        allowed: Whether downloads are allowed
        destination_folder: Destination folder for downloads
        user_contexts: Optional list of user contexts

    Raises:
        ValueError: If parameters are invalid
    Tz0destination_folder is required when allowed=TrueFz<destination_folder should not be provided when allowed=FalseN)
ValueErrorr	   r   user_contextss      r   validate_download_behaviorr   )   s9     $1KLL%.WXX /r   c                      e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded	<   dZ
ded
<   dZded<   d Zd Zd Zd Zd Zd Zd Zy)ClientWindowInfozClientWindowInfo.Nbool | Noneactive
Any | Noneclient_windowheightstatewidthxyc                    | j                   S )zGet the client window ID.)r   selfs    r   get_client_windowz"ClientWindowInfo.get_client_windowJ   s    !!!r   c                    | j                   S )zGet the client window state.)r   r#   s    r   	get_statezClientWindowInfo.get_stateN       zzr   c                    | j                   S )zGet the client window width.)r   r#   s    r   	get_widthzClientWindowInfo.get_widthR   r(   r   c                    | j                   S )zGet the client window height.)r   r#   s    r   
get_heightzClientWindowInfo.get_heightV       {{r   c                    | j                   S )z%Check if the client window is active.)r   r#   s    r   	is_activezClientWindowInfo.is_activeZ   r-   r   c                    | j                   S )z!Get the client window X position.)r    r#   s    r   get_xzClientWindowInfo.get_x^       vvr   c                    | j                   S )z!Get the client window Y position.)r!   r#   s    r   get_yzClientWindowInfo.get_yb   r2   r   )__name__
__module____qualname____doc__r   __annotations__r   r   r   r   r    r!   r%   r'   r*   r,   r/   r1   r4    r   r   r   r   >   sn    FK $M:$FJE:E:AzAz"r   r   c                       e Zd ZU dZdZded<   y)UserContextInfozUserContextInfo.Nr   user_contextr5   r6   r7   r8   r=   r9   r:   r   r   r<   r<   h   s    #L*#r   r<   c                  <    e Zd ZU dZdZded<   dZded<   dZded<   y)CreateUserContextParameterszCreateUserContextParameters.Nr   accept_insecure_certsr   proxyunhandled_prompt_behavior)r5   r6   r7   r8   rA   r9   rB   rC   r:   r   r   r@   r@   o   s%    &)-;-E:,0z0r   r@   c                  .    e Zd ZU dZ ee      Zded<   y)GetClientWindowsResultzGetClientWindowsResult.default_factory	list[Any]client_windowsN)r5   r6   r7   r8   r   listrI   r9   r:   r   r   rE   rE   x   s    ! %d ;NI;r   rE   c                  .    e Zd ZU dZ ee      Zded<   y)GetUserContextsResultzGetUserContextsResult.rF   rH   r   N)r5   r6   r7   r8   r   rJ   r   r9   r:   r   r   rL   rL      s     $T:M9:r   rL   c                       e Zd ZU dZdZded<   y)RemoveUserContextParameterszRemoveUserContextParameters.Nr   r=   r>   r:   r   r   rN   rN      s    &#L*#r   rN   c                  h    e Zd ZU dZ edd      Zded<   dZded	<   dZded
<   dZ	ded<   dZ
ded<   y)ClientWindowRectStatezClientWindowRectState.normalFdefaultinitr   r   Nr   r   r   r    r!   )r5   r6   r7   r8   r   r   r9   r   r   r    r!   r:   r   r   rP   rP      s>     xe4E34E:FJAzAzr   rP   c                  <    e Zd ZU dZdZded<    ee      Zded<   y)SetDownloadBehaviorParameterszSetDownloadBehaviorParameters.Nr   download_behaviorrF   rH   r   )	r5   r6   r7   r8   rW   r9   r   rJ   r   r:   r   r   rV   rV      s    ($(z($T:M9:r   rV   c                  >    e Zd ZU dZ edd      Zded<   dZded	<   y)
DownloadBehaviorAllowedzDownloadBehaviorAllowed.r	   FrR   r   r
   N
str | Noner   )r5   r6   r7   r8   r   r
   r9   r   r:   r   r   rY   rY      s!    "ie4D#4%)
)r   rY   c                  0    e Zd ZU dZ edd      Zded<   y)DownloadBehaviorDeniedzDownloadBehaviorDenied.r   FrR   r   r
   N)r5   r6   r7   r8   r   r
   r9   r:   r   r   r\   r\      s    !hU3D#3r   r\   c                       e Zd ZdZdZdZdZdZy)ClientWindowNamedStatez)Named states for a browser client window.
fullscreen	maximized	minimizedrQ   N)r5   r6   r7   r8   
FULLSCREEN	MAXIMIZED	MINIMIZEDNORMALr:   r   r   r^   r^      s    3JIIFr   r^   c                  .    e Zd ZU dZdZded<   dZded<   y)SetClientWindowStateParametersa  SetClientWindowStateParameters.

    The ``state`` field is required and must be either a named-state string
    (e.g. ``ClientWindowNamedState.MAXIMIZED``) or a
    :class:`ClientWindowRectState` instance.  ``client_window`` is the ID of
    the window to affect.
    Nr   r   r   )r5   r6   r7   r8   r   r9   r   r:   r   r   rg   rg      s     !%M:$E:r   rg   c                  |    e Zd ZdZddZd Z	 	 	 d	 	 	 	 	 ddZd Zd ZdddZ		 	 	 d	 	 	 	 	 dd	Z
	 	 d	 	 	 dd
Zy)BrowserzWebDriver BiDi browser module.c                    || _         y N)_conn)r$   conns     r   __init__zBrowser.__init__   s	    
r   c                    i }|j                         D ci c]  \  }}|	|| }}}t        d|      }| j                  j                  |      }|S c c}}w )zExecute browser.closezbrowser.close)itemsr   rl   execute)r$   paramskvcmdresults         r   closezBrowser.close   sY    
#)<<>C41aQ]!Q$CCov6##C( Ds
   
AANc                b   |rt        |d      r|j                         }|rt        |d      r|j                         }|||d}|j                         D ci c]  \  }}|	|| }}}t        d|      }| j                  j                  |      }|rd|v r|j                  d      }	|	S |S c c}}w )z!Execute browser.createUserContextto_bidi_dict)acceptInsecureCertsrB   unhandledPromptBehaviorzbrowser.createUserContextuserContext)hasattrry   rp   r   rl   rq   get)
r$   rA   rB   rC   rr   rs   rt   ru   rv   	extracteds
             r   create_user_contextzBrowser.create_user_context   s     WUN3&&(E$1JN)[(A(N(N(P% $9'@

 $*<<>C41aQ]!Q$CC96B##C(mv-

=1I Ds   
B+!B+c                   i }|j                         D ci c]  \  }}|	|| }}}t        d|      }| j                  j                  |      }|rd|v r|j	                  dg       }|D cg c]  }t        |t              r{t        |j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d	      
       c}S g S c c}}w c c}w )z Execute browser.getClientWindowszbrowser.getClientWindowsclientWindowsr   clientWindowr   r   r   r    r!   )r   r   r   r   r   r    r!   )rp   r   rl   rq   r~   
isinstancedictr   r$   rr   rs   rt   ru   rv   rp   items           r   get_client_windowszBrowser.get_client_windows   s    
#)<<>C41aQ]!Q$CC8&A##C(o/JJ3E " dD) !88H-"&((>":88H-((7+((7+hhsmhhsm  	% D
s   
DD,BD	c                H   i }|j                         D ci c]  \  }}|	|| }}}t        d|      }| j                  j                  |      }|rEd|v rA|j	                  dg       }|D cg c]#  }t        |t              r|j	                  d      % c}S g S c c}}w c c}w )zExecute browser.getUserContextszbrowser.getUserContextsuserContextsr|   )rp   r   rl   rq   r~   r   r   r   s           r   get_user_contextszBrowser.get_user_contexts  s    
#)<<>C41aQ]!Q$CC7@##C(n.JJ~r2E "dD) ' 
 	 D
s   
BB,(Bc                    |t        d      d|i}|j                         D ci c]  \  }}|	|| }}}t        d|      }| j                  j	                  |      }|S c c}}w )z!Execute browser.removeUserContextz?remove_user_context() missing required argument: 'user_context'r|   zbrowser.removeUserContext)	TypeErrorrp   r   rl   rq   )r$   r=   rr   rs   rt   ru   rv   s          r   remove_user_contextzBrowser.remove_user_context  su    ]^^ <
 $*<<>C41aQ]!Q$CC96B##C( Ds
   
A!A!c                    t        |||       t        ||      }d|i}|||d<   t        d|      }| j                  j	                  |      S )ah  Set the download behavior for the browser.

        Args:
            allowed: ``True`` to allow downloads, ``False`` to deny, or ``None``
                to reset to browser default (sends ``null`` to the protocol).
            destination_folder: Destination folder for downloads.  Required when
                ``allowed=True``.  Accepts a string or :class:`pathlib.Path`.
            user_contexts: Optional list of user context IDs.

        Raises:
            ValueError: If *allowed* is ``True`` and *destination_folder* is
                omitted, or ``False`` and *destination_folder* is provided.
        r   downloadBehaviorr   zbrowser.setDownloadBehavior)r   r   r   rl   rq   )r$   r	   r   r   rW   rr   ru   s          r   set_download_behaviorzBrowser.set_download_behavior"  sd    & 	#1'	

 6g?QR +,=>$%2F>";VDzz!!#&&r   c                   |t        d      |t        d      |}t        |d      r/|j                  j                         D ci c]
  \  }}||| }}}||d}t	        d|      }| j
                  j                  |      S c c}}w )a  Set the client window state.

        Args:
            client_window: The client window ID to apply the state to.
            state: The window state to set. Can be one of:
                - A string: "fullscreen", "maximized", "minimized", "normal"
                - A ClientWindowRectState object with width, height, x, y
                - A dict representing the state

        Raises:
            ValueError: If client_window is not provided or state is invalid.
        zclient_window is requiredzstate is required__dataclass_fields__)r   r   zbrowser.setClientWindowState)r   r}   __dict__rp   r   rl   rq   )r$   r   r   state_paramrs   rt   rr   ru   s           r   set_client_window_statezBrowser.set_client_window_stateB  s    "  899=011 501 "'!5!5!7A= 1K  * 
 <fEzz!!#&&s   B)returnNone)NNN)rA   r   rB   r   rC   r   rk   )r=   r   )r	   r   r   rZ   r   zlist[Any] | None)NN)r   r   r   r   )r5   r6   r7   r8   rn   rw   r   r   r   r   r   r   r:   r   r   ri   ri      s    ( .2 04	*  $.	40   $)-*.	'' '' (	'D %) $'!$' $'r   ri   )r	   r   r   rZ   r   zdict[str, Any] | Nonerk   )r	   r   r   rZ   r   r   r   r   )
__future__r   dataclassesr   r   typingr   %selenium.webdriver.common.bidi.commonr   r   r   r   r<   r@   rE   rL   rN   rP   rV   rY   r\   r^   rg   ri   r:   r   r   <module>r      s   # (  A" < !%YY"Y Y 
	Y* % % %R $ $ $ 1 1 1 < < < ; ; ; $ $ $    ; ; ; * * * 4 4 4  
 
 
b' b'r   