HEX
Server: Apache
System: Linux insrv.serversdaddy.com 5.14.0-362.24.2.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 30 14:11:54 EDT 2024 x86_64
User: jsaha (1066)
PHP: 8.3.6
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/usr/lib/python3.9/site-packages/cockpit/__pycache__/router.cpython-39.pyc
a

���e� �@s�ddlZddlZddlmZmZmZddlmZmZddl	m
Z
mZe�e
�ZGdd�d�ZGdd	�d	�ZGd
d�de�ZGdd
�d
�ZGdd�de�ZdS)�N)�Dict�List�Optional�)�JsonDocument�
JsonObject)�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>0�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�run2s


zExecutionQueue.runN)r�
__module__�__qualname__�__doc__rrr#rrrrr
sr
c@s�eZdZUded<dZeeed<dd�dd�Zdd	�Zd
d�Z	e
e
edd�d
d�Ze
e
dd�dd�Zee
ee
dd�dd�Ze
e
dd�dd�Ze
edd�dd�Zedd�dd�Zedd�dd�ZdS)�Endpoint�Router�routerN� _Endpoint__endpoint_frozen_queue�r)cCs
||_dSrr+�rr)rrrr?szEndpoint.__init__cCs4|jdusJ�t�d|�t|j|j|jh�|_dS)NzFreezing endpoint %s)r*rr r
�do_channel_control�do_channel_data�do_kill�rrrr�freeze_endpointBszEndpoint.freeze_endpointcCs.|jdusJ�t�d|�|j��d|_dS)NzThawing endpoint %s)r*rr r#r0rrr�
thaw_endpointGs
zEndpoint.thaw_endpoint��channel�command�message�returncCst�dSr��NotImplementedError)rr4r5r6rrrr-NszEndpoint.do_channel_control�r4�datar7cCst�dSrr8�rr4r;rrrr.QszEndpoint.do_channel_data��host�groupr7cCst�dSrr8)rr>r?rrrr/TszEndpoint.do_killcCs|j�||�dSr)r)Zwrite_channel_datar<rrr�send_channel_dataXszEndpoint.send_channel_data)r4�kwargsr7cKs|jj|fi|��dSr)r)Z
write_message)rr4rArrr�send_channel_message[szEndpoint.send_channel_message)rAr7cKs0|jjf||d�|��|dkr,|j�|�dS)N)r4r5�close)r)�
write_control�drop_channel)rr4r5rArrr�send_channel_control^szEndpoint.send_channel_controlcKs|jj|fi|��dSr)r)�shutdown_endpoint)rrArrrrGcszEndpoint.shutdown_endpoint)rr$r%�__annotations__r*rr
rr1r2�strrr-�bytesr.r/r@rrBrFrGrrrrr';s
r'c@seZdZdd�ZdS)�RoutingErrorcKs||_||_dSr)�problemrA)rrLrArrrrhszRoutingError.__init__N)rr$r%rrrrrrKgsrKc@s@eZdZUded<dd�dd�Zeeed�dd�Zd	d
�Z	dS)�RoutingRuler(r)r+cCs
||_dSrr+r,rrrrpszRoutingRule.__init__��optionsr7cCst�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
        Nr8)rrOrrr�
apply_ruless	zRoutingRule.apply_rulecCst�dSrr8r0rrr�shutdown~szRoutingRule.shutdownN)
rr$r%rHrrrr'rPrQrrrrrMms
rMc@s�eZdZUeeed<eeefed<dZ	e
ed<eed�dd�Zeed�d	d
�Z
edd�d
d�Zedd�dd�Zeeeedd�dd�Zeeedd�dd�Zeedd�dd�Ze
d�dd�Zeedd�dd �ZdS)!r(�
routing_rules�
open_channelsF�_eof)rRcCs |D]
}||_q||_i|_dSr)r)rRrS)rrR�rulerrrr�szRouter.__init__rNcCsT|jD]6}t�d|�|�|�}|durt�d|�|Sqt�d�td��dS)Nz  applying rule %sz    resulting endpoint is %sz  No rules matchedz
not-supported)rRrr rPrK)rrOrU�endpointrrr�check_rules�s



zRouter.check_rulesN)r4r7cCs`z|j�|�t�d|�Wn"ty>t�d||j�Yn0|js\|jr\|jr\|j��dS)Nzrouter dropped channel %sz.trying to drop non-existent channel %s from %s)	rS�poprr �KeyError�errorrTZ	transportrC)rr4rrrrE�szRouter.drop_channel)rVr7csV�fdd�|j��D�}t�d�||�|D]$}|jfd|d�|��|�|�q,dS)Ncsh|]\}}|�kr|�qSrr)�.0�key�value�rVrr�	<setcomp>�rz+Router.shutdown_endpoint.<locals>.<setcomp>z'shutdown_endpoint(%s, %s) will close %srC�r5r4)rS�itemsrr rDrE)rrVrAZchannelsr4rr^rrG�s
zRouter.shutdown_endpointr=cCs<t|j���}t�d||t|��|D]}|�||�q&dS)Nz+do_kill(%s, %s).  Considering %d endpoints.)�setrS�valuesrr r!r/)rr>r?Z	endpointsrVrrrr/�szRouter.do_killr3c
Cs�|dkr�||jvrtd��z"t�d||�d��|�|�}WnBty~}z*|jfd||jd�|j	��WYd}~dSd}~00||j|<n$z|j|}Wnt
y�YdS0|�|||�dS)N�openzchannel is already openz5Trying to find endpoint for new channel %s payload=%sZpayloadrC)r5r4rL)rSrrr �getrWrKrDrLrArYr-)rr4r5r6rV�excrrr�channel_control_received�s
zRouter.channel_control_receivedr:cCs4z|j|}Wnty"YdS0|�||�dSr)rSrYr.)rr4r;rVrrr�channel_data_received�s
zRouter.channel_data_received)r7cCs<d|_t|j���D]\}}|�|dd|d��qt|j�S)NTrCr`)rT�listrSrar-�bool)rr4rVrrr�eof_received�szRouter.eof_received)rfr7cCs|jD]}|��qdSr)rRrQ)rrfrUrrr�	do_closed�s
zRouter.do_closed)rr$r%rrMrHrrIr'rTrjrrrWrErGrr/rgrJrhrk�	Exceptionrlrrrrr(�s
r()rZlogging�typingrrrZjsonutilrrZprotocolrr	Z	getLoggerrrr
r'rmrKrMr(rrrr�<module>s
,