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__/channel.cpython-39.opt-1.pyc
a

�/�hjW�@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�_PcsXeZdZUded<edd��fdd�Zdeed�d	d
�Zedd�d
d�Z	dd�Z
�ZS)�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__zCollection[tuple[str, object]])r�options�returncCs@|D]6\}}|�|�}|dur$dS|dur||krdSqdS)NFT)�get)r-rr1r$Zexpected_valueZ	our_valuer r r!�check_restrictions7s
z%ChannelRoutingRule.check_restrictionszChannel | None�r1r2cCsL|�d�}t|t�sdS|j�|g�D] }|�|j|�r&||j�Sq&dS)Nr))r3�
isinstance�strrr4rr)r-r1r)rr r r!�
apply_ruleHs

zChannelRoutingRule.apply_rulecCsdSrr �r-r r r!�shutdownUszChannelRoutingRule.shutdown)�__name__�
__module__�__qualname__�__annotations__rr'r�boolr4r8r:�
__classcell__r r r/r!r&s


rc@seZdZdS)�ChannelErrorN)r;r<r=r r r r!rAYsrAc@sNeZdZUdZdZdZeed<dZe	ed<eZ
e	ed<eed<d	ed
<dZded
<ded<dZded<dZ
dZeed<ded<eedd�dd�Zeeedd�dd�Zddedd�dd �Zedd!�d"d#�Zdd$�d%d&�Zdd$�d'd(�Zdd$�d)d*�Zedd+�d,d-�Zedd+�d.d/�Zedd0�d1d2�Zeedd3�d4d5�Zed6d0�d7d8�Zedd9�d:d;�Zdd<�eeed=�d>d?�Z dd$�d@dA�Z!ed$�dBdC�Z"dd$�dDdE�Z#dFdG�Z$dcdHdI�Z%dddddJ�dKdL�Z&eed0�dMdN�Z'eed0�dOdP�Z(eed0�dQdR�Z)dedeedS�dTdU�Z*dVdW�Z+dd$�dXdY�Z,e-j.dZd[�Z/d\ed]<eedd^�d_d`�Z0edd+�dadb�Z1dS)f�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]]]r��	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�grouprQZbinary�raw�ready�done�close�ping�pongr1)�setrGrrPrrCrrFrSrKrLZfreeze_endpoint�do_open�do_ready�do_done�do_close�do_ping�do_pong�
do_options)r-rMrNr r r!�
do_controlws.


zChannel.do_control)rPrMrNr2c
Cs�|jdurdSzLz|�||�Wn6tyV}ztdt|�d�|�WYd}~n
d}~00Wn2ty�}z|�|���WYd}~n
d}~00dS)N�protocol-error�rN)rIrbrrAr7rW�	get_attrs)r-rPrMrN�excr r r!�do_channel_control�s
,zChannel.do_channel_controlz
str | None)�hostrS�_messager2cCs<|jdurdS|durdS|dur0|j|kr0dS|��dSr)rIrSr^)r-rhrSrir r r!�do_kill�s
zChannel.do_killr5cCst�dSr��NotImplementedError�r-r1r r r!r[�szChannel.do_open�r2cCsdSrr r9r r r!r\�szChannel.do_readycCsdSrr r9r r r!r]�szChannel.do_donecCs|��dSr�rWr9r r r!r^�szChannel.do_close�rNr2cCstddd��dS)Nz
not-supportedz)This channel does not implement "options"rd)rA�r-rNr r r!ra�szChannel.do_optionscCs|�|�dSr)�	send_pongrqr r r!r_�szChannel.do_ping��datar2cCs|jr|jdt|�d�dS)NZack)rR)rF�send_controlr�r-rtr r r!�send_ack�szChannel.send_ack)rPrtr2c
Cs^|jdurdSz|�|�s$|�|�Wn2tyX}z|�|���WYd}~n
d}~00dSr)rI�do_datarwrArWre)r-rPrtrfr 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.Trorvr r r!rx�szChannel.do_data)�kwargsr2cKs |��|jfddi|��dS)NrMrU)Z
thaw_endpointru)r-rzr r r!rU�sz
Channel.ready��final)rtr|r2c
CsNz|jj||d�WStyH}ztdt|�d�|�WYd}~n
d}~00dS)Nr{rcrd)rL�decode�UnicodeDecodeErrorrAr7)r-rtr|rfr r r!Z__decode_frame�szChannel.__decode_framecCs(|jdur|jddd�|jdd�dS)Nr#Tr{rV)rM)rL�_Channel__decode_framerur9r r r!rV�s
zChannel.donecCs
|jduSr)rIr9r r r!�
is_closing�szChannel.is_closingcCs|�|j�dSr)Zshutdown_endpointrIr9r r r!�
_close_now�szChannel._close_nowcCs(|j�|�|jdur$|js$|��dSr)rG�removerIr�)r-�taskr r r!�
_task_done�szChannel._task_donecCs&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().
        )�asyncio�create_taskrG�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)rIrGr�)r-r�r r r!rW
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.
        rX)rM�sequence)	Zsend_channel_datarPrCrDrrB�
