o
    M,hV8                     @   s  d dl Z d dlmZmZ d dlmZmZmZ d dlm	Z	 d dl
mZ G dd dZG dd	 d	ZeG d
d dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG dd dZeG d d! d!ZeG d"d# d#ZeG d$d% d%ZeG d&d' d'ZG d(d) d)ZG d*d+ d+ZdS ),    N)	dataclassfield)AnyOptionalUnion)command_builder)Sessionc                   @   s&   e Zd ZdZdZdZdZeeehZdS )PointerTypez&Represents the possible pointer types.mousepentouchN)__name__
__module____qualname____doc__MOUSEPENTOUCHVALID_TYPES r   r   p/var/www/www-root/data/www/bot.pdev.uz/venv/lib/python3.10/site-packages/selenium/webdriver/common/bidi/input.pyr	      s    r	   c                   @   s   e Zd ZdZdZdZdS )Originz%Represents the possible origin types.viewportpointerN)r   r   r   r   VIEWPORTPOINTERr   r   r   r   r   $   s    r   c                   @   s>   e Zd ZU dZeed< eed< defddZdefdd	Zd
S )ElementOriginz/Represents an element origin for input actions.typeelementelement_referencec                 C   s   d| _ || _d S )Nr   r   r   )selfr   r   r   r   __init__2   s   
zElementOrigin.__init__returnc                 C      | j | jdS )z*Convert the ElementOrigin to a dictionary.r    r    r!   r   r   r   to_dict6      zElementOrigin.to_dictN)	r   r   r   r   str__annotations__dictr"   r&   r   r   r   r   r   +   s   
 r   c                   @   s6   e Zd ZU dZejZeed< dd Z	de
fddZdS )	PointerParametersz2Represents pointer parameters for pointer actions.pointer_typec                 C   s(   | j tjvrtd| j  dtj d S )NzInvalid pointer type: z. Must be one of )r,   r	   r   
ValueErrorr%   r   r   r   __post_init__A   s   zPointerParameters.__post_init__r#   c                 C   s
   d| j iS )z.Convert the PointerParameters to a dictionary.pointerType)r,   r%   r   r   r   r&   E   s   
zPointerParameters.to_dictN)r   r   r   r   r	   r   r,   r(   r)   r.   r*   r&   r   r   r   r   r+   ;   s
   
 r+   c                   @   s|   e Zd ZU dZdZeed< dZeed< dZe	ed< dZ
e	ed< dZeed	< dZe	ed
< dZe	ed< dd ZdefddZdS )PointerCommonPropertiesz&Common properties for pointer actions.   widthheight        pressuretangential_pressurer   twistaltitude_angleazimuth_anglec                 C   s   | j dk r	td| jdk rtdd| j  kr dks%td tdd| j  kr3dks8td tdd| j  krFd	ksKtd
 td
d| j  kr\tjd ksatd tdd| j	  krrdtj kswtd tdd S )Nr1   zwidth must be at least 1zheight must be at least 1r4   g      ?z$pressure must be between 0.0 and 1.0z/tangential_pressure must be between 0.0 and 1.0r   ig  ztwist must be between 0 and 359   u+   altitude_angle must be between 0.0 and π/2u)   azimuth_angle must be between 0.0 and 2π)
r2   r-   r3   r5   r6   r7   r8   mathpir9   r%   r   r   r   r.   V   s2   

z%PointerCommonProperties.__post_init__r#   c                 C   s   i }| j dkr| j |d< | jdkr| j|d< | jdkr | j|d< | jdkr*| j|d< | jdkr4| j|d< | jdkr>| j|d	< | jdkrH| j|d
< |S )z4Convert the PointerCommonProperties to a dictionary.r1   r2   r3   r4   r5   tangentialPressurer   r7   altitudeAngleazimuthAngle)r2   r3   r5   r6   r7   r8   r9   r!   resultr   r   r   r&   f   s    













zPointerCommonProperties.to_dictN)r   r   r   r   r2   intr)   r3   r5   floatr6   r7   r8   r9   r.   r*   r&   r   r   r   r   r0   J   s   
 r0   c                   @   sB   e Zd ZU dZdZee ed< ede	fddZ
