+
    Ĝi6                    |   ^ RI Ht ^ RIt^ RIt^ RIHtHtHtHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHtHtHt ^ RIHtHtHt ^ R	IHtHt ^ R
IHtHt ^ RIHt ^ RIHt ]'       d%   ^ RI H!t!H"t" ^ RI#H$t$ ^ RI%H&t& ^ RI'H(t(H)t)H*t* ^ RI+H,t,  ! R R4      t-]RR R ll4       t.]RR R ll4       t/]RR R ll4       t0]-t1R# )    )annotationsN)AbstractContextManagerasynccontextmanagercontextmanagersuppress)count)JSONEncoder)Thread)TYPE_CHECKINGAnyClassVar)ContextContextTypeget_running_loop_or_none)init_mini_racermr_callback_func)JSTimeoutExceptionWrongReturnTypeException)ObjectFactoryImpl)INSTALL_SET_TIMEOUT)AsyncGenerator	Generator)TracebackType)Self)
JSFunctionPyJsFunctionTypePythonJSConvertedTypes)RawValueHandleTypec                  :   ] tR t^$t$ Rt]tR]R&   R.R R lltR/R R llt	R	 R
 lt
R R ltR R lt]R R l4       tR/R R lltR R ltR/R R lltRRRRRRRR/R R llt]R R l4       tR R  ltR! R" ltR# R$ ltR% R& ltR' R( ltR) R* ltR+ R, ltR-tR# )0	MiniRacera  
MiniRacer evaluates JavaScript code using a V8 isolate.

A MiniRacer instance can be explicitly closed using the close() method, or by using
the MiniRacer as a context manager, i.e,:

with MiniRacer() as mr:
    ...

The MiniRacer instance will otherwise clean up the underlying V8 resources upon
garbage collection.

Attributes:
    json_impl: JSON module used by helper methods default is
        [json](https://docs.python.org/3/library/json.html)
zClassVar[Any]	json_implNc                    V ^8  d   QhRRRR/# )   contextzContext | NonereturnNone )formats   "b/Users/mibo/.openclaw/workspace/.venv-ak/lib/python3.14/site-packages/py_mini_racer/_mini_racer.py__annotate__MiniRacer.__annotate__8   s     
' 
' 
'$ 
'    c                	    Vf0   \        4       V n        V P                  P                  4       V n        MR V n        Wn        V P	                  \
        4       R # N)_make_context_own_context_maker	__enter___ctxevalr   )selfr$   s   &&r)   __init__MiniRacer.__init__8   sF    ? # )-(?(?(I(I(KDI&*D#I		%&r,   c               (    V ^8  d   QhRRRRRRRR/# 	r#   exc_typeztype[BaseException] | Noneexc_valzBaseException | Noneexc_tbzTracebackType | Noner%   r&   r'   )r(   s   "r)   r*   r+   D   s8     B B,B &B %	B
 
Br,   c                j    V P                   pRV n         RV n        Ve   VP                  WV4       R# R# )zClose this MiniRacer instance.

It is an error to use this MiniRacer instance or any JS objects returned by it
after calling this method.
N)r0   r2   __exit__)r4   r9   r:   r;   own_context_makers   &&&& r)   closeMiniRacer.closeD   s:     !33"&	(&&x&A )r,   c                   V ^8  d   QhRR/# r#   r%   r&   r'   )r(   s   "r)   r*   r+   V   s       r,   c                	    \        \        4      ;_uu_ 4        V P                  4        R R R 4       R #   + '       g   i     R # ; ir.   )r   	Exceptionr?   r4   s   &r)   __del__MiniRacer.__del__V   s'     i  JJL !   s	   3A	c                   V ^8  d   QhRR/# )r#   r%   r   r'   )r(   s   "r)   r*   r+   ]   s      4 r,   c                	    V # r.   r'   rE   s   &r)   r1   MiniRacer.__enter__]   s    r,   c               (    V ^8  d   QhRRRRRRRR/# r8   r'   )r(   s   "r)   r*   r+   `   s2     . .,. &. %	.
 
.r,   c                	*    V P                  WV4       R # r.   )r?   )r4   r9   r:   r;   s   &&&&r)   r=   MiniRacer.__exit__`   s     	

8f-r,   c                   V ^8  d   QhRR/# )r#   r%   strr'   )r(   s   "r)   r*   r+   i   s     & &C &r,   c                V    V P                   f   Q hV P                   P                  4       # )zReturn the V8 version string.)r2   
v8_versionrE   s   &r)   rQ   MiniRacer.v8_versionh   s'     yy$$$yy##%%r,   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r#   coderO   timeoutfloat | Nonetimeout_sec
max_memory
int | Noner%   r   r'   )r(   s   "r)   r*   r+   n   s<     < << < "	<
 < 
 <r,   c                Z  aaa Ve   V P                  V4       V'       d
   VR,          oV P                  oSf   Q hSP                  4       '       g@   R VVV3R llp\        P                  ! V! 4       SP
                  4      P                  4       # Se   Q R4       hSP                  S4      # )a  Evaluate JavaScript code in the V8 isolate.

