
    X jH                     .   S SK r S SKrS SKJr  S SK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)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       v/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/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'   Sr\S-  \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clsr/   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.   classmethoddictr   r7   r   r   r   r   r(   r(   1   sX    /JK
IGS4ZGS4Z
T#s(^ 
 
 
r   r(   c                   ^    \ rS rSr% Sr\\S'   Sr\S-  \S'   \S\	\\
4   SS 4S j5       rS	rg)
SourceU   z*Represents the source of a script message.r*   Nr-   r/   r0   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-   r2   r5   s     r   r7   Source.from_json\   s8     $GHHw-HHY'
 	
r   r   )r   r   r   r   r   r9   r:   r-   r;   r<   r   r7   r   r   r   r   r>   r>   U   s@    4JGS4Z
T#s(^ 
 
 
r   r>   c                   |    \ rS rSr% Sr\\S'   \\S'   Sr\S-  \S'   Sr	\S-  \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_detailsr/   r0   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 EvaluateResultrE   exceptionDetails)r,   r*   rE   rF   r2   r5   s     r   r7   EvaluateResult.from_jsonx   s`     $OPPNOOfw-88H%"hh'9:	
 	
r   r   )r   r   r   r   r   r9   r:   rE   r<   rF   r;   r   r7   r   r   r   r   rC   rC   o   sU    5
IJFD4K%)td{)
T#s(^ 
0@ 
 
r   rC   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rN   rO   rP   )selfrN   rO   rP   s       r   __init__ScriptMessage.__init__   s    	r   r/   r0   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.
rN   z1Missing required field 'channel' in ScriptMessagerO   z.Missing required field 'data' in ScriptMessagerP   z0Missing required field 'source' in ScriptMessagerS   )r3   r>   r7   r5   s     r   r7   ScriptMessage.from_json   sm     D PQQMNN4OPPOf##DN3
 	
r   rS   N)r   r   r   r   r   event_classr9   r<   r>   rU   r;   r   r7   r   r   r   r   rK   rK      sN    ,"K 4  
 
T#s(^ 
 
 
r   rK   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 rR   r^   )rT   r^   s     r   rU   RealmCreated.__init__   s    $r   r/   r0   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.
r`   )r(   r7   r5   s     r   r7   RealmCreated.from_json   s     i11$788r   r`   N)r   r   r   r   r   rY   r(   rU   r;   r<   r9   r   r7   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 rR   r*   )rT   r*   s     r   rU   RealmDestroyed.__init__   s    
r   r/   r0   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 RealmDestroyedri   )r3   r5   s     r   r7   RealmDestroyed.from_json   s'     $OPPg''r   ri   N)r   r   r   r   r   rY   r9   rU   r;   r<   r   r7   r   r   r   r   re   re      sA    -)Kc  (T#s(^ (0@ ( (r   re   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\\   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-  S \S-  S!\S\4S" jjr   S/S#\S\S\S\S-  S\S-  S!\S\4S$ jjr  S0S%\S-  S&\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.rM   r]   rg   )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)rT   ru   rv   s      r   rU   Script.__init__   s#    	$)!r   c                     U R                  5         U R                  R                  [        U R	                  SU5      5      $ )Nconsole_subscribe_to_log_entriesru   add_callbackr   _handle_log_entryrT   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 rR   )ru   remove_callbackr   _unsubscribe_from_log_entries)rT   ids     r   remove_console_message_handler%Script.remove_console_message_handler   s"    		!!-4**,r   scriptr0   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)rT   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)rT   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: rp   )	rv   r   current_window_handleappend_Script__convert_to_local_value_call_functionr,   rE   rF   )	rT   r   argsbrowsing_context_idr   argr   rE   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 )z2Converts 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copysignr9   datetimer   	isoformatr   combinetimeminreplacetimezoneutcr   r   listtupler<   items)rT   r   JS_MAX_SAFE_INTEGERdtitemkvs          r   __convert_to_local_valueScript.__convert_to_local_value9  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   )r3   ru   r   r   )rT   r   r   r   r   r.   paramsrE   s           r   r   Script._add_preload_scriptj  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ru   r   r   )rT   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   )rT   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ru   r   r   rC   r7   )rT   r   r   r   r   r   r   r   r   r   rE   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   )	rT   r   r   r   r   r   r   r   rE   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)ru   r   r   r(   r7   )rT   r-   r,   r   rE   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)rw   r   ru   r   	subscriber   rY   rT   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 rt   )rw   r   rY   ru   ry   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 rR   )type_)	log_entryr   r,   s    r   r   3Script._handle_log_entry.<locals>._handle_log_entry  s    $&	" 'r   r   )rT   r,   r   r   s    `` r   r   Script._handle_log_entry  s    	# ! r   )ry   ru   rv   rw   rx   rR   )NNNN)NNNNF)NNF)NN) r   r   r   r   r   EVENTSrU   r   r   r   remove_javascript_error_handlerr9   r   r   r<   r   r   r   r   r   r   r   r   rC   r   r   r(   r   r~   r   r   r   r   r   r   rn   rn      sT   3 $.2Fad- 'E#	0# 	0# 	0/s /t /&4c &4T &4P.; .;h 26%)*."& !&  S#X'$.&  s)d"	& 
 Cy4'&  t&  
& PQ Q QDtCy D$ D4 D$ (,'+-1  %+0!+0 +0 	+0
 :$+0 *+0  $d{+0 Tk+0 +0 
+0d (,-1 %#0#0 #0 	#0
 *#0  $d{#0 #0 
#0N #JtJ DjJ 
i	J0-.!r   rn   )r   r   dataclassesr   typingr   selenium.common.exceptionsr   %selenium.webdriver.common.bidi.commonr   "selenium.webdriver.common.bidi.logr   &selenium.webdriver.common.bidi.sessionr   r
   r   r(   r>   rC   rK   r[   re   rn   r   r   r   <module>r
     s   $   !  9 A < : 
 
  
  
  
F 
 
 
2 
 
 
>
 
D9 9*( (0E! E!r   