defddZdS )	PauseActionzRepresents a pause action.Ndurationr#   c                 C      dS )Npauser   r%   r   r   r   r         zPauseAction.typec                 C   s"   d| j i}| jdur| j|d< |S )z(Convert the PauseAction to a dictionary.r   NrE   )r   rE   r@   r   r   r   r&      s   


zPauseAction.to_dict)r   r   r   r   rE   r   rB   r)   propertyr(   r   r*   r&   r   r   r   r   rD   {   s   
 rD   c                   @   >   e Zd ZU dZdZeed< edefddZde	fddZ
d	S )
KeyDownActionzRepresents a key down action. valuer#   c                 C   rF   )NkeyDownr   r%   r   r   r   r      rH   zKeyDownAction.typec                 C   r$   )z*Convert the KeyDownAction to a dictionary.r   rM   rO   r%   r   r   r   r&      r'   zKeyDownAction.to_dictNr   r   r   r   rM   r(   r)   rI   r   r*   r&   r   r   r   r   rK         
 rK   c                   @   rJ   )
KeyUpActionzRepresents a key up action.rL   rM   r#   c                 C   rF   )NkeyUpr   r%   r   r   r   r      rH   zKeyUpAction.typec                 C   r$   )z(Convert the KeyUpAction to a dictionary.rO   rO   r%   r   r   r   r&      r'   zKeyUpAction.to_dictNrP   r   r   r   r   rR      rQ   rR   c                   @   sN   e Zd ZU dZdZeed< dZee	 ed< e
defddZdefd	d
ZdS )PointerDownActionz!Represents a pointer down action.r   buttonN
propertiesr#   c                 C   rF   )NpointerDownr   r%   r   r   r   r      rH   zPointerDownAction.typec                 C   s(   | j | jd}| jr|| j  |S )z.Convert the PointerDownAction to a dictionary.r   rU   )r   rU   rV   updater&   r@   r   r   r   r&      s   zPointerDownAction.to_dict)r   r   r   r   rU   rB   r)   rV   r   r0   rI   r(   r   r*   r&   r   r   r   r   rT      s   
 rT   c                   @   s>   e Zd ZU dZdZeed< edefddZ	de
fddZd	S )
PointerUpActionzRepresents a pointer up action.r   rU   r#   c                 C   rF   )N	pointerUpr   r%   r   r   r   r      rH   zPointerUpAction.typec                 C   r$   )z,Convert the PointerUpAction to a dictionary.rX   rX   r%   r   r   r   r&      r'   zPointerUpAction.to_dictN)r   r   r   r   rU   rB   r)   rI   r(   r   r*   r&   r   r   r   r   rZ      rQ   rZ   c                   @   s   e Zd ZU dZdZeed< dZeed< dZe	e
 ed< dZe	eeef  ed< dZe	e ed< ed	efd
dZd	efddZdS )PointerMoveActionz!Represents a pointer move action.r   xyNrE   originrV   r#   c                 C   rF   )NpointerMover   r%   r   r   r   r      rH   zPointerMoveAction.typec                 C   sp   | j | j| jd}| jdur| j|d< | jdur+t| jtr&| j |d< n| j|d< | jr6|	| j  |S )z.Convert the PointerMoveAction to a dictionary.)r   r]   r^   NrE   r_   )
r   r]   r^   rE   r_   
isinstancer   r&   rV   rY   r@   r   r   r   r&      s   



zPointerMoveAction.to_dict)r   r   r   r   r]   rC   r)   r^   rE   r   rB   r_   r   r(   r   rV   r0   rI   r   r*   r&   r   r   r   r   r\      s   
 r\   c                   @   s   e Zd ZU dZdZeed< dZeed< dZeed< dZ	eed< dZ
ee ed< ejZeeeef  ed	< ed
efddZd
efddZdS )WheelScrollActionz!Represents a wheel scroll action.r   r]   r^   delta_xdelta_yNrE   r_   r#   c                 C   rF   )Nscrollr   r%   r   r   r   r      rH   zWheelScrollAction.typec                 C   sd   | j | j| j| j| jd}| jdur| j|d< | jdur0t| jtr+| j	 |d< |S | j|d< |S )z.Convert the WheelScrollAction to a dictionary.)r   r]   r^   deltaXdeltaYNrE   r_   )
r   r]   r^   rc   rd   rE   r_   ra   r   r&   r@   r   r   r   r&      s   



