
    ii                        S r SSKJr  SSKrSSKr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KJr  SSKJr  SSKJr   " S S\R(                  5      r " S S5      r\rSS jrSS jrSS jrg)zhGateway code for initiating popen, socket and ssh connections.

(c) 2004-2013, Holger Krekel and others
    )annotationsN)TYPE_CHECKING)Any)Callable   )gateway_base)IO)Channel)Message)Group)XSpecc                     ^  \ rS rSr% SrS\S'   SU 4S jjr\SS j5       rSS jr	SS jr
 S     SS	 jjrSSS
 jjrSS jrSS jr      SS jrSSS jjrSrU =r$ )Gateway   z0Gateway to a local or remote Python Interpreter.r   _groupc                b   > [         TU ]  XR                  SS9  X l        U R	                  5         g)z	:private:r   )ioid_startcountN)super__init__r   spec_initreceive)selfr   r   	__class__s      N/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/execnet/gateway.pyr   Gateway.__init__   s*    B77:	    c                .    U R                   R                  $ N)_ioremoteaddressr   s    r   r"   Gateway.remoteaddress#   s     xx%%%r   c                R    U R                  5       =(       a    S=(       d    Sn[        [        U R                  R	                  5       5      5      nSU R                  R                   SU R                  < SU SU R                  R                   S	U S