BLOCK_SIZErurE)r-rtZout_sequencer r r!�
send_bytesszChannel.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)rKr�rL�codecs�getincrementaldecoder�	send_textrrvr r r!�	send_data2s


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��encodervr r r!r�CszChannel.send_text)�msgrzr2cKs |j�t||��d}|�|�S)N�
)�json_encoderr�rr�)r-r�rzZprettyr r r!�	send_jsonJszChannel.send_jsoncCs@|jst�d|j�dS|dtj|_|j|jkr<|��dS)NzGot wild pong on channel %sr�)	rC�loggerZwarningrPrB�SEND_WINDOWrErD�do_resume_sendrqr r r!r`NszChannel.do_pongcCsdS)z<Called to indicate that the channel may start sending again.Nr r9r r r!r�WszChannel.do_resume_send�)�indentzClassVar[json.JSONEncoder]r�)rMrzr2cKs|j|j|dfi|��dSr�Zsend_channel_controlrP)r-rMrzr r r!ru]szChannel.send_controlcCs|�|jd|�dS)NrYr�rqr r r!rr`szChannel.send_pong)N)N)N)2r;r<r=r�r�rCr?r>rD�intrErIrrPrSr7rrbrgrjr[r\r]r^rar_rRrwryrxr
rUrrVr�r�r�r�rWr�r�r�r�r`r��jsonZJSONEncoderr�rurrr r r r!rB]sV
	
	rBc@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_pongsrH�
_last_pingz&asyncio.Task[asyncio.Transport] | None�_create_transport_task�_ready_infoF�
_close_on_eof�_eof)�loopr1r2c�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.
        Nrk)r-r�r1r r r!�create_transport{sz ProtocolChannel.create_transportr5cCs.t��}t�|�||��|_|j�|j�dSr)r��get_running_loopr�r�r�r��create_transport_done)r-r1r�r r r!r[�szProtocolChannel.do_openzasyncio.Task[asyncio.Transport])r�r2c
Cs|d|_z|��}Wn4tyF}z|�|���WYd}~dSd}~00|�|�|jdurp|jfi|j��n|��dSr)r��resultrArWre�connection_mader�rU)r-r��	transportrfr r r!r��s

z%ProtocolChannel.create_transport_done)r�r2cCs
||_dSr)r�)r-r�r r r!r��szProtocolChannel.connection_maderncCsiSrr r9r r r!�_get_close_args�szProtocolChannel._get_close_argszException | None)rfr2cCs|�|���dSr)rWr�)r-rfr r r!�connection_lost�szProtocolChannel.connection_lostrscCs|j�|�dSr)r��writervr r r!rx�szProtocolChannel.do_datacCs|j��r|j��dSr)r�Z
can_write_eofZ	write_eofr9r r r!r]�s
zProtocolChannel.do_donecCs|jdur|j��dSr)r�rWr9r r r!r^�s
zProtocolChannel.do_closec
CsPz|�|�s|j��Wn2tyJ}z|�|���WYd}~n
d}~00dSr)r�r�Z
pause_readingrArWre)r-rtrfr r r!�
data_received�s

zProtocolChannel.data_receivedcCs|j��dSr)r�Zresume_readingr9r r r!r��szProtocolChannel.do_resume_sendcCsd|_|jr|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�rWr9r r r!�close_on_eof�s
zProtocolChannel.close_on_eofcCsd|_|��|jS�NT)r�rVr�r9r r r!�eof_received�szProtocolChannel.eof_receivedcCs|jr|�|�n||_dSr)r�rrr�rqr r r!r_�szProtocolChannel.do_pingcCs
d|_dS)NF)r�r9r r r!�
pause_writing�szProtocolChannel.pause_writingcCs&d|_|jdur"|�|j�d|_dSr�)r�r�rrr9r r r!�resume_writing�s
zProtocolChannel.resume_writing)#r;r<r=�__doc__r�r>r�r?r�r�r�r�r�r��AbstractEventLooprZ	Transportr�r[r�Z
BaseTransportr�r�r�rRrxr]r^r�r�r�r�r_r�r�r r r r!r�ds0

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�NrHr5c�st�dSrrkrmr r r!�runszAsyncChannel.runc
�s�z$t��|_|�|�|�IdH�Wnrtjy@|��YnXtyp}z|�|���WYd}~n0d}~0ty�|�dt	�
�d���Yn0dS)Nzinternal-error)Zproblem�cause)r�r�r�rWr�ZCancelledErrorrAre�
BaseException�	traceback�
format_exc)r-r1rfr r r!�run_wrappers
"zAsyncChannel.run_wrapperzbytes | Nonernc�sF|j��IdH}|durdSt|t�r2|�|�q|�|�|SqdSr)r�r3r6rrrrw)r-�itemr r r!�reads

zAsyncChannel.readrsc�s&|�|�s"|j��|_|jIdHdSr)r�r�Z
create_future�write_waiterrvr r r!r� s
zAsyncChannel.writezCallable[_P, _T]z_P.argsz	_P.kwargsr)�fn�argsrzr2c�s"|jjd|g|�Ri|��IdHSr)r��run_in_executor)r-r�r�rzr r r!�	in_thread%szAsyncChannel.in_thread)�streamr2c�sf|�N|j�d|jtj�IdH}|dkr*q<|�|�IdHq|��Wd�n1sX0YdS)Nr#)r�r�r�rBr�r�rV)r-r�rtr r r!�sendfile(szAsyncChannel.sendfilecCs |jdur|j�d�d|_dSr)r�Z
set_resultr9r r r!r�2s
zAsyncChannel.do_resume_sendcCs4t��|_|j|�|�|jj�d|�d�d�|_dS)Nz
.run_wrapper(�))r�)r�ZQueuer�r�r�r0r;�	_run_taskrmr r r!r[7s
�zAsyncChannel.do_opencCs|j�d�dSr�r�Z
put_nowaitr9r r r!r]<szAsyncChannel.do_donecCs|j��dSr)r��cancelr9r r r!r^?szAsyncChannel.do_closerpcCs|j�|�dSrr�rqr r r!r_BszAsyncChannel.do_pingcCs|j�|�dSr�r�rvr r r!rxEszAsyncChannel.do_data)r;r<r=r�r>r�r�r�rr�r�r�rRr�r�rr�r�r[r]r^r_r?rxr 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__generatorr5cCst�dSrrkrmr r r!�
do_yield_dataSszGeneratorChannel.do_yield_dataNcCs|�|�|_|��dSr)r�r�r�rmr r r!r[VszGeneratorChannel.do_openrnc
CsTz|�t|j��rqWn8tyN}z |��|�|j�WYd}~n
d}~00dSr)r��nextr��
StopIterationrVrW�value)r-�stopr r r!r�ZszGeneratorChannel.do_resume_send)	r;r<r=r�r>rr�r[r�r r r r!r�Js

r�)+r�r�r�Zloggingr��typingrrrrrrrr	Zjsonutilrrr
rrrrZprotocolrrrrrZ	getLoggerr;r��
TYPE_CHECKING�TypeVarrZ	ParamSpecrrrArB�Protocolr�r�r�r r r r!�<module>s,($


3	d