Side effects from the JavaScript evaluation is persisted inside a context
(meaning variables set are kept for the next evaluation).

The JavaScript value returned by the last expression in `code` is converted to
a Python value and returned by this method. Only primitive types are supported
(numbers, strings, buffers...). Use the
[py_mini_racer.MiniRacer.execute][] method to return more complex
types such as arrays or objects.

The evaluation can be interrupted by an exception for several reasons: a limit
was reached, the code could not be parsed, a returned value could not be
converted to a Python value.

Args:
    code: JavaScript code
    timeout: number of milliseconds after which the execution is interrupted.
        This is deprecated; use timeout_sec instead.
    timeout_sec: number of seconds after which the execution is interrupted
    max_memory: hard memory limit, in bytes, after which the execution is
        interrupted.
  c                   V ^8  d   QhRR/# )r#   r%   r   r'   )r(   s   "r)   r*   $MiniRacer.eval.<locals>.__annotate__   s     4 45 4r,   c                    <"    \         P                  ! SP                  S4      SR 7      G Rj  xL
 #  L  \         P                   d   p \        T hRp ? ii ; i5i))rU   N)asynciowait_foreval_cancelableTimeoutErrorr   )erT   ctxrW   s    r)   runMiniRacer.eval.<locals>.run   sW     4!(!1!1++D1;"    ++ 4,!34s1   A*6 46 A6 AAAAz{To apply a timeout in an async context, use `await asyncio.wait_for(mr.eval_cancelable(your_params), timeout=your_timeout)`)set_hard_memory_limitr2   +are_we_running_on_the_mini_racer_event_loopr_   run_coroutine_threadsafe
event_loopresultr3   )r4   rT   rU   rW   rX   re   rd   s   &f&f& @r)   r3   MiniRacer.evaln   s    > !&&z2 "D.Kii>>@@4 4 33CE3>>JQQSS" 	
%	
" xx~r,   c                    V ^8  d   QhRRRR/# )r#   rT   rO   r%   r   r'   )r(   s   "r)   r*   r+      s     5 5# 52H 5r,   c                t   "   V P                   f   Q hV P                   P                  V4      G Rj  xL
 #  L5i)zEvaluate JavaScript code in the V8 isolate.

Similar to eval(), but runaway calls can be canceled by canceling the
coroutine's task, e.g., using:

    await asyncio.wait_for(mr.eval_cancelable(...), timeout=some_timeout)

N)r2   ra   )r4   rT   s   &&r)   ra   MiniRacer.eval_cancelable   s2      yy$$$YY..t4444s   /868c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r#   exprrO   rU   rV   rW   rX   rY   r%   r   r'   )r(   s   "r)   r*   r+      s<     ) )) ) "	)
 ) 
)r,   c                    V'       d
   VR,          pRV R2pV P                  WSVR7      p\        V\        4      '       g   \        \	        V4      4      hV P
                  P                  V4      # )a  Helper to evaluate a JavaScript expression and return composite types.

Returned value is serialized to JSON inside the V8 isolate and deserialized
using `json_impl`.

Args:
    expr: JavaScript expression
    timeout: number of milliseconds after which the execution is interrupted.
        This is deprecated; use timeout_sec instead.
    timeout_sec: number of seconds after which the execution is interrupted
    max_memory: hard memory limit, in bytes, after which the execution is
        interrupted.
r[   z#JSON.stringify((function(){return (z)})())rW   rX   )r3   
isinstancerO   r   typer!   loads)r4   rq   rU   rW   rX   wrapped_exprrets   &&&&&  r)   executeMiniRacer.execute   sc    *  "D.K=dV7Kii*iU#s##*4955~~##C((r,   encoderrU   rW   rX   c               4    V ^8  d   QhRRRRRRRRR	RR
RRR/# )r#   rq   rO   argsr   r{   ztype[JSONEncoder] | NonerU   rV   rW   rX   rY   r%   r'   )r(   s   "r)   r*   r+      sY     #P #P#P #P *	#P
 #P "#P #P 
#Pr,   c                   V'       d
   VR,          pV P                   P                  VRVR7      pV RV R2pV P                  WVR7      # )a  Helper to call a JavaScript function and return compositve types.

The `expr` argument refers to a JavaScript function in the current V8
isolate context. Further positional arguments are serialized using the JSON
implementation `json_impl` and passed to the JavaScript function as arguments.

