+
    i&  c                   s    ^ RI t ^ RIt^ RIt^ RIHtHtHt ^RIHtH	t	 ^RI
HtHtHt ]P                  ! ]4      t ! R R4      t ! R R4      t ! R	 R
]4      t ! R R4      t ! R R]4      tR# )i    N)DictListOptional)
JsonObject	JsonValue)CockpitProblemCockpitProtocolErrorCockpitProtocolServerc                   sB   a  ] tR t^t o RtR tR tV 3R lR ltRtV t	R# )ExecutionQueuea_  Temporarily delay calls to a given set of class methods.

Functions by replacing the named function at the instance __dict__
level, effectively providing an override for exactly one instance
of `method`'s object.
Queues the invocations.  Run them later with .run(), which also reverses
the redirection by deleting the named methods from the instance.
c                s    \         P                  ! 4       V n        Wn        V P                   F  pV P	                  V4       K  	  R # N)collectionsZdequequeuemethods_wrap)selfr   method   && 3/usr/lib/python3.14/site-packages/cockpit/router.py__init__ZExecutionQueue.__init__   s1     &&(
llFJJv #    c                sj   a a \        SP                  SP                  P                  VV 3R  l4       R# )c                  s>   < SP                   P                  SV 34      # r	   )r   Zappend)argsr   r   s   *r   Z<lambda>Z&ExecutionQueue._wrap.<locals>.<lambda>%   s    IZIZ\bdh[iIjr   N)Zsetattr__self____func____name__)r   r   s   ffr   r   ZExecutionQueue._wrap!   s      	!9!9;jkr   c                   < V ^8  d   QhRR/#    returnN Zformat__classdict__   "r   __annotate__ZExecutionQueue.__annotate__'   s     ? ?T ?r   c                s   \         P                  R \        V P                  4      4       V P                   F  w  rV! V!   K  	  V P                   F-  p\        VP                  VP                  P                  4       K/  	  R# )z.ExecutionQueue: Running %d queued method callsN)	loggerdebuglenr   r   Zdelattrr   r   r   )r   r   r      &  r   runZExecutionQueue.run'   sX    Es4::W JJLFDM ' llFFOOV__%=%=> #r   )r   r   N)
r   
__module____qualname____firstlineno__Z__doc__r   r   r%   __static_attributes____classdictcell__r      @r   r   r      s     l? ?r   r   c                   s   a  ] tR t^0t o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltRV 3R lR lltV 3R ltRtV tR# )EndpointNc                r   r   routerRouterr   r   r   r   r    Endpoint.__annotate__4   s      x r   c                s4    VP                  V 4       Wn        R # r	   )add_endpointr/   r   r/      &&r   r   ZEndpoint.__init__4   s    D!r   c                r   r   r   r   r   r   r    r1   8   s     u u ur   c                s    \         P                  R V 4       \        V P                  V P                  V P
                  04      V n        R# )zFreezing endpoint %sN)r!   r"   r   do_channel_controldo_channel_datado_kill _Endpoint__endpoint_frozen_queuer      &r   freeze_endpointZEndpoint.freeze_endpoint8   s9    +T2'5t7N7NPTPdPdfjfrfr6s't$r   c                r   r   r   r   r   r   r    r1   =   s     , ,t ,r   c                st    \         P                  R V 4       V P                  P                  4        RV n        R# )zThawing endpoint %sN)r!   r"   r8   r%   r9   r:   r   thaw_endpointZEndpoint.thaw_endpoint=   s+    *D1$$((*'+$r   c                r   r   r   r   r   r   r    r1   D        " "$ "r   c                    \         hr	   ZNotImplementedErrorr9   r:   r   do_closeZEndpoint.do_closeD       !!r   c                0   < V ^8  d   QhRS[ RS[ RS[RR/# r   channelcommandmessager   Nstrr   r   r   r   r    r1   G   s*     " "# " "j "UY "r   c                r>   r	   r?   )r   rD   rE   rF      &&&&r   r5   ZEndpoint.do_channel_controlG   rA   r   c                *   < V ^8  d   QhRS[ RS[RR/# r   rD   datar   NrH   Zbytesr   r   r   r    r1   J   s"     " "s "% "D "r   c                r>   r	   r?   r   rD   rL      &&&r   r6   ZEndpoint.do_channel_dataJ   rA   r   c                ,   < V ^8  d   QhRRRRRS[ RR/# r   hostz
