grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a q©jÓVã@s(ddlZddlZddlZddlZddlZddlZddlmZmZmZm Z m Z m Z m Z m Z ddlmZmZmZmZmZmZmZddlmZddlmZmZmZe e¡ZejrÀe  d¡Z!e "d¡Z#Gd d „d eƒZ$Gd d „d eƒZ%Gd d„deƒZ&Gdd„de&ej'ƒZ(Gdd„de&ƒZ)Gdd„de&ƒZ*dS)éN)ÚBinaryIOÚCallableÚClassVarÚ CollectionÚ GeneratorÚMappingÚSequenceÚTypeé)Ú JsonErrorÚ JsonObjectÚ JsonValueÚ create_objectÚget_boolÚget_enumÚget_str)ÚCockpitProblem)ÚEndpointÚRouterÚ RoutingRuleÚ_TÚ_PcsleZdZUded<eddœ‡fdd„ Zedœdd „Zd eed œd d „Z eddœdd„Z ddœdd„Z ‡Z S)ÚChannelRoutingRulezdict[str, list[Type[Channel]]]ÚtablezCollection[Type[Channel]])ÚrouterÚ channel_typescs\tƒ |¡i|_|D]}|j |jg¡}| |¡q|j ¡D]}|jdd„dd�q@dS)NcSs t|jƒS©N)ÚlenÚ restrictions)Úcls©r ú3/usr/lib/python3.9/site-packages/cockpit/channel.pyÚ)óz-ChannelRoutingRule.__init__..T)ÚkeyÚreverse)ÚsuperÚ__init__rÚ setdefaultÚpayloadÚappendÚvaluesÚsort)ÚselfrrrÚentry©Ú __class__r r!r's  zChannelRoutingRule.__init__©ÚreturncCs>i}|j ¡D]*\}}g}|D]}| |j¡q|||<q|Sr)rÚitemsÚextendÚ capabilities)r-Úresultr)ZimplsZcapsÚimplr r r!r5+s zChannelRoutingRule.capabilitieszCollection[tuple[str, object]])rÚoptionsr2cCs@|D]6\}}| |¡}|dur$dS|dur||krdSqdS)NFT)Úget)r-rr8r$Zexpected_valueZ our_valuer r r!Úcheck_restrictions5s  z%ChannelRoutingRule.check_restrictionszChannel | None©r8r2cCsZ|jdusJ‚| d¡}t|tƒs&dS|j |g¡D] }| |j|¡r4||jƒSq4dS)Nr))rr9Ú isinstanceÚstrrr:r)r-r8r)rr r r!Ú apply_ruleFs  zChannelRoutingRule.apply_ruleNcCsdSrr ©r-r r r!ÚshutdownSszChannelRoutingRule.shutdown) Ú__name__Ú __module__Ú __qualname__Ú__annotations__rr'r r5Úboolr:r>r@Ú __classcell__r r r/r!rs   rc@s eZdZdS)Ú ChannelErrorN)rArBrCr r r r!rGWsrGc@sZeZdZUdZdZdZeed<dZe ed<eZ e ed<eed<d ed <d Z d ed <ded<dZ ded<dZ ded<dZdZeed<ded<eed dœdd„Zeeed dœdd„Zdded d œd!d"„Zed d#œd$d%„Zd d&œd'd(„Zd d&œd)d*„Zd d&œd+d,„Zed d-œd.d/„Zed d-œd0d1„Zed d2œd3d4„Zeed d5œd6d7„Zed8d2œd9d:„Zed d;œdœeeed?œd@dA„Z!d d&œdBdC„Z"ed&œdDdE„Z#d d&œdFdG„Z$dHdI„Z%dedJdK„Z&dfd d dLœdMdN„Z'eed2œdOdP„Z(eed2œdQdR„Z)eed2œdSdT„Z*dgd eedUœdVdW„Z+dXdY„Z,d d&œdZd[„Z-e.j/d\d]�Z0d^ed_<eed d`œdadb„Z1ed d-œdcdd„Z2d S)hÚChanneli@i FÚ _send_pingsrÚ _out_sequenceÚ _out_windowÚ _ack_byteszset[asyncio.Task]Ú_tasksNúJsonObject | NoneÚ _close_argsz ClassVar[str]r)r z&ClassVar[Sequence[tuple[str, object]]]rzClassVar[Sequence[str]]r5ÚÚ is_binaryz codecs.IncrementalDecoder | NoneÚdecoder)ÚcommandÚmessager2cCsø|dkr„tƒ|_t|dƒ|_t|ddd�r0d|_t|ddgdƒdu|_t|d d ƒ|_t|d d gdƒdu|_ d|_ |  ¡|  |¡np|d kr–|  ¡n^|dkr¨| ¡nL|dkrº| ¡n:|dkrÎ| |¡n&|dkrâ| |¡n|dkrô| |¡dS)NÚopenÚchannelz flow-controlF)ÚdefaultTz send-acksÚbytesÚgrouprWZbinaryÚrawÚreadyÚdoneÚcloseÚpingÚpongr8)ÚsetrMrrVrrIrrLrYrQrRZfreeze_endpointÚdo_openÚdo_readyÚdo_doneÚdo_closeÚdo_pingÚdo_pongÚ do_options)r-rSrTr r r!Ú do_controlvs.       zChannel.do_control)rVrSrTr2c Cs’|jdurdSzLz| ||¡Wn6tyV}ztdt|ƒd�|‚WYd}~n d}~00Wn2tyŒ}z| | ¡¡WYd}~n d}~00dS)Núprotocol-error©rT)rOrhr rGr=r]Ú get_attrs)r-rVrSrTÚexcr r r!Údo_channel_control’s ,zChannel.do_channel_controlz str | None)ÚhostrYÚ_messager2cCs<|jdurdS|durdS|dur0|j|kr0dS| ¡dSr)rOrYrd)r-rnrYror r r!Údo_kill s zChannel.do_killr;cCst‚dSr©ÚNotImplementedError©r-r8r r r!ra¬szChannel.do_openr1cCsdSrr r?r r r!rb°szChannel.do_readycCsdSrr r?r r r!rc³szChannel.do_donecCs | ¡dSr©r]r?r r r!rd¶szChannel.do_close©rTr2cCstddd�‚dS)Nz not-supportedz)This channel does not implement "options"rj)rG©r-rTr r r!rg¹szChannel.do_optionscCs| |¡dSr)Ú send_pongrvr r r!re½szChannel.do_ping©Údatar2cCs|jr|jdt|ƒd�dS)NZack)rX)rLÚ send_controlr©r-ryr r r!Úsend_ackÀszChannel.send_ack)rVryr2c Cs^|jdurdSz| |¡s$| |¡Wn2tyX}z| | ¡¡WYd}~n d}~00dSr)rOÚdo_datar|rGr]rk)r-rVryrlr r r!Údo_channel_dataÄs  zChannel.do_channel_dataz bool | NonecCs~| ¡dS)aHandles incoming data to the channel. Return value is True if the channel takes care of send acks on its own, in which case it should call self.send_ack() on `data` at some point. None or False means that the acknowledgement is sent automatically.Trtr{r r r!r}ÐszChannel.do_data)Úkwargsr2cKs | ¡|jfddi|¤ŽdS)NrSr[)Z thaw_endpointrz)r-rr r r!r[Üsz Channel.ready©Úfinal)ryr�r2c Cs\|jdusJ‚z|jj||d�WStyV}ztdt|ƒd�|‚WYd}~n d}~00dS)Nr€rirj)rRÚdecodeÚUnicodeDecodeErrorrGr=)r-ryr�rlr r r!Z__decode_frameàs zChannel.__decode_framecCs(|jdur|jddd�|jdd�dS)Nr#Tr€r\)rS)rRÚ_Channel__decode_framerzr?r r r!r\çs z Channel.donecCs |jduSr)rOr?r r r!Ú is_closingîszChannel.is_closingcCs| |j¡dSr)Zshutdown_endpointrOr?r r r!Ú _close_nowñszChannel._close_nowcCs(|j |¡|jdur$|js$| ¡dSr)rMÚremoverOr†)r-Útaskr r r!Ú _task_doneôs zChannel._task_donecCs4|jdusJ‚t |¡}|j |¡| |j¡|S)z¬Create a task associated with the channel. All tasks must exit before the channel can close. You may not create new tasks after calling .close(). N)rOÚasyncioÚ create_taskrMÚaddÚadd_done_callbackr‰)r-Ú coroutineÚnamerˆr r r!r‹ýs    zChannel.create_task)Ú close_argsr2cCs*|jdurdS|pi|_|js&| ¡dS)zÛRequests the channel to be closed. After you call this method, you won't get anymore `.do_*()` calls. This will wait for any running tasks to complete before sending the close message. N)rOrMr†)r-r�r r r!r] s   z Channel.closecCsX| |j|¡|jrL|jt|ƒ}|jtj|tjkrF|jd|d�||_|j|jkS)a«Send binary data and handle book-keeping for flow control. The flow control is "advisory". The data is sent immediately, even if it's larger than the window. In general you should try to send packets which are approximately Channel.BLOCK_SIZE in size. Returns True if there is still room in the window, or False if you should stop writing for now. In that case, `.do_resume_send()` will be called later when there is more room. Be careful with text channels (i.e. without binary="raw"): you are responsible for ensuring that @data is valid UTF-8. This isn't validated here for efficiency reasons. r^)rSÚsequence) Zsend_channel_datarVrIrJrrHÚ BLOCK_SIZErzrK)r-ryZ out_sequencer r r!Ú send_bytesszChannel.send_bytescCs<|jr| |¡S|jdur,t d¡dd�|_| | |¡¡S)aDSend data and transparently handle UTF-8 for text channels Use this for channels which can be text, but are not guaranteed to get valid UTF-8 frames -- i.e. multi-byte characters may be split across frames. This is expensive, so prefer send_text() or send_bytes() wherever possible. Nzutf-8Ústrict)Úerrors)rQr“rRÚcodecsÚgetincrementaldecoderÚ send_textr„r{r r r!Ú send_data1s   zChannel.send_datacCs| | ¡¡S)z¨Send UTF-8 string data and handle book-keeping for flow control. Similar to `send_bytes`, but for text data. The data is sent as UTF-8 encoded bytes. )r“Úencoder{r r r!r˜BszChannel.send_text)Úmsgrr2cKs |j t||ƒ¡d}| |¡S)NÚ )Ú json_encoderršrr˜)r-r›rZprettyr r r!Ú send_jsonIszChannel.send_jsoncCs@|jst d|j¡dS|dtj|_|j|jkr<| ¡dS)NzGot wild pong on channel %sr‘) rIÚloggerZwarningrVrHÚ SEND_WINDOWrKrJÚdo_resume_sendrvr r r!rfMs  zChannel.do_pongcCsdS)zs,($    = f