+
    i#  c                   s    ^ RI t ^ RIt^ RIt^ RIt^RIHtHtHtHtH	t	H
t
HtHt ]P                  ! ]4      t ! R R]4      t ! R R]4      t ! R R] P&                  4      t ! R	 R
]4      tR# )    N)	JsonError
JsonObject	JsonValuecreate_objectget_intget_strget_str_or_nonetypecheckedc                   sd   a a ] tR t^t oRtRV3R lV 3R llltV3R lR ltV3R ltRtVt	V ;t
# )	CockpitProblema  A type of exception that carries a problem code and a message.

Depending on the scope, this is used to handle shutting down:

  - an individual channel (sends problem code in the close message)
  - peer connections (sends problem code in close message for each open channel)
  - the main stdio interaction with the bridge

It is usually thrown in response to some violation of expected protocol
when parsing messages, connecting to a peer, or opening a channel.
c                s.   < V ^8  d   QhRS[ RRRS[RR/# )   problemmsgJsonObject | NonekwargsreturnNstrr   Zformat__classdict__   "5/usr/lib/python3.14/site-packages/cockpit/protocol.py__annotate__CockpitProblem.__annotate__   s2     B B B*= BPY B^b B    c                sx   < WR &   \        W#4      V n        \        SV `  \	        V P                  RV4      4       R# )r   messageN)r   attrssuper__init__r   )selfr   r   r   	__class__s   &&&,r   r   ZCockpitProblem.__init__   s1    #y"3/
Y@Ar   c                    < V ^8  d   QhRS[ /# r
   r   r   r   r   r   r   r   #   s      : r   c                s$   V P                   R ,          R8X  dn   V P                  e`   \        V P                   \        P                  ! V P                  P
                  V P                  V P                  P                  4      R7      # V P                   # )r   zinternal-error)Zcause)r   Z	__cause__dict	tracebackZformat_exceptionr   Z__traceback__r      &r   	get_attrsZCockpitProblem.get_attrs#   sh    ::i $449S

)*D*D(($..$..:V:V+   ::r   c                s&   < V ^8  d   Qh/ S[ ;R&   # )r
   r   r!   r   r   r   r   r      s       r   )r   N)__name__
__module____qualname____firstlineno____doc__r   r&   __annotate_func____static_attributes____classdictcell____classcell__r   r      @@r   r	   r	      s'     
B B
 '  r   r	   c                   sB   a a ] tR t^,t oRV3R lV 3R llltRtVtV ;t# )CockpitProtocolErrorc                s&   < V ^8  d   QhRS[ RS[ /# )r
   r   r   )r   r   r   r   r   Z!CockpitProtocolError.__annotate__-   s     3 3 3c 3r   c                s(   < \         SV `  W!R 7       R# ))r   N)r   r   )r   r   r   r   s   &&&r   r   ZCockpitProtocolError.__init__-   s    2r    )zprotocol-error)r(   r)   r*   r+   r   r.   r/   r0   r1   r2   r   r3   r3   ,   s     3 3 3r   r3   c                   sV  a  ] tR t^1t o RtRtRtRt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V 3R lR ltR%V 3R lR l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tR$tV tR# )&CockpitProtocolzA naive implementation of the Cockpit frame protocol

We need to use this because Python's SelectorEventLoop doesn't supported
buffered protocols.
Nr   Fc                   < V ^8  d   QhRR/# r
   r   Nr4   r   r   r   r   CockpitProtocol.__annotate__<   s      $ r   c                    R # r'   r4   r$   r%   r   do_readyZCockpitProtocol.do_ready<       r   c                "   < V ^8  d   QhRRRR/# r
   exczException | Noner   Nr4   r   r   r   r   r8   ?   s      / D r   c                r9   r'   r4   r   r>      &&r   	do_closedZCockpitProtocol.do_closed?   r;   r   c                *   < V ^8  d   QhRS[ RS[RR/# r
   commandr   r   Nr   r   r   r   r   r   r8   B   s"     " "# "
 "t "r   c                    \         hr'   ZNotImplementedErrorr   rD   r      &&&r   transport_control_receivedZ*CockpitProtocol.transport_control_receivedB       !!r   c                s0   < V ^8  d   QhRS[ RS[ RS[RR/# )r
   channelrD   r   r   NrE   r   r   r   r   r8   E   s*     " " "c "J "[_ "r   c                rF   r'   rG   )r   rL   rD   r      &&&&r   channel_control_receivedZ(CockpitProtocol.channel_control_receivedE   rK   r   c                rB   )r
   rL   datar   Nr   bytesr   r   r   r   r8   H   s"     " "S " "$ "r   c                rF   r'   rG   )r   rL   rO   rI   r   channel_data_receivedZ%CockpitProtocol.channel_data_receivedH   rK   r   c                $   < V ^8  d   QhRS[ RR/# )r
   framer   NrQ   r   r   r   r   r8   K   s     	( 	(E 	(d 	(r   c                s    VP                  R 4      w  r#pVR8w  dE   VP                  R4      p\        P                  R\	        V4      V4       V P                  WT4       R# V P                  V4       R# )   
r   asciiz.data received: %d bytes of data for channel %sN)Z	partitionZdecodeloggerdebuglenrR   control_received)r   rT   headerZ_rO   rL      &&    r   frame_receivedZCockpitProtocol.frame_receivedK   s]    //%04S=mmG,GLLI3t9V]^&&w5 !!$'r   c                rS   r
   rO   r   NrU   r   r   r   r   r8   V   s     M MU Mt Mr   c                s    \        \        P                  ! V4      \        4      p\	        VR 4      p\	        VRR4      pVe+   \
        P                  RV4       V P                  WCV4       R# \
        P                  RV4       V P                  W24       R#   \        P                  \        3 d   p\        RT: 24      ThRp?ii ; i)rD   rL   Nzchannel control received %sztransport control received %szcontrol message: )r   jsonZloadsr"   r   rX   rY   rN   rJ   ZJSONDecodeErrorr   r3   )r   rO   r   rD   rL   r>   r]   r   r[   Z CockpitProtocol.control_receivedV   s    	M!$**T"2D9Ggy1Ggy$7G":GD--gH<gF//A$$i0 	M&):3''BCL	Ms   A)B -'B C1CCc                s&   < V ^8  d   QhRS[ RS[/# )r
   rO   r   )rQ   intr   r   r   r   r8   f   s      e  r   c                s    VP                  R4      p \	        TRT 4      pT^,           pYT,           pT\        T4      8  d   \        T4      T,
          # T P                  YT 4       T#   \         d9   p\        T4      ^
8  d   \        T4      ^
,
          u Rp?# \        R4      ThRp?ii ; i  \         d   p\        R4      ThRp?ii ; i)zConsumes a single frame from view.

Returns positive if a number of bytes were consumed, or negative if no
work can be done because of a given number of bytes missing.
rV   Nzsize line is too longzframe size is not an integer)ZindexZ
ValueErrorrZ   r3   ra   r^   )r   rO   Znewliner>   ZlengthZstartZends   &&     r   consume_one_frameZ!CockpitProtocol.consume_one_framef   s    	Ijj'G	Phw(F !nT?t9s?" 	DsO,
)  	I4y2~4y2~%&'>?SH		I  	P&'EFCO	Ps:   A* B0 *B-5!B(B-B((B-0C;CCc                s8   < V ^8  d   QhRS[ P                  RR/# )r
   	transportr   N)asyncioZBaseTransportr   r   r   r   r8      s!      )>)> 4 r   c                s   \         P                  R V4       \        V\        P                  4      '       g   Q hWn        V P                  4        V P                  '       d(   \         P                  R4       VP                  4        R# R# )zconnection_made(%s)z;  but the protocol already was closed, so closing transportN)	rX   rY   Z
isinstancerd   Z	Transportrc   r:   _closedclose)r   rc   r@   r   connection_madeZCockpitProtocol.connection_made   s]    *I6)W%6%67777"<<<LLVWOO r   c                r<   r=   r4   r   r   r   r   r8      s      #5 $ r   c                s    \         P                  R 4       V P                  f   Q hRV n        V P                  V4       R# )connection_lostN)rX   rY   rc   rf   r?   r@   r   rh   ZCockpitProtocol.connection_lost   s1    &'~~)))

3r   c                r<   r=   r4   r   r   r   r   r8      s      + t r   c                s    V P                   '       d   R # RV n         V P                  '       d   V P                  P                  4        V P                  V4       R # )NT)re   rc   rf   rA   r?   r@   r   rf   ZCockpitProtocol.close   s:    <<<>>>NN  "sr   c                rB   )r
   rL   payloadr   NrP   r   r   r   r   r8      s"     	= 	=# 	= 	=$ 	=r   c                sD   \        VR,           4      \        V4      ,           pV RV R2P                  R4      pV P                  eD   \        P	                  RV P                  4       V P                  P                  WB,           4       R# \        P	                  R4       R# )z0Send a given payload (bytes) on channel (string)
rW   Nzwriting to transport %sz cannot write to closed transport)rZ   encoderc   rX   rY   Zwrite)r   rL   ri   Zframe_lengthr\   s   &&&  r   write_channel_dataZ"CockpitProtocol.write_channel_data   sw     7T>*S\9 >G9B/66w?>>%LL2DNNCNN  !12LL;<r   c                s(   < V ^8  d   QhRRRS[ RR/# )r
   r   r   r   r   N)r   r   r   r   r   r8      s$     5 5!4 5y 5UY 5r   c                s    \         P                  RW4       \        P                  ! \	        W4      ^R7      R,           pV P                  RVP                  4       4       R# )zCWrite a control message.  See jsonutil.create_object() for details.zsending control message %r %r)Zindentrj   Z N)rX   rY   r`   Zdumpsr   rl   rk   )r   r   r   Zprettys   &&, r   write_controlZCockpitProtocol.write_control   sA    4cBM#6qADHFMMO4r   c                rS   r_   rU   r   r   r   r   r8      s     	 	% 	D 	r   c                s&    V ;P                   V,          un         V P                   '       d;   V P                  V P                   4      pV^ 8:  d   R# V P                   VR V n         KL  R#   \         d   pT P                  T4        Rp?R# Rp?ii ; i)r    N)bufferrb   r3   rf   )r   rO   Zresultr>   s   &&  r   data_receivedZCockpitProtocol.data_received   sr    	KK4K+++//<Q;"kk&'2	 
 $ 	JJsOO	s"   *A) "A) A) )B4BBc                r   r    Zboolr   r   r   r   r8      s      d r   c                r9   )Fr4   r$   r%   r   eof_receivedZCockpitProtocol.eof_received   s    r   c                s:   < V ^8  d   Qh/ R;R&   S[ ;R&   R;R&   # )r
   zasyncio.Transport | Nonerc   re   zasyncio.Future[None] | None_communication_donerp   r   r   r   r   r8   1   s,      *0    7= r   )re   rn   rc   r'   )r(   r)   r*   r+   r,   rc   rn   re   rr   r:   rA   rJ   rN   rR   r^   r[   rb   rg   rh   rf   rl   rm   ro   rq   r-   r.   r/   r      @r   r5   r5   1   s     
 -1IFG9=  " "" "" "	( 	(M M  >   	= 	=5 5	 	 U  r   r5   c                   s   a  ] tR t^t o RtRt^ 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RV 3R lR lltV 3R lR ltV 3R ltRtV tR# )CockpitProtocolServerNc                r6   r7   r4   r   r   r   r   "CockpitProtocolServer.__annotate__   s     " "d "r   c                rF   r'   rG   r$   r%   r   do_send_initZ"CockpitProtocolServer.do_send_init   rK   r   c                rS   r
   r   r   Nr!   r   r   r   r   rv      s      z d r   c                r9   r'   r4   )r   r   r@   r   do_initZCockpitProtocolServer.do_init   r;   r   c                s,   < V ^8  d   QhRRRRRS[ RR/# )r
   host
str | Nonegroupr   r   Nr!   r   r   r   r   rv      s*     " "L " "
 "W[ "r   c                rF   r'   rG   )r   rz   r|   r   rM   r   do_killZCockpitProtocolServer.do_kill   rK   r   c                rB   rC   rE   r   r   r   r   rv      s'     Y Y# Y
 Yt Yr   c                sF   VR 8X  dA   \        VR4      ^8w  d   \        R4      h\        VR4      V n        V P	                  V4       R# VR8X  d,   V P                  \        VRR4      \        VRR4      V4       R# VR8X  d   V P                  V4       R# \        RV R	24      h)
ZinitZversionzincorrect version numberrz   ZkillNr|   	authorizezunexpected control message z	 received)r   r3   r   	init_hostry   r}   r   do_authorizerH   rI   r   rJ   Z0CockpitProtocolServer.transport_control_received   s    fw	*a/*+EFF$Wf5DNLL!LL&$?QXZacgAhjqr#g&&)DWIY'WXXr   c                r6   r7   r4   r   r   r   r   rv      s      $ r   c                s&    V P                  4        R # r'   )rw   r$   r%   r   r:   ZCockpitProtocolServer.do_ready   s    r   c                s0   < V ^8  d   QhRS[ RRRS[RS[/# r
   	challengetimeoutz
int | Noner   r   )r   r   r   r   r   r   r   rv      s-     , ,,'3,FO,	,r   c           	     s  "   V P                   f   / V n         \        V P                  4      pV ;P                  ^,          un        \        P                  ! 4       P                  4       p WPP                   V&   V P                  ! RRRRVRV/VB  \        P                  ! WR4      G R j  xL
 V P                   P                  V4       #  L  T P                   P                  T4       i ; i5i)NrD   r~   r   cookier'   )	authorizationsr   next_auth_idrd   Zget_running_loopZcreate_futurerm   Zwait_forZpop)r   r   r   r   r   Zfutures   &&&,  r   request_authorization_objectZ2CockpitProtocolServer.request_authorization_object   s      &"$DT&&'Q))+99;	,*0'g[gIgV\g`fg ))&::##F+ ;##F+s0   A'C+*?C )C	*C -C+	C C((C+c                s0   < V ^8  d   QhRS[ RRRS[RS[ /# r   r   r   r   r   r   rv      s3     j jj'3jFOj	jr   c                sX   "   \        V P                  ! W3/ VB G R j  xL
 R4      #  L	5i)NZresponse)r   r   )r   r   r   r   s   &&&,r   request_authorizationZ+CockpitProtocolServer.request_authorization   s,      T>>y\U[\\^hii\s   *(
*c                rS   rx   r!   r   r   r   r   rv      s     8 8J 84 8r   c                s    \        VR 4      pV P                  e   W P                  9  d   \        P                  R4       R# V P                  V,          P	                  V4       R# )r   Nzno matching authorize request)r   r   rX   ZwarningZ
set_result)r   r   r   s   && r   r   Z"CockpitProtocolServer.do_authorize   sN    (+&&8K8K*KNN:;F#..w7r   c                s.   < V ^8  d   Qh/ R;R&   R;R&   # )r
   r{   r   z,dict[str, asyncio.Future[JsonObject]] | Noner   r4   r   r   r   r   rv      s     " BI r   )r   r   r'   )r(   r)   r*   r+   r   r   r   rw   ry   r}   rJ   r:   r   r   r   r-   r.   r/   rs   rt   r   ru   ru      sp     "IEINL" " " "Y Y , ,j j
8 8g  r   ru   )rd   r`   Zloggingr#   Zjsonutilr   r   r   r   r   r   r   r   Z	getLoggerr(   rX   Z	Exceptionr	   r3   ZProtocolr5   ru   r4   r   r   <module>r      se        u u u			8	$Y 83> 3
Kg&& K^:8O :8r   