str | NonegrouprF   r   Nr   r   r   r   r    r1   M   s*     " "L " "
 "W[ "r   c                r>   r	   r?   )r   rR   rS   rF   rI   r   r7   ZEndpoint.do_killM   rA   r   c                rJ   rK   rM   r   r   r   r    r1   Q   s"     6 6 6E 6d 6r   c                s<    V P                   P                  W4       R # r	   )r/   Zwrite_channel_datarN   rO   r   send_channel_dataZEndpoint.send_channel_dataQ   s    &&w5r   c          
      s4   < V ^8  d   QhRS[ RS[ RRRS[RR/# )r   rD   rE   msgJsonObject | Nonekwargsr   N)rH   r   r   r   r   r    r1   T   s5     . ..%(./B.NW.	.r   c                s    V P                   P                  ! V3R VRV/VB  VR8X  dJ   V P                   P                  V ,          P                  V4       V P                   P	                  V4       R# R# )rD   rE   closeN)r/   write_control	endpointsZremovedrop_channel)r   rD   rE   rV   rX   s   &&&&,r   send_channel_controlZEndpoint.send_channel_controlT   sa     	!!#RwRR6RgKK!!$'..w7KK$$W- r   c                s(   < V ^8  d   QhRRRS[ RR/# )r   rV   rW   rX   r   N)r   r   r   r   r    r1   \   s$     ; ;%8 ;9 ;Y] ;r   c                s@    V P                   P                  ! W3/ VB  R # r	   )r/   shutdown_endpoint)r   rV   rX   s   &&,r   r^   ZEndpoint.shutdown_endpoint\   s    %%d:6:r   c                s@   < V ^8  d   Qh/ R;R&   S[ S[,          ;R&   # )r   r0   r/   r8   )r   r   r   r   r   r    r1   0   s       %n5< r   )Z__endpoint_frozen_queuer/   r	   )r   r&   r'   r(   r8   r   r;   r<   r@   r5   r6   r7   rU   r]   r^   __annotate_func__r)   r*   r+   r,   r   r-   r-   0   sy     8< u u
, ," "" "" "" "6 6. .; ;Y  r   r-   c                   s    ] tR t^`tRtR# )RoutingErrorr   N)r   r&   r'   r(   r)   r   r   r   r`   r`   `   s    r   r`   c                   sb   a  ] tR t^dt o V 3R lR ltV 3R lR ltV 3R lR ltV 3R ltRtV t	R	# )
RoutingRulec                r   r.   r   r   r   r   r    RoutingRule.__annotate__g   s      x r   c                s    Wn         R # r	   r/   r3   r4   r   r   ZRoutingRule.__init__g   s    r   c                s6   < V ^8  d   QhRS[ RS[S[,          /# r   optionsr   )r   r   r-   r   r   r   r    rb   j   s      	" 	"* 	"(1C 	"r   c                r>   )a5  Check if a routing rule applies to a given 'open' message.

This should inspect the options dictionary and do one of the following three things:

    - return an Endpoint to handle this channel
    - raise a RoutingError to indicate that the open should be rejected
    - return None to let the next rule run
r?   )r   re   r4   r   
apply_ruleZRoutingRule.apply_rulej   s
     "!r   c                r   r   r   r   r   r   r    rb   u   r=   r   c                r>   r	   r?   r9   r:   r   shutdownZRoutingRule.shutdownu   rA   r   c                s$   < V ^8  d   Qh/ R;R&   # )r   r0   r/   r   r   r   r   r    rb   d   s      r   rc   N)
r   r&   r'   r(   r   rf   rg   r_   r)   r*   r+   r,   r   ra   ra   d   s*      	" 	"" "#  r   ra   c                   s  a  ] tR t^yt o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR lt	RV 3R lR llt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltRtV 3R lR ltV 3R lR ltV 3R ltRtV tR# )r0   Fc                s0   < V ^8  d   QhRS[ S[,          /# )r   routing_rules)r   ra   r   r   r   r    Router.__annotate__   s        d;&7  r   c                s    V F	  pWn         K  	  Wn        / V n        / V n        \        P
                  ! 4       V n        V P                  P                  4        R # r	   )r/   rh   open_channelsr[   asyncioEventno_endpointsset)r   rh   ruler   r   r   ZRouter.__init__   sF    !DK "*#MMOr   c                    < V ^8  d   QhRS[ /# r   r   rT   r   r   r   r    ri      s      j r   c                s    / # )z7Used by the 'info' channel.  Gets overridden in Bridge.r   r9   r:   r   infoZRouter.info   s    	r   c                s&   < V ^8  d   QhRS[ RS[/# rd   )r   r-   r   r   r   r    ri      s     	0 	0: 	0( 	0r   c                s    V P                    FH  p\        P                  R V4       VP                  V4      pVf   K0  \        P                  RV4       Vu # 	  \        P                  R4       \	        R4      h)z  applying rule %sz    resulting endpoint is %sz  No rules matchedznot-supported)rh   r!   r"   rf   r`   )r   re   ro   endpoints   &&  r   check_rulesZRouter.check_rules   sc    &&DLL-t4w/H#;XF ' LL-.//r   c                $   < V ^8  d   QhRS[ RR/# )r   rD   r   N)rH   r   r   r   r    ri      s     h hC hD hr   c                s     V P                   P                  V4       \        P                  R V4       R#   \         d%    \        P                  RYP                   4        R# i ; i)zrouter dropped channel %sz.trying to drop non-existent channel %s from %sN)rj   popr!   r"   KeyErrorZerror)r   rD   r4   r   r\   ZRouter.drop_channel   sQ    	h""7+LL4g> 	hLLI7TfTfg	hs   15 +A$#A$c                ru   )r   rs   r   N)r-   r   r   r   r    ri      s     " "X "$ "r   c                sh    \        4       V P                  V&   V P                  P                  4        R # r	   )rn   r[   rm   Zclear)r   rs   r4   r   r2   ZRouter.add_endpoint   s$    #&5x !r   Nc                s.   < V ^8  d   QhRS[ RRRS[RR/# )r   rs   rV   rW   rX   r   N)r-   r   r   r   r   r    ri      s,     ' '( '9L '_h 'mq 'r   c                s:   V P                   P                  V4      p\        P                  R WV4       V F+  pV P                  ! V3RRRV/VB  V P                  V4       K-  	  V P                   '       g   V P                  P                  4        V P                  '       dz   \        P                  RV P                   4       V P                   '       gF   V P                  '       d2   \        P                  R4       V P                  P                  4        R# R# R# R# )z'shutdown_endpoint(%s, %s) will close %srE   rY   rD     endpoints remaining: %rz  close transportN)r[   rv   r!   r"   rZ   r\   rm   rn   _eofZ	transportrY   )r   rs   rV   rX   ZchannelsrD   s   &&&,  r   r^   ZRouter.shutdown_endpoint   s    >>%%h/>RZ[GsOGOWOOg&   ~~~!!# 999LL4dnnE>>>dnnn01$$& '5> r   c                rP   rQ   rT   r   r   r   r    ri      s*     3 3L 3 3
 3W[ 3r   c                s    \        V P                  4      p\        P                  R W\	        V4      4       V F  pVP                  WV4       K  	  R# )z+do_kill(%s, %s).  Considering %d endpoints.N)rn   r[   r!   r"   r#   r7   )r   rR   rS   rF   r[   rs      &&&&  r   r7   ZRouter.do_kill   sB    '	BDQTU^Q_`!HT'2 "r   c                rB   rC   rG   r   r   r   r    ri      s*     ? ? ?c ?J ?[_ ?r   c                s2   V P                   f   \        R4      hVR8X  d   WP                  9   d   \        R4      h \        P	                  RWP                  R4      4       V P                  V4      pY@P                  T&   T P                  T,          P                  T4       M V P                  V,          pTP                  YT4       R #   \         d.   pT P                  TP                  4       RTR7        R p?R # R p?ii ; i  \         d     R # i ; i)Nz,channel control message received before initZopenzchannel is already openz5Trying to find endpoint for new channel %s payload=%sZpayloadrY   )rE   rD   )	init_hostr   rj   r!   r"   Zgetrt   r`   rZ   Z	get_attrsr[   Zaddrw   r5   )r   rD   rE   rF   rs   excrz   r   channel_control_receivedZRouter.channel_control_received   s    >>!&'UVV
 f,,,*+DEETV]_j_jkt_uv++G4
 +3w'NN8$((1--g6 	##Gg>   ""3==?GW"U  s)   6C %D D"C??DDDc                rJ   rK   rM   r   r   r   r    ri      s"     	0 	0S 	0 	0$ 	0r   c                s    V P                   f   \        R4      h V P                  V,          pTP	                  Y4       R #   \         d     R # i ; i)Nz)channel data message received before init)r{   r   rj   rw   r6   )r   rD   rL   rs   s   &&& r   channel_data_receivedZRouter.channel_data_received   sQ    >>!&'RSS	))'2H 	  /  		s   A AAc                rp   rq   )boolr   r   r   r    ri      s     	$ 	$d 	$r   c                s   \         P                  R V 4       \        V P                  4      pV F  pVP	                  4        K  	  RV n        \         P                  RV P                  4       \        V P                  4      # )zeof_received(%r)Trx   )r!   r"   rn   r[   r@   ry   r   )r   r[   rs   r$   r   eof_receivedZRouter.eof_received   s`    '.'	!H " 	0$..ADNN##r   c                s4   < V ^8  d   QhRS[ S[,          RR/# )r   r|   r   N)r   Z	Exceptionr   r   r   r    ri      s      	< 	<Xi0 	<T 	<r   c                s    V P                   '       g   V P                  4        V P                  e?   Vf   V P                  P                  R 4       R # V P                  P	                  V4       R # R # r	   )ry   r   _communication_doneZ
