
    iMI                     2   S SK r S SKrS SKJr  S SKJrJr  S SKJr  S SK	J
r
  S SKJr  S SKJr   " S S	5      r " S
 S5      r\ " S S5      5       r\ " S S5      5       r\ " S S5      5       r " S S5      r " S S5      r " S S5      r " S S5      rg)    N)	dataclass)AnyOptional)WebDriverException)command_builder)LogEntryAdded)Sessionc                        \ rS rSrSrSrSrSrg)ResultOwnership   z/Represents the possible result ownership types.noneroot N)__name__
__module____qualname____firstlineno____doc__NONEROOT__static_attributes__r       RC:\des-py\RoboSAPF\venv\Lib\site-packages\selenium\webdriver\common\bidi\script.pyr   r      s    9DDr   r   c                   8    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrg)	RealmType$   z$Represents the possible realm types.windowzdedicated-workerzshared-workerzservice-workerworkerzpaint-workletzaudio-workletworkletr   N)r   r   r   r   r   WINDOWDEDICATED_WORKERSHARED_WORKERSERVICE_WORKERWORKERPAINT_WORKLETAUDIO_WORKLETWORKLETr   r   r   r   r   r   $   s.    .F)#M%NF#M#MGr   r   c                       \ rS rSr% Sr\\S'   \\S'   \\S'   Sr\\   \S'   Sr	\\   \S'   \
S	\\\4   S
S 4S j5       rSrg)	RealmInfo1   z%Represents information about a realm.realmorigintypeNcontextsandboxjsonreturnc           	          SU;  a  [        S5      eSU;  a  [        S5      eSU;  a  [        S5      eU " US   US   US   UR                  S5      UR                  S5      S	9$ )
zCreates a RealmInfo instance from a dictionary.

Args:
    json: A dictionary containing the realm information.

Returns:
    RealmInfo: A new instance of RealmInfo.
r+   z+Missing required field 'realm' in RealmInfor,   z,Missing required field 'origin' in RealmInfor-   z*Missing required field 'type' in RealmInfor.   r/   )r+   r,   r-   r.   r/   
ValueErrorgetclsr0   s     r   	from_jsonRealmInfo.from_json;   sz     $JKK4KLLIJJw->fHHY'HHY'
 	
r   r   )r   r   r   r   r   str__annotations__r.   r   r/   classmethoddictr   r8   r   r   r   r   r)   r)   1   sX    /JK
I!GXc]!!GXc]!
T#s(^ 
 
 
r   r)   c                   ^    \ rS rSr% Sr\\S'   Sr\\   \S'   \	S\
\\4   SS 4S j5       rS	rg)
SourceU   z*Represents the source of a script message.r+   Nr.   r0   r1   c                 V    SU;  a  [        S5      eU " US   UR                  S5      S9$ )zCreates a Source instance from a dictionary.

Args:
    json: A dictionary containing the source information.

Returns:
    Source: A new instance of Source.
r+   z(Missing required field 'realm' in Sourcer.   )r+   r.   r3   r6   s     r   r8   Source.from_json\   s8     $GHHw-HHY'
 	
r   r   )r   r   r   r   r   r:   r;   r.   r   r<   r=   r   r8   r   r   r   r   r?   r?   U   s@    4J!GXc]!
T#s(^ 
 
 
r   r?   c                   |    \ rS rSr% Sr\\S'   \\S'   Sr\\	   \S'   Sr
\\	   \S'   \S\	\\4   S	S 4S
 j5       rSrg)EvaluateResulto   z+Represents the result of script evaluation.r-   r+   Nresultexception_detailsr0   r1   c                     SU;  a  [        S5      eSU;  a  [        S5      eU " US   US   UR                  S5      UR                  S5      S9$ )zCreates an EvaluateResult instance from a dictionary.

Args:
    json: A dictionary containing the evaluation result.

Returns:
    EvaluateResult: A new instance of EvaluateResult.
r+   z0Missing required field 'realm' in EvaluateResultr-   z/Missing required field 'type' in EvaluateResultrF   exceptionDetails)r-   r+   rF   rG   r3   r6   s     r   r8   EvaluateResult.from_jsonx   s`     $OPPNOOfw-88H%"hh'9:	
 	
r   r   )r   r   r   r   r   r:   r;   rF   r   r=   rG   r<   r   r8   r   r   r   r   rD   rD   o   sU    5
IJ!FHTN!(,x~,
T#s(^ 
0@ 
 
r   rD   c                   X    \ rS rSrSrSrS\S\S\4S jr	\
S\\\4   S	S 4S
 j5       rSrg)ScriptMessage   z"Represents a script message event.script.messagechanneldatasourcec                 (    Xl         X l        X0l        g NrO   rP   rQ   )selfrO   rP   rQ   s       r   __init__ScriptMessage.__init__   s    	r   r0   r1   c                     SU;  a  [        S5      eSU;  a  [        S5      eSU;  a  [        S5      eU " US   US   [        R                  US   5      S9$ )zCreates a ScriptMessage instance from a dictionary.

Args:
    json: A dictionary containing the script message.

Returns:
    ScriptMessage: A new instance of ScriptMessage.
rO   z1Missing required field 'channel' in ScriptMessagerP   z.Missing required field 'data' in ScriptMessagerQ   z0Missing required field 'source' in ScriptMessagerT   )r4   r?   r8   r6   s     r   r8   ScriptMessage.from_json   sm     D PQQMNN4OPPOf##DN3
 	
r   rT   N)r   r   r   r   r   event_classr:   r=   r?   rV   r<   r   r8   r   r   r   r   rL   rL      sN    ,"K 4  
 
T#s(^ 
 
 
r   rL   c                   P    \ rS rSrSrSrS\4S jr\S\	\
\4   SS 4S j5       rS	rg
)RealmCreated   z!Represents a realm created event.script.realmCreated
realm_infoc                     Xl         g rS   r_   )rU   r_   s     r   rV   RealmCreated.__init__   s    $r   r0   r1   c                 4    U " [         R                  U5      S9$ )zCreates a RealmCreated instance from a dictionary.

Args:
    json: A dictionary containing the realm created event.

Returns:
    RealmCreated: A new instance of RealmCreated.
ra   )r)   r8   r6   s     r   r8   RealmCreated.from_json   s     i11$788r   ra   N)r   r   r   r   r   rZ   r)   rV   r<   r=   r:   r   r8   r   r   r   r   r\   r\      s@    +'K%9 % 	9T#s(^ 	9 	9 	9r   r\   c                   P    \ rS rSrSrSrS\4S jr\S\	\\
4   SS 4S j5       rS	rg
)RealmDestroyed   z#Represents a realm destroyed event.script.realmDestroyedr+   c                     Xl         g rS   r+   )rU   r+   s     r   rV   RealmDestroyed.__init__   s    
r   r0   r1   c                 6    SU;  a  [        S5      eU " US   S9$ )zCreates a RealmDestroyed instance from a dictionary.

Args:
    json: A dictionary containing the realm destroyed event.

Returns:
    RealmDestroyed: A new instance of RealmDestroyed.
r+   z0Missing required field 'realm' in RealmDestroyedrj   )r4   r6   s     r   r8   RealmDestroyed.from_json   s'     $OPPg''r   rj   N)r   r   r   r   r   rZ   r:   rV   r<   r=   r   r8   r   r   r   r   rf   rf      sA    -)Kc  (T#s(^ (0@ ( (r   rf   c                      \ rS rSrSrSSSS.rS,S jrS	 rS
 rS r	\	r
S\S\4S jrS\SS4S jrS\S\4S jrS\4S jr    S-S\S\\\\\4         S\\\      S\\\      S\\   S\4S jjrS\SS4S jrS\\   S\SS4S jr     S.S\S\S\S\\\      S\\   S\\   S \\   S!\S\4S" jjr   S/S#\S\S\S\\   S\\   S!\S\4S$ jjr  S0S%\\   S&\\   S\\   4S' jjrS( rS) rS* rS+r g)1Script   z)BiDi implementation of the script module.rN   r^   rh   )messagerealm_createdrealm_destroyedNc                 F    Xl         X l        SU l        0 U l        0 U l        g NF)conndriverlog_entry_subscribedsubscriptions	callbacks)rU   rv   rw   s      r   rV   Script.__init__   s#    	$)!r   c                     U R                  5         U R                  R                  [        U R	                  SU5      5      $ )Nconsole_subscribe_to_log_entriesrv   add_callbackr   _handle_log_entryrU   handlers     r   add_console_message_handler"Script.add_console_message_handler   s3    &&(yy%%mT5K5KIW^5_``r   c                     U R                  5         U R                  R                  [        U R	                  SU5      5      $ )N
javascriptr~   r   s     r   add_javascript_error_handler#Script.add_javascript_error_handler   s3    &&(yy%%mT5K5KLZa5bccr   c                 d    U R                   R                  [        U5        U R                  5         g rS   )rv   remove_callbackr   _unsubscribe_from_log_entries)rU   ids     r   remove_console_message_handler%Script.remove_console_message_handler   s"    		!!-4**,r   scriptr1   c                 $    U R                  U5      $ )zPins a script to the current browsing context.

Args:
    script: The script to pin.

Returns:
    str: The ID of the pinned script.
)_add_preload_script)rU   r   s     r   pin
Script.pin   s     ''//r   	script_idc                 &    U R                  U5        g)zoUnpins a script from the current browsing context.

Args:
    script_id: The ID of the pinned script to unpin.
N)_remove_preload_script)rU   r   s     r   unpinScript.unpin	  s     	##I.r   c                    U R                   c  [        S5      eU R                   R                  n/ nU H#  nUR                  U R	                  U5      5        M%     SU0nU R                  USXd(       a  UOSS9nUR                  S:X  a  UR                  b  UR                  $ 0 $ SnUR                  (       aK  SUR                  ;   a  US	UR                  S    3-  nO%S
UR                  ;   a  US	UR                  S
    3-  n[        U5      e)a  Executes a script in the current browsing context.

Args:
    script: The script function to execute.
    *args: Arguments to pass to the script function.

Returns:
    dict: The result value from the script execution.

Raises:
    WebDriverException: If the script execution fails.
Nz1Driver reference is required for script executionr.   T)function_declarationawait_promisetarget	argumentssuccesszError while executing scripttextz: rq   )	rw   r   current_window_handleappend_Script__convert_to_local_value_call_functionr-   rF   rG   )	rU   r   argsbrowsing_context_idr   argr   rF   error_messages	            r   executeScript.execute  s    ;;$%XYY"kk?? 	CT::3?@  01$$!'tFclV_rv % 
 ;;)#$*MM$=6==E2E:M''V555!r&*B*B6*J)K%LLM&":"::!r&*B*B9*M)N%OOM$]33r   c           	         Uc  SS0$ [        U[        5      (       a  SUS.$ [        U[        [        45      (       a  [        U[        5      (       aq  [        R
                  " U5      (       a  SSS.$ [        R                  " U5      (       a  US:  a  SSS.$ SS	S.$ US
:X  a   [        R                  " SU5      S:  a  SSS.$ Sn[        U[        5      (       a  X:  d  X* :  a  S[        U5      S.$ SUS.$ [        U[        5      (       a  SUS.$ [        U[        R                  5      (       a5  SUR                  c  UR                  5       S-   S.$ UR                  5       S.$ [        U[        R                  5      (       ap  [        R                  R                  U[        R                  R                  5      R!                  [        R"                  R$                  S9nSUR                  5       S.$ [        U[&        5      (       a$  SU Vs/ s H  o@R)                  U5      PM     snS.$ [        U[*        [,        45      (       a$  SU Vs/ s H  o@R)                  U5      PM     snS.$ [        U[.        5      (       aH  SUR1                  5        VVs/ s H'  u  pVU R)                  U5      U R)                  U5      /PM)     snnS.$ S[        U5      S.$ s  snf s  snf s  snnf )z4
Converts a Python value to BiDi LocalValue format.
r-   nullboolean)r-   valuenumberNaNr   Infinityz	-Infinityg        g      ?z-0l    bigintstringdateZ)tzinfosetarrayobject)
isinstanceboolintfloatmathisnanisinfcopysignr:   datetimer   	isoformatr   combinetimeminreplacetimezoneutcr   r   listtupler=   items)rU   r   JS_MAX_SAFE_INTEGERdtitemkvs          r   __convert_to_local_valueScript.__convert_to_local_value:  s    =F##t$$%66U|,,%''::e$$$,u==ZZ&&qy(0:FF(0;GGc\dmmC&?!&C$,t<<"2%%%5+F%RfJf (3u:>>$u55s##$u55x0011"H\U__->-Dttbgbqbqbsttx}}--""**5(--2C2CDLLT\TeTeTiTiLjB"R\\^<<s##!]b,c]bUY-J-J4-P]b,cdde}--#_d.e_dW[/L/LT/R_d.efft$$ ejepeperer]a]^T2215t7T7TUV7WXer  %s5z:: -d.es   KK.K"r   r   contextsuser_contextsr/   c                     Ub  Ub  [        S5      eSU0nUb  X&S'   Ub  X6S'   Ub  XFS'   Ub  XVS'   U R                  R                  [        SU5      5      nUS   $ )	a  Adds a preload script.

Args:
    function_declaration: The function declaration to preload.
    arguments: The arguments to pass to the function.
    contexts: The browsing context IDs to apply the script to.
    user_contexts: The user context IDs to apply the script to.
    sandbox: The sandbox name to apply the script to.

Returns:
    str: The preload script ID.

Raises:
    ValueError: If both contexts and user_contexts are provided.
z.Cannot specify both contexts and user_contextsfunctionDeclarationr   r   userContextsr/   zscript.addPreloadScriptr   )r4   rv   r   r   )rU   r   r   r   r   r/   paramsrF   s           r   r   Script._add_preload_scriptm  s    . M$=MNN"79M!N "+;!):$%2>" '9""?3Lf#UVhr   c                 V    SU0nU R                   R                  [        SU5      5        g)zQRemoves a preload script.

Args:
    script_id: The preload script ID to remove.
r   zscript.removePreloadScriptNrv   r   r   )rU   r   r   s      r   r   Script._remove_preload_script  s(     I&		/*FOPr   handlesr   c                 X    UUS.nU R                   R                  [        SU5      5        g)zoDisowns the given handles.

Args:
    handles: The handles to disown.
    target: The target realm or context.
)r   r   zscript.disownNr   )rU   r   r   r   s       r   _disownScript._disown  s,     
 			//6BCr   r   result_ownershipserialization_optionsthisuser_activationc	                     UUUUS.n	Ub  XIS'   Ub  XYS'   Ub  XiS'   Ub  XyS'   U R                   R                  [        SU	5      5      n
[        R	                  U
5      $ )a,  Calls a provided function with given arguments in a given realm.

Args:
    function_declaration: The function declaration to call.
    await_promise: Whether to await promise resolution.
    target: The target realm or context.
    arguments: The arguments to pass to the function.
    result_ownership: The result ownership type.
    serialization_options: The serialization options.
    this: The 'this' value for the function call.
    user_activation: Whether to trigger user activation.

Returns:
    EvaluateResult: The result of the function call.
)r   awaitPromiser   userActivationr   resultOwnershipserializationOptionsr   zscript.callFunctionrv   r   r   rD   r8   )rU   r   r   r   r   r   r   r   r   r   rF   s              r   r   Script._call_function  s    6 $8)-	
  "+;'(8$% ,-B)*!6N""?3H&#QR''//r   
expressionc                     UUUUS.nUb  XGS'   Ub  XWS'   U R                   R                  [        SU5      5      n[        R	                  U5      $ )a  Evaluates a provided script in a given realm.

Args:
    expression: The script expression to evaluate.
    target: The target realm or context.
    await_promise: Whether to await promise resolution.
    result_ownership: The result ownership type.
    serialization_options: The serialization options.
    user_activation: Whether to trigger user activation.

Returns:
    EvaluateResult: The result of the script evaluation.
)r   r   r   r   r   r   zscript.evaluater   )	rU   r   r   r   r   r   r   r   rF   s	            r   	_evaluateScript._evaluate  sd    . %)-	
 '(8$% ,-B)*""?3Df#MN''//r   r.   r-   c                     0 nUb  XS'   Ub  X#S'   U R                   R                  [        SU5      5      nUS    Vs/ s H  n[        R	                  U5      PM     sn$ s  snf )zReturns a list of all realms, optionally filtered.

Args:
    context: The browsing context ID to filter by.
    type: The realm type to filter by.

Returns:
    List[RealmInfo]: A list of realm information.
r.   r-   zscript.getRealmsrealms)rv   r   r   r)   r8   )rU   r.   r-   r   rF   r+   s         r   _get_realmsScript._get_realms  sj      '9!6N""?3Ev#NO8>x8HI8Hu	##E*8HIIIs   Ac                     U R                   (       dU  [        U R                  5      nU R                  R                  UR	                  [
        R                  5      5        SU l         g g )NT)rx   r	   rv   r   	subscriber   rZ   rU   sessions     r   r    Script._subscribe_to_log_entries  sI    ((dii(GIIg//0I0IJK(,D% )r   c                 "   U R                   (       a~  [        R                  U R                  R                  ;  aU  [        U R                  5      nU R                  R                  UR                  [        R                  5      5        SU l         g g g ru   )rx   r   rZ   rv   rz   r	   r   unsubscriber   s     r   r   $Script._unsubscribe_from_log_entries  sd    $$)B)B$))J]J])]dii(GIIg11-2K2KLM(-D% *^$r   c                    ^^ UU4S jnU$ )Nc                 8   > U R                   T:X  a	  T" U 5        g g rS   )type_)	log_entryr   r-   s    r   r   3Script._handle_log_entry.<locals>._handle_log_entry"  s    $&	" 'r   r   )rU   r-   r   r   s    `` r   r   Script._handle_log_entry!  s    	# ! r   )rz   rv   rw   rx   ry   rS   )NNNN)NNNNF)NNF)NN)!r   r   r   r   r   EVENTSrV   r   r   r   remove_javascript_error_handlerr:   r   r   r=   r   r   r   r   r   r   r   r   r   rD   r   r   r)   r   r   r   r   r   r   r   r   ro   ro      sT   3 $.2Fad- 'E#	0# 	0# 	0/s /t /'4c '4T '4R0; 0;l 59(,-1!%& !&  Dc3h01&  49%	& 
  S	*&  #&  
& PQ Q QDtCy D$ D4 D$ +/*.04# %+0!+0 +0 	+0
 DJ'+0 #3-+0  (~+0 tn+0 +0 
+0d +/04 %#0#0 #0 	#0
 #3-#0  (~#0 #0 
#0N "&"J#J smJ 
i	J0-.!r   ro   )r   r   dataclassesr   typingr   r   selenium.common.exceptionsr   %selenium.webdriver.common.bidi.commonr   "selenium.webdriver.common.bidi.logr   &selenium.webdriver.common.bidi.sessionr	   r   r   r)   r?   rD   rL   r\   rf   ro   r   r   r   <module>r     s   $   !   9 A < : 
 
  
  
  
F 
 
 
2 
 
 
>
 
D9 9*( (0H! H!r   