
    /_i$                     x    d dl Z d dlmZ d dlmZ d dlmZ d dlmZ  G d d      Z	 G d d	      Z
 G d
 d      Zy)    N)Any)command_builder)UserPromptHandler)Proxyc                   ,    e Zd ZdZdZdZdZdZeeeehZy)ClientWindowStatezRepresents a window state.
fullscreen	maximized	minimizednormalN)	__name__
__module____qualname____doc__
FULLSCREEN	MAXIMIZED	MINIMIZEDNORMALVALID_STATES     e/var/www/html/land_sniper/venv/lib/python3.12/site-packages/selenium/webdriver/common/bidi/browser.pyr   r      s'    $JIIF	9f=Lr   r   c                       e Zd ZdZdededededededefd	Zd
efdZd
efdZ	d
efdZ
d
efdZd
efdZd
efdZd
efdZeded
d fd       Zy)ClientWindowInfoz'Represents a client window information.client_windowstatewidthheightxyactivec                 f    || _         || _        || _        || _        || _        || _        || _        y Nr   r   r   r   r   r    r!   )selfr   r   r   r   r   r    r!   s           r   __init__zClientWindowInfo.__init__'   s6     +

r   returnc                     | j                   S )zGets the state of the client window.

        Returns:
            str: The state of the client window (one of the ClientWindowState constants).
        )r   r%   s    r   	get_statezClientWindowInfo.get_state9        zzr   c                     | j                   S )zlGets the client window identifier.

        Returns:
            str: The client window identifier.
        )r   r)   s    r   get_client_windowz"ClientWindowInfo.get_client_windowA   s     !!!r   c                     | j                   S )zpGets the width of the client window.

        Returns:
            int: The width of the client window.
        )r   r)   s    r   	get_widthzClientWindowInfo.get_widthI   r+   r   c                     | j                   S )zrGets the height of the client window.

        Returns:
            int: The height of the client window.
        )r   r)   s    r   
get_heightzClientWindowInfo.get_heightQ        {{r   c                     | j                   S )z~Gets the x coordinate of the client window.

        Returns:
            int: The x coordinate of the client window.
        )r   r)   s    r   get_xzClientWindowInfo.get_xY        vvr   c                     | j                   S )z~Gets the y coordinate of the client window.

        Returns:
            int: The y coordinate of the client window.
        )r    r)   s    r   get_yzClientWindowInfo.get_ya   r5   r   c                     | j                   S )zChecks if the client window is active.

        Returns:
            bool: True if the client window is active, False otherwise.
        )r!   r)   s    r   	is_activezClientWindowInfo.is_activei   r2   r   datac           	         	 |d   }t        |t              st        d      |d   }t        |t              st        d      |t        j                  vrt        d| dt        j                         |d   }t        |t
              r|dk  rt        d	|       |d
   }t        |t
              r|dk  rt        d|       |d   }t        |t
              s!t        dt        |      j                         |d   }t        |t
              s!t        dt        |      j                         |d   }t        |t              st        d       | |||||||      S # t        t        f$ r}	t        d|	       |	d}	~	ww xY w)aJ  Creates a ClientWindowInfo instance from a dictionary.

        Args:
            data: A dictionary containing the client window information.

        Returns:
            ClientWindowInfo: A new instance of ClientWindowInfo.

        Raises:
            ValueError: If required fields are missing or have invalid types.
        clientWindowzclientWindow must be a stringr   zstate must be a stringzInvalid state: z. Must be one of r   r   z*width must be a non-negative integer, got r   z+height must be a non-negative integer, got r   zx must be an integer, got r    zy must be an integer, got r!   zactive must be a booleanr$   z*Invalid data format for ClientWindowInfo: N)
isinstancestr
ValueErrorr   r   inttyper   boolKeyError	TypeError)
clsr:   r   r   r   r   r   r    r!   es
             r   	from_dictzClientWindowInfo.from_dictq   s   )	V 0MmS1 !@AAMEeS) !9::-::: ?5'9JK\KiKiJj!kllMEeS)UQY #MeW!UVV(^Ffc*fqj #Nvh!WXXS	Aa% #=d1g>N>N=O!PQQS	Aa% #=d1g>N>N=O!PQQ(^Ffd+ !;<<+  )$ 	VI!MNTUU	Vs   EE F-E<<FN)r   r   r   r   r>   r@   rB   r&   r*   r-   r/   r1   r4   r7   r9   classmethoddictrG   r   r   r   r   r   $   s    1  	
    $3 "3 "3 C s s 4  5VT 5V&8 5V 5Vr   r   c            	           e Zd ZdZd Z	 	 	 ddedz  dedz  dedz  defdZ	de