set_resultZset_exception)r   r|   r4   r   	do_closedZRouter.do_closed   sU    yyy##/{((33D9((66s;	 0r   c                r   r   r   r   r   r   r    ri      s     + +4 +r   c                sn  "   \         P                  ! 4       P                  4       V n         V P                  G Rj  xL
  RV n        V P                  P                  4       G Rj  xL
  R#  L/  \        \
        3 d     L@i ; i L  RT n        T P                  P                  4       G Rj  xL 
  i ; i5i)zNWait until communication is complete on the router and all endpoints are done.N)rk   Zget_running_loopZcreate_futurer   ZBrokenPipeErrorZConnectionResetErrorrm   Zwaitr9   r:   r   communicateZRouter.communicate   s      $+#;#;#=#K#K#M 		+**** (,D$ ##((*** +!56 		 +	 (,D$ ##((***sb   )B5A- A+A-  $B5$B%B5+A- -B>B  BB B5%B2+B.,B22B5c                s   < V ^8  d   Qh/ S[ S[,          ;R&   S[S[S[3,          ;R&   R;R&   S[P                  ;R&   S[;R&   S[S[P                  ,          ;R&   # )r   rh   rj   zdict[Endpoint, set[str]]r[   rm   ry   r   )
r   ra   r    rH   r-   rk   rl   r   r   ZFuturer   r   r   r    ri   y   sl     $$ X&&  *)  --	 
  j "'..18k r   )r   ry   r[   rm   rj   rh   r	   )r   r&   r'   r(   ry   r   rr   rt   r\   r2   r^   r7   r}   r~   r   r   r   r   r_   r)   r*   r+   r,   r   r0   r0   y   s     
 D    	0 	0h h" "' '"3 3? ?<	0 	0	$ 	$ 59	< 	<+ +E  r   r0   )rk   r
   ZloggingZtypingr    r   r   Zjsonutilr   r   Zprotocolr   r   r   Z	getLoggerr   r!   r   r-   r`   ra   r0   r   r   r   <module>r      si       ' ' + Q Q			8	$? ?>-; -;`	> 	" "*O+" O+r   