zWheelScrollAction.to_dict)r   r   r   r   r]   rB   r)   r^   rc   rd   rE   r   r   r   r_   r   r(   r   rI   r   r*   r&   r   r   r   r   rb      s   
 rb   c                   @   sT   e Zd ZU dZdZeed< eedZ	ee
 ed< edefddZdefd	d
ZdS )NoneSourceActionsz&Represents a sequence of none actions.rL   iddefault_factoryactionsr#   c                 C   rF   )Nnoner   r%   r   r   r   r     rH   zNoneSourceActions.typec                 C      | j | jdd | jD dS )z.Convert the NoneSourceActions to a dictionary.c                 S      g | ]}|  qS r   r&   .0actionr   r   r   
<listcomp>      z-NoneSourceActions.to_dict.<locals>.<listcomp>r   ri   rl   rv   r%   r   r   r   r&        zNoneSourceActions.to_dictN)r   r   r   r   ri   r(   r)   r   listrl   rD   rI   r   r*   r&   r   r   r   r   rh     s   
 rh   c                   @   s^   e Zd ZU dZdZeed< eedZ	ee
eeef  ed< edefddZdefd	d
ZdS )KeySourceActionsz%Represents a sequence of key actions.rL   ri   rj   rl   r#   c                 C   rF   )Nkeyr   r%   r   r   r   r   $  rH   zKeySourceActions.typec                 C   rn   )z-Convert the KeySourceActions to a dictionary.c                 S   ro   r   rp   rq   r   r   r   rt   *  ru   z,KeySourceActions.to_dict.<locals>.<listcomp>rv   rv   r%   r   r   r   r&   (  rw   zKeySourceActions.to_dictN)r   r   r   r   ri   r(   r)   r   rx   rl   r   rD   rK   rR   rI   r   r*   r&   r   r   r   r   ry     s   
  ry   c                   @   sx   e Zd ZU dZdZeed< dZee	 ed< e
edZeeeeeef  ed< dd	 Zed
efddZd
efddZdS )PointerSourceActionsz)Represents a sequence of pointer actions.rL   ri   N
parametersrj   rl   c                 C   s   | j d u rt | _ d S d S N)r|   r+   r%   r   r   r   r.   7  s   
z"PointerSourceActions.__post_init__r#   c                 C   rF   )Nr   r   r%   r   r   r   r   ;  rH   zPointerSourceActions.typec                 C   s4   | j | jdd | jD d}| jr| j |d< |S )z1Convert the PointerSourceActions to a dictionary.c                 S   ro   r   rp   rq   r   r   r   rt   D  ru   z0PointerSourceActions.to_dict.<locals>.<listcomp>rv   r|   )r   ri   rl   r|   r&   r@   r   r   r   r&   ?  s   zPointerSourceActions.to_dict)r   r   r   r   ri   r(   r)   r|   r   r+   r   rx   rl   r   rD   rT   rZ   r\   r.   rI   r   r*   r&   r   r   r   r   r{   -  s   
 r{   c                   @   s\   e Zd ZU dZdZeed< eedZ	ee
eef  ed< edefddZdefd	d
ZdS )WheelSourceActionsz'Represents a sequence of wheel actions.rL   ri   rj   rl   r#   c                 C   rF   )Nwheelr   r%   r   r   r   r   R  rH   zWheelSourceActions.typec                 C   rn   )z/Convert the WheelSourceActions to a dictionary.c                 S   ro   r   rp   rq   r   r   r   rt   X  ru   z.WheelSourceActions.to_dict.<locals>.<listcomp>rv   rv   r%   r   r   r   r&   V  rw   zWheelSourceActions.to_dictN)r   r   r   r   ri   r(   r)   r   rx   rl   r   rD   rb   rI   r   r*   r&   r   r   r   r   r~   K  s   
 r~   c                   @   sH   e Zd ZU dZeed< eed< dZee	 ed< e
