%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3.9/site-packages/cockpit/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3.9/site-packages/cockpit/__pycache__/router.cpython-39.opt-1.pyc

a

��hP(�@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�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�<lambda>1�z&ExecutionQueue._wrap.<locals>.<lambda>)�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�run3s


zExecutionQueue.run)r�
__module__�__qualname__�__doc__rrr&rrrrrsrc@s�eZdZUded<dZeeed<dd�dd�Zdd�d	d
�Zdd�dd�Z	dd�d
d�Z
eeedd�dd�Z
eedd�dd�Zddedd�dd�Zeedd�dd�Zeededd�dd�Zd"dedd�d d!�ZdS)#�Endpoint�Router�routerN� _Endpoint__endpoint_frozen_queue�r,cCs|�|�||_dSr)�add_endpointr,�rr,rrrr@s
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_endpointDszEndpoint.freeze_endpointcCs t�d|�|j��d|_dS)NzThawing endpoint %s)r"r#r-r&r4rrr�
thaw_endpointIs
zEndpoint.thaw_endpointcCst�dSr��NotImplementedErrorr4rrr�do_closePszEndpoint.do_close��channel�command�messager!cCst�dSrr7)rr;r<r=rrrr1SszEndpoint.do_channel_control�r;�datar!cCst�dSrr7�rr;r?rrrr2VszEndpoint.do_channel_data�
str | None��host�groupr=r!cCst�dSrr7)rrCrDr=rrrr3YszEndpoint.do_killcCs|j�||�dSr)r,Zwrite_channel_datar@rrr�send_channel_data]szEndpoint.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_control`szEndpoint.send_channel_control)rGrHr!cKs|jj||fi|��dSr)r,�shutdown_endpoint)rrGrHrrrrOhszEndpoint.shutdown_endpoint)N)rr'r(�__annotations__r-rrrr5r6r9�strrr1�bytesr2r3rErrNrOrrrrr*<s
�r*c@seZdZdS)�RoutingErrorN)rr'r(rrrrrSlsrSc@sFeZdZUded<dd�dd�Zeeed�dd�Zd	d
�dd�Z	d	S)
�RoutingRuler+r,r.cCs
||_dSrr.r0rrrrsszRoutingRule.__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_rulevs	zRoutingRule.apply_ruleNr cCst�dSrr7r4rrr�shutdown�szRoutingRule.shutdown)
rr'r(rPrrrr*rWrXrrrrrTps
rTc@s*eZdZUeeed<eeefed<ded<e	j
ed<dZe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�szRouter.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|}Wnty�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�communicates�zRouter.communicate)N) rr'r(rrTrPrrQr*r]r^r\rprrrarcrMr/rrOr3rnrRrorqrrrZFuture�	Exceptionrsrwrrrrr+�s$

	r+)r]r
Zlogging�typingrrrZjsonutilrrZprotocolrr	r
Z	getLoggerrr"rr*rSrTr+rrrr�<module>s
0

Zerion Mini Shell 1.0