Returned value is serialized to JSON inside the V8 isolate and deserialized
using `json_impl`.

Args:
    expr: JavaScript expression referring to a function
    encoder: Custom JSON encoder
    timeout: number of milliseconds after which the execution is
        interrupted.
    timeout_sec: number of seconds after which the execution is interrupted
    max_memory: hard memory limit, in bytes, after which the execution is
        interrupted
r[   )
separatorsclsz.apply(this, )rs   ),:)r!   dumpsry   )	r4   rq   r{   rU   rW   rX   r}   	json_argsjss	   &&$$$$*  r)   callMiniRacer.call   sR    8  "D.KNN((*'(R	v]9+Q/||BJ|OOr,   c                    V ^8  d   QhRRRR/# )r#   funcr   r%   z AsyncGenerator[JSFunction, None]r'   )r(   s   "r)   r*   r+      s      $	)r,   c                  "   V P                   f   Q hV P                   P                  V4      ;_uu_4       GRj  xL
 pV5x  RRR4      GRj  xL
  R#  L L  + GRj  xL 
 '       g   i     R# ; i5i)aF  Wrap a Python function such that it can be called from JS.

To be wrapped and exposed in JavaScript, a Python function should:

  1. Be async,
  2. Accept variable positional arguments each of type PythonJSConvertedTypes,
     and
  3. Return one value of type PythonJSConvertedTypes (a type union which
     includes None).

The function is rendered on the JavaScript side as an async function (i.e., a
function which returns a Promise).

Returns:
    An async context manager which, when entered, yields a JS Function which
    can be passed into MiniRacer and called by JS code.
N)r2   wrap_py_function_as_js_function)r4   r   js_funcs   && r)   wrap_py_functionMiniRacer.wrap_py_function   sK     , yy$$$99<<TBBBgM CBBBBBsJ   8A7AA7AA7AA7A7A4	 A#!
A4	,A4	.	A7c                    V ^8  d   QhRRRR/# r#   limitintr%   r&   r'   )r(   s   "r)   r*   r+     s     	/ 	/3 	/4 	/r,   c                \    V P                   f   Q hV P                   P                  V4       R# )zSet a hard memory limit on this V8 isolate.

JavaScript execution will be terminated when this limit is reached.

:param int limit: memory limit in bytes or 0 to reset the limit
N)r2   rg   r4   r   s   &&r)   rg   MiniRacer.set_hard_memory_limit  s&     yy$$$		''.r,   c                    V ^8  d   QhRRRR/# r   r'   )r(   s   "r)   r*   r+   %  s     
/ 
/3 
/4 
/r,   c                \    V P                   f   Q hV P                   P                  V4       R# )zSet a soft memory limit on this V8 isolate.

The Garbage Collection will use a more aggressive strategy when
the soft limit is reached but the execution will not be stopped.

:param int limit: memory limit in bytes or 0 to reset the limit
N)r2   set_soft_memory_limitr   s   &&r)   r   MiniRacer.set_soft_memory_limit%  s&     yy$$$		''.r,   c                   V ^8  d   QhRR/# r#   r%   boolr'   )r(   s   "r)   r*   r+   1       9 9t 9r,   c                V    V P                   f   Q hV P                   P                  4       # )zCReturn true if the hard memory limit was reached on the V8 isolate.)r2   was_hard_memory_limit_reachedrE   s   &r)   r   'MiniRacer.was_hard_memory_limit_reached1  '     yy$$$yy6688r,   c                   V ^8  d   QhRR/# r   r'   )r(   s   "r)   r*   r+   7  r   r,   c                V    V P                   f   Q hV P                   P                  4       # )zCReturn true if the soft memory limit was reached on the V8 isolate.)r2   was_soft_memory_limit_reachedrE   s   &r)   r   'MiniRacer.was_soft_memory_limit_reached7  r   r,   c                   V ^8  d   QhRR/# rB   r'   )r(   s   "r)   r*   r+   =  s     , , ,r,   c                Z    V P                   f   Q hV P                   P                  4        R# )z7Ask the V8 isolate to collect memory more aggressively.N)r2   low_memory_notificationrE   s   &r)   r   !MiniRacer.low_memory_notification=  s$     yy$$$		))+r,   c                   V ^8  d   QhRR/# r#   r%   r   r'   )r(   s   "r)   r*   r+   C  s     < <C <r,   c                    V P                   f   Q hV P                  P                  V P                   P                  4       4      # )z&Return the V8 isolate heap statistics.)r2   r!   rv   
heap_statsrE   s   &r)   r   MiniRacer.heap_statsC  s6     yy$$$~~##DII$8$8$:;;r,   c                   V ^8  d   QhRR/# r   r'   )r(   s   "r)   r*   r+   I  s     ? ?s ?r,   c                    V P                   f   Q hV P                  P                  V P                   P                  4       4      # )z)Return a snapshot of the V8 isolate heap.)r2   r!   rv   heap_snapshotrE   s   &r)   r   MiniRacer.heap_snapshotI  s6     yy$$$~~##DII$;$;$=>>r,   )r2   r0   r.   )NNN)__name__
__module____qualname____firstlineno____doc__jsonr!   __annotations__r5   r?   rF   r1   r=   propertyrQ   r3   ra   ry   r   r   r   rg   r   r   r   r   r   r   __static_attributes__r'   r,   r)   r    r    $   s    "  $I}#
'B$. & &
<|5)@#P -1	#P
 !%#P %)#P "&#PJ  4	/