de	dd fdd	ZdS )
FileDialogInfozERepresents file dialog information from input.fileDialogOpened event.contextmultipleNr   datar#   c                 C   s   | |d |d | ddS )a  Creates a FileDialogInfo instance from a dictionary.

        Parameters:
        -----------
            data: A dictionary containing the file dialog information.

        Returns:
        -------
            FileDialogInfo: A new instance of FileDialogInfo.
        r   r   r   )r   r   r   )get)clsr   r   r   r   	from_dictc  s   zFileDialogInfo.from_dict)r   r   r   r   r(   r)   boolr   r   r*   classmethodr   r   r   r   r   r   [  s   
 r   c                   @   s    e Zd ZdZdZedd ZdS )FileDialogOpenedz-Event class for input.fileDialogOpened event.zinput.fileDialogOpenedc                 C   s
   t |S )z%Create FileDialogInfo from JSON data.)r   r   )r   jsonr   r   r   	from_jsonx  s   
zFileDialogOpened.from_jsonN)r   r   r   r   event_classr   r   r   r   r   r   r   s  s
    r   c                	   @   s   e Zd ZdZdd Zdedeeee	e
ef  ddfdd	Zdeddfd
dZdededee ddfddZdd ZdeddfddZdS )Inputz2
    BiDi implementation of the input module.
    c                 C   s   || _ i | _i | _d S r}   )connsubscriptions	callbacks)r!   r   r   r   r   r"     s   
zInput.__init__r   rl   r#   Nc                 C   s*   |dd |D d}| j td| dS )zPerforms a sequence of user input actions.

        Parameters:
        -----------
            context: The browsing context ID where actions should be performed.
            actions: A list of source actions to perform.
        c                 S   ro   r   rp   rq   r   r   r   rt     ru   z)Input.perform_actions.<locals>.<listcomp>)r   rl   zinput.performActionsNr   executer   )r!   r   rl   paramsr   r   r   perform_actions  s   zInput.perform_actionsc                 C   s   d|i}| j td| dS )zReleases all input state for the given context.

        Parameters:
        -----------
            context: The browsing context ID to release actions for.
        r   zinput.releaseActionsNr   )r!   r   r   r   r   r   release_actions  s   zInput.release_actionsr   filesc                 C   s"   |||d}| j td| dS )zSets files for a file input element.

        Parameters:
        -----------
            context: The browsing context ID.
            element: The element reference (script.SharedReference).
            files: A list of file paths to set.
        )r   r   r   zinput.setFilesNr   )r!   r   r   r   r   r   r   r   	set_files  s   	zInput.set_filesc                 C   sd   t j| jvrt| j}| j|t j g | jt j< | jt |}| jt j | || j	|< |S )a	  Add a handler for file dialog opened events.

        Parameters:
        -----------
            handler: Callback function that takes a FileDialogInfo object.

        Returns:
        --------
            int: Callback ID for removing the handler later.
        )
r   r   r   r   r   r   	subscribeadd_callbackappendr   )r!   handlersessioncallback_idr   r   r   add_file_dialog_handler  s   

zInput.add_file_dialog_handlerr   c                 C   s   || j v r	| j |= tj| jv r:|| jtj v r | jtj | | jtj s:t| j}| j|tj | jtj= | j	t| dS )zRemove a file dialog handler.

        Parameters:
        -----------
            callback_id: The callback ID returned by add_file_dialog_handler.
        N)
r   r   r   r   remover   r   r   unsubscriberemove_callback)r!   r   r   r   r   r   remove_file_dialog_handler  s   


z Input.remove_file_dialog_handler)r   r   r   r   r"   r(   rx   r   rh   ry   r{   r~   r   r   r*   r   r   rB   r   r   r   r   r   r   ~  s    

r   )r;   dataclassesr   r   typingr   r   r   %selenium.webdriver.common.bidi.commonr   &selenium.webdriver.common.bidi.sessionr   r	   r   r   r+   r0   rD   rK   rR   rT   rZ   r\   rb   rh   ry   r{   r~   r   r   r   r   r   r   r   <module>   sN   
0"