HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/cockpit/__pycache__/router.cpython-39.pyc
a

�/�h�'�@s�ddlZddlZddlZddlmZmZmZddlmZm	Z	ddl
mZmZm
Z
e�e�ZGdd�d�ZGdd	�d	�ZGd
d�de�ZGdd
�d
�ZGdd�de
�ZdS)�N)�Dict�List�Optional�)�
JsonObject�	JsonValue)�CockpitProblem�CockpitProtocolError�CockpitProtocolServerc@s(eZdZdZdd�Zdd�Zdd�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�<lambda>1�z&ExecutionQueue._wrap.<locals>.<lambda>)�setattr�__self__�__func__�__name__)rrrrrr-szExecutionQueue._wrapcCsJt�dt|j��|jD]\}}||�q|jD]}t|j|jj�q0dS)Nz.ExecutionQueue: Running %d queued method calls)	�logger�debug�lenrr�delattrrrr)rrrrrr�run3s


zExecutionQueue.runN)r�
__module__�__qualname__�__doc__rrr$rrrrrsrc@s�eZdZUded<dZeeed<dd�dd�Zdd	�Zd
d�Z	dd
�Z
eeedd�dd�Z
eedd�dd�Zddedd�dd�Zeedd�dd�Zeededd�dd�Zd!dedd�dd �ZdS)"�Endpoint�Router�routerN� _Endpoint__endpoint_frozen_queue�r*cCs|�|�||_dSr)�add_endpointr*�rr*rrrr@s
zEndpoint.__init__cCs4|jdusJ�t�d|�t|j|j|jh�|_dS)NzFreezing endpoint %s)r+r r!r�do_channel_control�do_channel_data�do_kill�rrrr�freeze_endpointDszEndpoint.freeze_endpointcCs.|jdusJ�t�d|�|j��d|_dS)NzThawing endpoint %s)r+r r!r$r2rrr�
thaw_endpointIs
zEndpoint.thaw_endpointcCst�dSr��NotImplementedErrorr2rrr�do_closePszEndpoint.do_close��channel�command�message�returncCst�dSrr5)rr9r:r;rrrr/SszEndpoint.do_channel_control�r9�datar<cCst�dSrr5�rr9r>rrrr0VszEndpoint.do_channel_data�
str | None��host�groupr;r<cCst�dSrr5)rrBrCr;rrrr1YszEndpoint.do_killcCs|j�||�dSr)r*Zwrite_channel_datar?rrr�send_channel_data]szEndpoint.send_channel_data�JsonObject | None)r9r:�msg�kwargsr<cKsD|jj|f||d�|��|dkr@|jj|�|�|j�|�dS)N)r9r:�close)r*�
write_control�	endpoints�remove�drop_channel)rr9r:rFrGrrr�send_channel_control`szEndpoint.send_channel_control)rFrGr<cKs|jj||fi|��dSr)r*�shutdown_endpoint)rrFrGrrrrNhszEndpoint.shutdown_endpoint)N)rr%r&�__annotations__r+rrrr3r4r7�strrr/�bytesr0r1rDrrMrNrrrrr(<s
�r(c@seZdZdS)�RoutingErrorN)rr%r&rrrrrRlsrRc@s@eZdZUded<dd�dd�Zeeed�dd�Zd	d
�Z	dS)�RoutingRuler)r*r,cCs
||_dSrr,r.rrrrsszRoutingRule.__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
        Nr5)rrUrrr�
apply_rulevs	zRoutingRule.apply_rulecCst�dSrr5r2rrr�shutdown�szRoutingRule.shutdownN)
rr%r&rOrrrr(rVrWrrrrrSps
rSc@seZdZUeeed<eeefed<ded<e	j
ed<dZeed<eed�d	d
�Z
eed�dd
�Zedd�dd�Zedd�dd�Zd,ededd�dd�Zddedd�dd�Zeeedd�dd�Zeedd �d!d"�Zed#�d$d%�ZdZee	jed&<eedd'�d(d)�Zdd#�d*d+�ZdS)-r)�
routing_rules�
open_channelszdict[Endpoint, set[str]]rJ�no_endpointsF�_eof)rXcCs:|D]
}||_q||_i|_i|_t��|_|j��dSr)r*rXrYrJ�asyncio�EventrZ�set)rrX�rulerrrr�s
zRouter.__init__rTcCsT|jD]6}t�d|�|�|�}|durt�d|�|Sqt�d�td��dS)Nz  applying rule %sz    resulting endpoint is %sz  No rules matchedz
not-supported)rXr r!rVrR)rrUr_�endpointrrr�check_rules�s



zRouter.check_rulesN)r9r<cCsDz|j�|�t�d|�Wn"ty>t�d||j�Yn0dS)Nzrouter dropped channel %sz.trying to drop non-existent channel %s from %s)rY�popr r!�KeyError�error)rr9rrrrL�s
zRouter.drop_channel)r`r<cCst�|j|<|j��dSr)r^rJrZ�clear)rr`rrrr-�szRouter.add_endpointrE)r`rFrGr<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 %srH�r:r9�  endpoints remaining: %rz  close transport)rJrbr r!rIrLrZr^r[Z	transportrH)rr`rFrGZchannelsr9rrrrN�s

zRouter.shutdown_endpointr@rAcCs:t|j�}t�d||t|��|D]}|�|||�q"dS)Nz+do_kill(%s, %s).  Considering %d endpoints.)r^rJr r!r"r1)rrBrCr;rJr`rrrr1�s
zRouter.do_killr8c
Cs�|dkr�||jvrtd��z"t�d||�d��|�|�}Wn:tyv}z"|j|��d|d�WYd}~dSd}~00||j|<|j	|�
|�n$z|j|}Wnty�YdS0|�|||�dS)N�openzchannel is already openz5Trying to find endpoint for new channel %s payload=%sZpayloadrHrf)
rYr	r r!�getrarRrIZ	get_attrsrJ�addrcr/)rr9r:r;r`�excrrr�channel_control_received�s 

zRouter.channel_control_receivedr=cCs4z|j|}Wnty"YdS0|�||�dSr)rYrcr0)rr9r>r`rrr�channel_data_received�s
zRouter.channel_data_received)r<cCsFt�d|�t|j�}|D]}|��qd|_t�d|j�t|j�S)Nzeof_received(%r)Trg)r r!r^rJr7r[�bool)rrJr`rrr�eof_received�s

zRouter.eof_received�_communication_done)rkr<cCs>|js|��|jdur:|dur.|j�d�n|j�|�dSr)r[rorpZ
set_resultZ
set_exception)rrkrrr�	do_closed�s
zRouter.do_closedc	�s||jdusJ�t����|_zBz|jIdHWnttfyDYn0Wd|_|j��IdHnd|_|j��IdH0dS)zNWait until communication is complete on the router and all endpoints are done.N)rpr\Zget_running_loopZ
create_future�BrokenPipeError�ConnectionResetErrorrZ�waitr2rrr�communicate�s�zRouter.communicate)N)rr%r&rrSrOrrPr(r\r]r[rnrrrarLr-rrNr1rlrQrmrorprZFuture�	Exceptionrqrurrrrr)�s"

	r))r\r
Zlogging�typingrrrZjsonutilrrZprotocolrr	r
Z	getLoggerrr rr(rRrSr)rrrr�<module>s
0