o
    M,h                     @   sb   d dl mZmZ d dlmZ d dlmZ d dlmZ G dd dZ	G dd dZ
G d	d
 d
ZdS )    )AnyOptional)command_builder)UserPromptHandler)Proxyc                   @   s,   e Zd ZdZdZdZdZdZeeeehZdS )ClientWindowStatezRepresents a window state.
fullscreen	maximized	minimizednormalN)	__name__
__module____qualname____doc__
FULLSCREEN	MAXIMIZED	MINIMIZEDNORMALVALID_STATES r   r   r/var/www/www-root/data/www/bot.pdev.uz/venv/lib/python3.10/site-packages/selenium/webdriver/common/bidi/browser.pyr      s    r   c                   @   s   e Zd ZdZdededededededefd	d
ZdefddZdefddZ	defddZ
defddZdefddZdefddZdefddZededd fddZdS )ClientWindowInfoz'Represents a client window information.client_windowstatewidthheightxyactivec                 C   s.   || _ || _|| _|| _|| _|| _|| _d S Nr   r   r   r   r   r   r   )selfr   r   r   r   r   r   r   r   r   r   __init__(   s   

zClientWindowInfo.__init__returnc                 C      | j S )zGets the state of the client window.

        Returns:
        -------
            str: The state of the client window (one of the ClientWindowState constants).
        )r   r!   r   r   r   	get_state:      zClientWindowInfo.get_statec                 C   r$   )z|Gets the client window identifier.

        Returns:
        -------
            str: The client window identifier.
        )r   r%   r   r   r   get_client_windowC   r'   z"ClientWindowInfo.get_client_windowc                 C   r$   )zGets the width of the client window.

        Returns:
        -------
            int: The width of the client window.
        )r   r%   r   r   r   	get_widthL   r'   zClientWindowInfo.get_widthc                 C   r$   )zGets the height of the client window.

        Returns:
        -------
            int: The height of the client window.
        )r   r%   r   r   r   
get_heightU   r'   zClientWindowInfo.get_heightc                 C   r$   )zGets the x coordinate of the client window.

        Returns:
        -------
            int: The x coordinate of the client window.
        )r   r%   r   r   r   get_x^   r'   zClientWindowInfo.get_xc                 C   r$   )zGets the y coordinate of the client window.

        Returns:
        -------
            int: The y coordinate of the client window.
        )r   r%   r   r   r   get_yg   r'   zClientWindowInfo.get_yc                 C   r$   )zChecks if the client window is active.

        Returns:
        -------
            bool: True if the client window is active, False otherwise.
        )r   r%   r   r   r   	is_activep   r'   zClientWindowInfo.is_activedatac           
   
   C   sN  z|d }t |tstd|d }t |tstd|tjvr+td| dtj |d }t |tr8|dk r?td	| |d
 }t |trL|dk rStd| |d }t |tsftdt|j |d }t |tsytdt|j |d }t |tstd| |||||||dW S  t	t
fy }	 ztd|	 d}	~	ww )a  Creates a ClientWindowInfo instance from a dictionary.

        Parameters:
        -----------
            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   er   r   r   	from_dicty   sJ   





	zClientWindowInfo.from_dictN)r   r   r   r   r1   r3   r5   r"   r&   r(   r)   r*   r+   r,   r-   classmethoddictr:   r   r   r   r   r   %   s4    
							r   c                	   @   s|   e Zd ZdZdd Z			ddee dee dee de	fd	d
Z
dee	 fddZde	ddfddZdee fddZdS )Browserz4
    BiDi implementation of the browser module.
    c                 C   s
   || _ d S r   )conn)r!   r>   r   r   r   r"      s   
zBrowser.__init__Naccept_insecure_certsproxyunhandled_prompt_behaviorr#   c                 C   sV   i }|dur
||d< |dur|  |d< |dur| |d< | jtd|}|d S )a  Creates a new user context.

        Parameters:
        -----------
            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.
        NacceptInsecureCertsr@   unhandledPromptBehaviorzbrowser.createUserContextuserContext)to_bidi_dictto_dictr>   executer   )r!   r?   r@   rA   paramsresultr   r   r   create_user_context   s   zBrowser.create_user_contextc                 C   $   | j tdi }dd |d D S )zuGets all user contexts.

        Returns:
        -------
            List[str]: A list of user context IDs.
        zbrowser.getUserContextsc                 S   s   g | ]}|d  qS )rD   r   ).0context_infor   r   r   
<listcomp>   s    z-Browser.get_user_contexts.<locals>.<listcomp>userContextsr>   rG   r   r!   rI   r   r   r   get_user_contexts      zBrowser.get_user_contextsuser_context_idc                 C   s.   |dkrt dd|i}| jtd| dS )zRemoves a user context.

        Parameters:
        -----------
            user_context_id: The ID of the user context to remove.

        Raises:
        ------
            Exception: If the user context ID is "default" or does not exist.
        defaultz&Cannot remove the default user contextrD   zbrowser.removeUserContextN)	Exceptionr>   rG   r   )r!   rT   rH   r   r   r   remove_user_context   s   zBrowser.remove_user_contextc                 C   rK   )zGets all client windows.

        Returns:
        -------
            List[ClientWindowInfo]: A list of client window information.
        zbrowser.getClientWindowsc                 S   s   g | ]}t |qS r   )r   r:   )rL   windowr   r   r   rN      s    z.Browser.get_client_windows.<locals>.<listcomp>clientWindowsrP   rQ   r   r   r   get_client_windows   rS   zBrowser.get_client_windows)NNN)r   r   r   r   r"   r   r5   r   r   r1   rJ   listrR   rW   r   rZ   r   r   r   r   r=      s$    
 
r=   N)typingr   r   %selenium.webdriver.common.bidi.commonr   &selenium.webdriver.common.bidi.sessionr   selenium.webdriver.common.proxyr   r   r   r=   r   r   r   r   <module>   s    