grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a q©jà%ã@s¨ddlZddlZddlZddlmZmZmZddlmZm Z ddl m Z m Z m Z e e¡ZGdd„dƒZGdd „d ƒZGd d „d e ƒZGd d „d ƒZGdd„de ƒZdS)éN)ÚDictÚListÚOptionalé)Ú JsonObjectÚ JsonValue)ÚCockpitProblemÚCockpitProtocolErrorÚCockpitProtocolServerc@s.eZdZdZdd„Zdd„Zddœdd „ZdS) ÚExecutionQueueawTemporarily 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. cCs*t ¡|_||_|jD]}| |¡qdS©N)Ú collectionsÚdequeÚqueueÚmethodsÚ_wrap)ÚselfrÚmethod©rú2/usr/lib/python3.9/site-packages/cockpit/router.pyÚ__init__s  zExecutionQueue.__init__cs tˆjˆjj‡‡fdd„ƒdS)Ncsˆj ˆ|f¡Sr )rÚappend)Úargs©rrrrÚ%óz&ExecutionQueue._wrap..)ÚsetattrÚ__self__Ú__func__Ú__name__)rrrrrr!szExecutionQueue._wrapN©ÚreturncCsJt dt|jƒ¡|jD]\}}||Žq|jD]}t|j|jjƒq0dS)Nz.ExecutionQueue: Running %d queued method calls) ÚloggerÚdebugÚlenrrÚdelattrrrr)rrrrrrÚrun's   zExecutionQueue.run)rÚ __module__Ú __qualname__Ú__doc__rrr&rrrrr sr c@sÔeZdZUded<dZeeed<ddœdd„Zddœd d „Zddœd d „Z ddœd d„Z e e e ddœdd„Z e eddœdd„Zdde ddœdd„Ze eddœdd„Ze e deddœdd„Zd"deddœd d!„ZdS)#ÚEndpointÚRouterÚrouterNÚ _Endpoint__endpoint_frozen_queue©r,cCs| |¡||_dSr )Ú add_endpointr,©rr,rrrr4s zEndpoint.__init__r cCs&t d|¡t|j|j|jhƒ|_dS)NzFreezing endpoint %s)r"r#r Údo_channel_controlÚdo_channel_dataÚdo_killr-©rrrrÚfreeze_endpoint8s zEndpoint.freeze_endpointcCs t d|¡|j ¡d|_dS)NzThawing endpoint %s)r"r#r-r&r4rrrÚ thaw_endpoint=s  zEndpoint.thaw_endpointcCst‚dSr ©ÚNotImplementedErrorr4rrrÚdo_closeDszEndpoint.do_close©ÚchannelÚcommandÚmessager!cCst‚dSr r7)rr;r<r=rrrr1GszEndpoint.do_channel_control©r;Údatar!cCst‚dSr r7©rr;r?rrrr2JszEndpoint.do_channel_dataú str | None©ÚhostÚgroupr=r!cCst‚dSr r7)rrCrDr=rrrr3MszEndpoint.do_killcCs|j ||¡dSr )r,Zwrite_channel_datar@rrrÚsend_channel_dataQszEndpoint.send_channel_dataúJsonObject | None)r;r<ÚmsgÚkwargsr!cKsD|jj|f||dœ|¤Ž|dkr@|jj| |¡|j |¡dS)N)r;r<Úclose)r,Ú write_controlÚ endpointsÚremoveÚ drop_channel)rr;r<rGrHrrrÚsend_channel_controlTszEndpoint.send_channel_control)rGrHr!cKs|jj||fi|¤ŽdSr )r,Úshutdown_endpoint)rrGrHrrrrO\szEndpoint.shutdown_endpoint)N)rr'r(Ú__annotations__r-rr rr5r6r9Ústrrr1Úbytesr2r3rErrNrOrrrrr*0s þ r*c@s eZdZdS)Ú RoutingErrorN)rr'r(rrrrrS`srSc@sFeZdZUded<ddœdd„Zeeedœdd„Zd d œd d „Z d S) Ú RoutingRuler+r,r.cCs ||_dSr r.r0rrrrgszRoutingRule.__init__©Úoptionsr!cCst‚dS)a]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 Nr7)rrVrrrÚ apply_rulejs zRoutingRule.apply_ruleNr cCst‚dSr r7r4rrrÚshutdownuszRoutingRule.shutdown) rr'r(rPrrrr*rWrXrrrrrTds  rTc@s*eZdZUeeed<eeefed<ded<e j ed<dZ e ed<eedœd d „Z ed œd d „Zeedœdd„Zeddœdd„Zeddœdd„Zd.ededdœdd„Zddeddœdd„Zeeedd œd!d"„Zeedd#œd$d%„Ze d œd&d'„ZdZee jed(<eedd)œd*d+„Zdd œd,d-„ZdS)/r+Ú routing_rulesÚ open_channelszdict[Endpoint, set[str]]rKÚ no_endpointsFÚ_eof)rYcCs:|D] }||_q||_i|_i|_t ¡|_|j ¡dSr )r,rYrZrKÚasyncioÚEventr[Úset)rrYÚrulerrrr€s zRouter.__init__r cCsiS)z7Used by the 'info' channel. Gets overridden in Bridge.rr4rrrÚinfo‰sz Router.inforUcCsT|jD]6}t d|¡| |¡}|durt d|¡|Sqt d¡tdƒ‚dS)Nz applying rule %sz resulting endpoint is %sz No rules matchedz not-supported)rYr"r#rWrS)rrVr`ÚendpointrrrÚ check_rules�s      zRouter.check_rulesN)r;r!cCsDz|j |¡t d|¡Wn"ty>t d||j¡Yn0dS)Nzrouter dropped channel %sz.trying to drop non-existent channel %s from %s)rZÚpopr"r#ÚKeyErrorÚerror)rr;rrrrM˜s   zRouter.drop_channel)rbr!cCstƒ|j|<|j ¡dSr )r_rKr[Úclear)rrbrrrr/Ÿs zRouter.add_endpointrF)rbrGrHr!cKs�|j |¡}t d|||¡|D]&}|j|fd|dœ|¤Ž| |¡q |jsX|j ¡|jrŒt d|j¡|jsŒ|j rŒt d¡|j   ¡dS)Nz'shutdown_endpoint(%s, %s) will close %srI©r<r;ú endpoints remaining: %rz close transport) rKrdr"r#rJrMr[r_r\Z transportrI)rrbrGrHZchannelsr;rrrrO£s     zRouter.shutdown_endpointrArBcCs:t|jƒ}t d||t|ƒ¡|D]}| |||¡q"dS)Nz+do_kill(%s, %s). Considering %d endpoints.)r_rKr"r#r$r3)rrCrDr=rKrbrrrr3´s zRouter.do_killr:c CsÊ|dkr”||jvrtdƒ‚z"t d|| d¡¡| |¡}Wn:tyv}z"|j| ¡d|d�WYd}~dSd}~00||j|<|j |  |¡n$z|j|}Wnt y¶YdS0|  |||¡dS)NÚopenzchannel is already openz5Trying to find endpoint for new channel %s payload=%sZpayloadrIrh) rZr r"r#ÚgetrcrSrJZ get_attrsrKÚaddrer1)rr;r<r=rbÚexcrrrÚchannel_control_receivedºs    zRouter.channel_control_receivedr>cCs4z|j|}Wnty"YdS0| ||¡dSr )rZrer2)rr;r?rbrrrÚchannel_data_receivedÕs  zRouter.channel_data_receivedcCsFt d|¡t|jƒ}|D] }| ¡qd|_t d|j¡t|jƒS)Nzeof_received(%r)Tri)r"r#r_rKr9r\Úbool)rrKrbrrrÚ eof_receivedÝs   zRouter.eof_receivedÚ_communication_done)rmr!cCs>|js| ¡|jdur:|dur.|j d¡n |j |¡dSr )r\rqrrZ set_resultZ set_exception)rrmrrrÚ do_closedês  zRouter.do_closedc Ãsnt ¡ ¡|_zBz|jIdHWnttfy6Yn0Wd|_|j ¡IdHnd|_|j ¡IdH0dS)zNWait until communication is complete on the router and all endpoints are done.N)r]Zget_running_loopZ create_futurerrÚBrokenPipeErrorÚConnectionResetErrorr[Úwaitr4rrrÚ communicateõsüzRouter.communicate)N) rr'r(rrTrPrrQr*r]r^r\rprrrarcrMr/rrOr3rnrRrorqrrrZFutureÚ Exceptionrsrwrrrrr+ys$        r+)r]r ZloggingÚtypingrrrZjsonutilrrZprotocolrr r Z getLoggerrr"r r*rSrTr+rrrrÚs 0