3$ ! [
         a    SnSn NUf = f)z.A string representing gateway type and status.zreceive-liveznot-receivinguninitializedno<z id= , z model, z active channels>)hasreceiverstrlen_channelfactorychannelsAttributeErrorr   __name__r   	execmodelbackend)r   ris      r   __repr__Gateway.__repr__(   s    	&&(;^OAC,,55789A 4>>**+4{!A3bAWAW@XX`ab`cctuu  	AA	s   AB B&%B&c                   U R                  S5        X R                  ;  a  U R                  S5        gU R                  R                  U 5         U R                  S5        U R                  [        R
                  5        U R                  S5        U R                  R                  5         g! [        [        [        4 a/  nU R                  S5        U R                  SU-  5         SnAgSnAff = f)zTrigger gateway exit.

Defer waiting for finishing of receiver-thread and subprocess activity
to when group.terminate() is called.
zgateway.exit() calledz'gateway already unregistered with groupNz--> sending GATEWAY_TERMINATEz--> io.close_writez-io-error: could not send termination sequencez exception: %r)_tracer   _unregister_sendr   GATEWAY_TERMINATEr!   close_write
ValueErrorEOFErrorOSError)r   excs     r   exitGateway.exit2   s     	+,{{"KKAB%	0KK78JJw001KK,-HH  "Hg. 	0KKGHKK(3.//	0s   AB+ +C/ %C**C/c                    X4U l         [        R                  " U R                   5      nU R                  [        R
                  US9  g)zSet the string coercion for this gateway.

The default is to try to convert py2 str as py3 str, but not to try and
convert py3 str to py2 str.
)dataN)
_strconfigr   dumps_internalr;   r   RECONFIGURE)r   py2str_as_py3strpy3str_as_py2strrE   s       r   reconfigureGateway.reconfigureF   s8     ,>**4??;

7&&T
2r   c                   U(       d  [        U S5      (       dP  U R                  [        5      n [        UR	                  5       5      U l        UR                  5         U R
                  $ U R
                  $ ! UR                  5         f = f)z,Return some sys/env information from remote._cache_rinfo)hasattrremote_execrinfo_sourceRInforeceiverN   	waitclose)r   updatechs      r   _rinfoGateway._rinfoR   sf    ~66!!,/B$)"**,$7!   t    s   A5 5Bc                <    U R                   R                  5       S:  $ )z(Whether gateway is able to receive data.r   )_receivepoolactive_countr#   s    r   r+   Gateway.hasreceiver\   s      --/!33r   c                    U R                  5       nU R                  [        R                  UR                  5        UR                  5       nU R                  R                  UR                  5        [        U5      $ )z5Obtain information about the remote execution status.)	
newchannelr;   r   STATUSr   rS   r.   _local_closeRemoteStatus)r   channel
statusdicts      r   remote_statusGateway.remote_status`   sU    //#

7>>7::.__&
 	))'**5J''r   c           
     ~   SnSn[        U[        R                  5      (       aC  [        R                  " U5      n[
        R                  " U5        [        R                  " U5      nOl[        U[        R                  5      (       a.  UR                  n[        R                  " U5      n[        U5      nO[        R                  " [        U5      5      nU(       d  U(       a  [        S5      eU R                  5       nU R!                  ["        R$                  UR&                  [(        R*                  " XX245      5        U$ )aO  Return channel object and connect it to a remote
execution thread where the given ``source`` executes.

* ``source`` is a string: execute source string remotely
  with a ``channel`` put into the global namespace.
* ``source`` is a pure function: serialize source and
  call function with ``**kwargs``, adding a
  ``channel`` object to the keyword arguments.
* ``source`` is a pure module: execute source of module
  with a ``channel`` in its global namespace.

In all cases the binding ``__name__='__channelexec__'``
will be available in the global namespace of the remotely
executing code.
Nz-can't pass kwargs to non-function remote_exec)
isinstancetypes
ModuleTypeinspectgetsourcefile	linecacheupdatecache	getsourceFunctionTyper1   _source_of_functiontextwrapdedentr,   	TypeErrorr^   r;   r   CHANNEL_EXECr   r   rG   )r   sourcekwargs	call_name	file_namerb   s         r   rP   Gateway.remote_execj   s    ( 		fe..//--f5I!!),&&v.F 2 233I--f5I(0F__S[1FVKLL//#

  JJ''I(NO	

 r   c                    [        S5        g)z1DEPRECATED.  Is currently a NO-OPERATION already.z?WARNING: remote_init_threads() is a no-operation in execnet-1.2N)print)r   nums     r   remote_init_threadsGateway.remote_init_threads   s    OPr   )rN   rF   r   )r   r	   r   r   returnNoner   r,   r   r   )TF)rI   boolrJ   r   r   r   )F)rU   r   r   rR   )r   r   )r   ra   )ru   zCstr | types.FunctionType | Callable[..., object] | types.ModuleTyperv   objectr   r
   r    )r|   z
int | Noner   r   )r1   
__module____qualname____firstlineno____doc____annotations__r   propertyr"   r6   rB   rK   rW   r+   rd   rP   r}   __static_attributes____classcell__)r   s   @r   r   r      s    :M & &v0* GL
3 $
3?C
3	
3!4(*S* * 
	*XQ Qr   r   c                  F    \ rS rSrSS jrSS jr\(       a  S	S jrSrgSrg)
rR      c                :    U R                   R                  U5        g r    )__dict__rU   )r   rv   s     r   r   RInfo.__init__   s    V$r   c                ~    SR                  S [        U R                  R                  5       5       5       5      nSU-  $ )Nr*   c              3  4   #    U  H  u  pU S U 3v   M     g7f)=N ).0kvs      r   	<genexpr>!RInfo.__repr__.<locals>.<genexpr>   s     N0MA3as0Ms   z
<RInfo %r>)joinsortedr   items)r   infos     r   r6   RInfo.__repr__   s3    yyNt}}7J7J7L0MNNd""r   c                    g r    r   )r   names     r   __getattr__RInfo.__getattr__   s    r   r   Nr   r   )r   r,   r   r   )	r1   r   r   r   r   r6   r   r   r   r   r   r   rR   rR      s    %# 4 r   rR   c           
         SS K nSS KnU R                  [        UR                  UR
                  S S UR                  UR                  5       UR                  5       S95        g )Nr      )
executableversion_infoplatformcwdpid)	ossyssenddictr   r   r   getcwdgetpid)rb   r   r   s      r   rQ   rQ      sL    LL~~))"1-\\					
r   c                d   SS K nSS Kn[        R                  UR                  5      nUR                  UR                  U 5      5       Vs/ s HY  n[        XRR                  5      (       d  M  UR                  U;  d  M1  UR                  UR                  ;  d  MM  UR                  PM[     sn$ s  snf )Nr   )astbuiltinsr   fromkeysco_varnameswalkparserg   Namer   r   )ru   codeobjr   r   varsnodes         r   _find_non_builtin_globalsr      s    ==,,-D HHSYYv.//DdHH% 	 GG4 	 GG8,,,	 	/  s   
B-,B->B-B-c                V   U R                   S:X  a  [        S5      e [        R                  " U 5      nUR                  nU(       a	  US   S:w  a  [        S5      eU R                  nU R                  nUb  [        S5      e [        R                  " U 5      n[        R                  " U5      n[        XT5      nU(       a  [        SU5      eS	UR                  S
-
  -  nX-   $ ! [
         a    [        R                  " U 5      S   n Nf = f! [         a  n[        SU -  5      UeS nAff = f)Nz<lambda>z can't evaluate lambda functions'r   rb   z0expected first function argument to be `channel`z'functions with closures can't be passedzcan't find source file for %sz.the use of non-builtin globals isn't supported
r   )r1   r>   rj   getfullargspecargsr0   
getargspec__closure____code__rn   r@   rq   rr   r   co_firstlineno)	functionsigr   closurer   ru   eused_globals
leading_wss	            r   rp   rp      s)   J&;<<$$X. xx47i'KLL""GGBCCL""8, __V$F,V=LI<XX//!34J3  /!!(+A./  L88CD!KLs)   C! D
 !#DD

D(D##D(r   )ru   r,   r   ztypes.CodeTyper   z	list[str])r   z*types.FunctionType | Callable[..., object]r   r,   )r   
__future__r   rj   rl   rq   rh   typingr   r   r    r   r	   r
   r   multir   xspecr   BaseGatewayr   rR   ra   rQ   r   rp   r   r   r   <module>r      sm   
 #           ! !  @Ql&& @QF
5 
5  r   