e   fd	Zd
eddfdZde
e   fdZdddddedz  deej                   z  dz  de
e   dz  ddfdZy)Browserz*BiDi implementation of the browser module.c                     || _         y r#   )conn)r%   rM   s     r   r&   zBrowser.__init__   s	    	r   Naccept_insecure_certsproxyunhandled_prompt_behaviorr'   c                     i }|||d<   ||j                         |d<   ||j                         |d<   | j                  j                  t	        d|            }|d   S )ao  Creates a new user context.

        Args:
            accept_insecure_certs: Optional flag to accept insecure TLS certificates.
            proxy: Optional proxy configuration for the user context.
            unhandled_prompt_behavior: Optional configuration for handling user prompts.

        Returns:
            str: The ID of the created user context.
        acceptInsecureCertsrO   unhandledPromptBehaviorzbrowser.createUserContextuserContext)to_bidi_dictto_dictrM   executer   )r%   rN   rO   rP   paramsresults         r   create_user_contextzBrowser.create_user_context   st      "$ ,,AF()#002F7O$00I0Q0Q0SF,-""?3NPV#WXm$$r   c                     | j                   j                  t        di             }|d   D cg c]  }|d   	 c}S c c}w )zeGets all user contexts.

        Returns:
            List[str]: A list of user context IDs.
        zbrowser.getUserContextsuserContextsrT   )rM   rW   r   )r%   rY   context_infos      r   get_user_contextszBrowser.get_user_contexts   s>     ""?3Lb#QR@F~@VW]+WWWs   <user_context_idc                 v    |dk(  rt        d      d|i}| j                  j                  t        d|             y)zRemoves a user context.

        Args:
            user_context_id: The ID of the user context to remove.

        Raises:
            ValueError: If the user context ID is "default" or does not exist.
        defaultz&Cannot remove the default user contextrT   zbrowser.removeUserContextN)r?   rM   rW   r   )r%   r_   rX   s      r   remove_user_contextzBrowser.remove_user_context   s<     i'EFF1		/*EvNOr   c                     | j                   j                  t        di             }|d   D cg c]  }t        j	                  |       c}S c c}w )z|Gets all client windows.

        Returns:
            List[ClientWindowInfo]: A list of client window information.
        zbrowser.getClientWindowsclientWindows)rM   rW   r   r   rG   )r%   rY   windows      r   get_client_windowszBrowser.get_client_windows   sE     ""?3Mr#RSAGAXYv **62YYYs   A)alloweddestination_folderuser_contextsrg   rh   ri   c                    i }|d|d<   n?|r)|st        d      dt        j                  |      d|d<   n|rt        d      ddi|d<   |||d	<   | j                  j	                  t        d
|             y)a  Set the download behavior for the browser or specific user contexts.

        Args:
            allowed: True to allow downloads, False to deny downloads, or None to
                clear download behavior (revert to default).
            destination_folder: Required when allowed is True. Specifies the folder
                to store downloads in.
            user_contexts: Optional list of user context IDs to apply this
                behavior to. If omitted, updates the default behavior.

        Raises:
            ValueError: If allowed=True and destination_folder is missing, or if
                allowed=False and destination_folder is provided.
        NdownloadBehaviorz1destination_folder is required when allowed=True.rg   )rA   destinationFolderz=destination_folder should not be provided when allowed=False.rA   deniedr\   zbrowser.setDownloadBehavior)r?   osfspathrM   rW   r   )r%   rg   rh   ri   rX   s        r   set_download_behaviorzBrowser.set_download_behavior   s    * "$?)-F%&)$%XYY%)+3E)F.)*
 &$%dee.4h-?)*$%2F>"		/*GPQr   )NNN)r   r   r   r   r&   rB   r   r   r>   rZ   listr^   rb   r   rf   rn   PathLikerp   r   r   r   rK   rK      s    4
 .2">B	%#d{% t|% $5t#;	%
 
%<X49 XP3 P4 PZD)9$: Z  $7;*.)R )R  "++-4	)R
 Cy4')R 
)Rr   rK   )rn   typingr   %selenium.webdriver.common.bidi.commonr   &selenium.webdriver.common.bidi.sessionr   selenium.webdriver.common.proxyr   r   r   rK   r   r   r   <module>rw      s=   " 
  A D 1> >CV CVLnR nRr   