/99,<? ?r,   r    c                    V ^8  d   QhRRRR/# )r#   rj    asyncio.AbstractEventLoop | Noner%   z0Generator[asyncio.AbstractEventLoop, None, None]r'   )r(   s   "r)   r*   r*   Q  s     ! !0!5!r,   c              #    a "   S ;'       g    \        4       o S e   S x  R# \        P                  ! 4       o R V 3R llp\        VRR7      pVP	                  4         S x  S P                  S P                  4       VP                  4        R#   S P                  S P                  4       TP                  4        i ; i5i)zPick an asyncio loop. In descending order of precedence:

1. The caller-specified one,
2. The running one (defined if we're being called from async context), or
3. One we create and launch a thread for, on the spot.
Nc                   V ^8  d   QhRR/# rB   r'   )r(   s   "r)   r*   )_running_event_loop.<locals>.__annotate__c  s      D r,   c                    < \         P                  ! S 4       S f   Q hS P                  4        S P                  4        R # r.   )r_   set_event_looprun_foreverr?   )rj   s   r)   run_event_loop+_running_event_loop.<locals>.run_event_loopc  s5    z*%%% r,   T)targetdaemon)r   r_   new_event_loopr
   startcall_soon_threadsafestopjoin)rj   r   event_loop_threads   f  r)   _running_event_loopr   P  s      9979J'')J  nTB!''
8  	''
8 s   AB?B "-B?-B<<B?c                    V ^8  d   QhRRRR/# )r#   rj   r   r%   zGenerator[Context, None, None]r'   )r(   s   "r)   r*   r*   t  s     ! !0!#!r,   c           	   #    a"   \        R R7      p\        R V3R ll4       p\        4       p\        V4      p\	        VP                  V4      4      p \        V 4      ;_uu_ 4       p\        WV\        4       V4      oSx  RRR4       VP                  V4       R#   + '       g   i     L#; i  TP                  T4       i ; i5i)T)ignore_duplicate_initc               $    V ^8  d   QhRRRRRR/# )r#   callback_idr   raw_val_handler   r%   r&   r'   )r(   s   "r)   r*   #_make_context.<locals>.__annotate__}  s'     E E E6H ET Er,   c                *   < SP                  W4       R # r.   )handle_callback_from_v8)r   r   r$   s   &&r)   mr_callback"_make_context.<locals>.mr_callback|  s     	''Dr,   N)
r   r   r   nextr   mr_init_contextr   r   r   mr_free_context)rj   dllr    next_cancelable_task_callback_id_rd   loopr$   s   &      @r)   r/   r/   s  s      
5C
 E E (-w$ 	-.A
c))+6
7C! ,,$ 1 35UG M	 - 	C  -, 	C s6   ACB. %B B. CB+	&B. .CCc                    V ^8  d   QhRRRR/# )r#   rj   r   r%   zGenerator[MiniRacer, None]r'   )r(   s   "r)   r*   r*     s      0r,   c              #     "   \        V 4      ;_uu_ 4       p\        V4      x  R R R 4       R #   + '       g   i     R # ; i5ir.   )r/   r    )rj   rd   s   & r)   
mini_racerr     s,      
z	"	"cn 
#	"	"	"s   A.
A?		Ar.   )2
__future__r   r_   r   
contextlibr   r   r   r   	itertoolsr   r	   	threadingr
   typingr   r   r   py_mini_racer._contextr   r   r   py_mini_racer._dllr   r   py_mini_racer._excr   r   py_mini_racer._objectsr   py_mini_racer._set_timeoutr   collections.abcr   r   typesr   typing_extensionsr   py_mini_racer._typesr   r   r   py_mini_racer._value_handler   r    r   r/   r   StrictMiniRacerr'   r,   r)   <module>r      s    "       / / Q Q @ K 4 :9#& 
 ?i? i?X	 ! !D ! !:   r,   