관리-도구
편집 파일: channel.cpython-39.pyc
a ������gjW����������������������@���s(��d�dl�Z�d�dlZd�dlZd�dlZd�dlZd�dlZd�dlmZmZmZm Z m Z mZmZm Z �ddlmZmZmZmZmZmZmZ�ddlmZ�ddlmZmZmZ�e�e�Zejr�e� d�Z!e�"d�Z#G�d d ��d e�Z$G�dd��de�Z%G�d d��de�Z&G�dd��de&e�j'�Z(G�dd��de&�Z)G�dd��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�_Pc�����������������������sX���e�Zd�ZU�ded<�edd���fdd�Zdeed�d d �Zedd�d d�Z dd��Z ���ZS�)�ChannelRoutingRulezdict[str, list[Type[Channel]]]�tablezCollection[Type[Channel]])�router� channel_typesc��������������������s\���t����|��i�|�_|D�]}|�j�|jg��}|�|��q|�j���D�]}|jdd��dd��q@d�S�)Nc�����������������S���s ���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)�selfr���r���r����entry�� __class__r ���r!���r'���)���s����zChannelRoutingRule.__init__zCollection[tuple[str, object]])r����options�returnc�����������������C���s@���|D�]6\}}|��|�}|d�u�r$�dS�|d�ur||kr�dS�qdS�)NFT)�get)r-���r���r1���r$���Zexpected_valueZ our_valuer ���r ���r!����check_restrictions7���s���� z%ChannelRoutingRule.check_restrictionszChannel | None�r1���r2���c�����������������C���sZ���|�j�d�usJ��|�d�}t|t�s&d�S�|�j�|g��D�] }|��|j|�r4||�j����S�q4d�S�)Nr)���)r���r3���� isinstance�strr���r4���r���)r-���r1���r)���r���r ���r ���r!���� apply_ruleH���s���� zChannelRoutingRule.apply_rulec�����������������C���s���d�S�r���r ����r-���r ���r ���r!����shutdownU���s����zChannelRoutingRule.shutdown)�__name__� __module__�__qualname__�__annotations__r���r'���r����boolr4���r8���r:���� __classcell__r ���r ���r/���r!���r���&���s ��� r���c�������������������@���s���e�Zd�ZdS�)�ChannelErrorN)r;���r<���r=���r ���r ���r ���r!���rA���Y���s���rA���c�������������������@���sN��e�Zd�ZU�dZdZdZeed<�dZe ed<�eZ e ed<�eed<�d ed <�dZded <�ded<�dZded<�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%dddddJ�dKdL�Z&eed0�dMdN�Z'eed0�dOdP�Z(eed0�dQdR�Z)dedeedS�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�messager2���c�����������������C���s����|dkr�t���|�_t|d�|�_t|ddd�r0d|�_t|ddgd��d�u|�_t|d d �|�_t|ddgd��d�u|�_ d�|�_ |�����|��|��np|d kr�|�� ���n^|dkr�|�����nL|dkr�|�����n:|dkr�|��|��n&|dkr�|��|��n|dkr�|��|��d�S�)N�open�channelzflow-controlF)�defaultTz send-acks�bytes�grouprQ���Zbinary�raw�ready�done�close�ping�pongr1���)�setrG���r���rP���r���rC���r���rF���rS���rK���rL���Zfreeze_endpoint�do_open�do_ready�do_done�do_close�do_ping�do_pong� do_options)r-���rM���rN���r ���r ���r!���� do_controlw���s.���� zChannel.do_control)rP���rM���rN���r2���c�������������� ���C���s����|�j�d�urd�S�zLz|��||��W�n6�tyV�}�ztdt|�d�|�W�Y�d�}~n d�}~0�0�W�n2�ty��}�z|��|�����W�Y�d�}~n d�}~0�0�d�S�)N�protocol-error�rN���)rI���rb���r���rA���r7���rW���� get_attrs)r-���rP���rM���rN����excr ���r ���r!����do_channel_control����s���� ,zChannel.do_channel_controlz str | None)�hostrS����_messager2���c�����������������C���s<���|�j�d�urd�S�|d�urd�S�|d�ur0|�j|kr0d�S�|�����d�S�r���)rI���rS���r^���)r-���rh���rS���ri���r ���r ���r!����do_kill����s���� zChannel.do_killr5���c�����������������C���s���t��d�S�r�����NotImplementedError�r-���r1���r ���r ���r!���r[�������s����zChannel.do_open�r2���c�����������������C���s���d�S�r���r ���r9���r ���r ���r!���r\�������s����zChannel.do_readyc�����������������C���s���d�S�r���r ���r9���r ���r ���r!���r]�������s����zChannel.do_donec�����������������C���s���|������d�S�r����rW���r9���r ���r ���r!���r^�������s����zChannel.do_close�rN���r2���c�����������������C���s���t�ddd��d�S�)Nz not-supportedz)This channel does not implement "options"rd���)rA����r-���rN���r ���r ���r!���ra�������s����zChannel.do_optionsc�����������������C���s���|���|��d�S�r���)� send_pongrq���r ���r ���r!���r_�������s����zChannel.do_ping��datar2���c�����������������C���s���|�j�r|�jdt|�d��d�S�)NZack)rR���)rF����send_controlr����r-���rt���r ���r ���r!����send_ack����s����zChannel.send_ack)rP���rt���r2���c�������������� ���C���s^���|�j�d�urd�S�z|��|�s$|��|��W�n2�tyX�}�z|��|�����W�Y�d�}~n d�}~0�0�d�S�r���)rI����do_datarw���rA���rW���re���)r-���rP���rt���rf���r ���r ���r!����do_channel_data����s���� zChannel.do_channel_datazbool | Nonec�����������������C���s���~|������dS�)a��Handles 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.Tro���rv���r ���r ���r!���rx�������s����zChannel.do_data)�kwargsr2���c�����������������K���s ���|������|�jf�ddi|���d�S�)NrM���rU���)Z thaw_endpointru���)r-���rz���r ���r ���r!���rU�������s����z Channel.ready��final)rt���r|���r2���c������������� ���C���s\���|�j�d�usJ��z|�j�j||d�W�S��tyV�}�ztdt|�d�|�W�Y�d�}~n d�}~0�0�d�S�)Nr{���rc���rd���)rL����decode�UnicodeDecodeErrorrA���r7���)r-���rt���r|���rf���r ���r ���r!���Z__decode_frame����s ����zChannel.__decode_framec�����������������C���s(���|�j�d�ur|�jddd��|�jdd��d�S�)Nr#���Tr{���rV���)rM���)rL����_Channel__decode_frameru���r9���r ���r ���r!���rV�������s���� zChannel.donec�����������������C���s ���|�j�d�uS�r���)rI���r9���r ���r ���r!���� is_closing����s����zChannel.is_closingc�����������������C���s���|���|�j��d�S�r���)Zshutdown_endpointrI���r9���r ���r ���r!���� _close_now����s����zChannel._close_nowc�����������������C���s(���|�j��|��|�jd�ur$|�j�s$|�����d�S�r���)rG����removerI���r����)r-����taskr ���r ���r!���� _task_done����s����zChannel._task_donec�����������������C���s4���|�j�du�sJ��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)rI����asyncio�create_taskrG����add�add_done_callbackr����)r-���� coroutine�namer����r ���r ���r!���r��������s ���� zChannel.create_task)� close_argsr2���c�����������������C���s*���|�j�durdS�|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)rI���rG���r����)r-���r����r ���r ���r!���rW��� ��s ���� z Channel.closec�����������������C���sX���|���|�j|��|�jrL|�jt|��}|�jtj�|tj�krF|�jd|d��||�_|�j|�jk�S�)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_datarP���rC���rD���r���rB���� BLOCK_SIZEru���rE���)r-���rt���Zout_sequencer ���r ���r!���� send_bytes��s����zChannel.send_bytesc�����������������C���s<���|�j�r|��|�S�|�jdu�r,t�d�dd�|�_|��|��|��S�)aD��Send 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)rK���r����rL����codecs�getincrementaldecoder� send_textr���rv���r ���r ���r!���� send_data2��s ���� zChannel.send_datac�����������������C���s���|���|����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�����encoderv���r ���r ���r!���r����C��s����zChannel.send_text)�msgrz���r2���c�����������������K���s ���|�j��t||��d�}|��|�S�)N� )�json_encoderr����r���r����)r-���r����rz���Zprettyr ���r ���r!���� send_jsonJ��s����zChannel.send_jsonc�����������������C���s@���|�j�st�d|�j��d�S�|d�tj�|�_|�j|�jk�r<|�����d�S�)NzGot wild pong on channel %sr����) rC����loggerZwarningrP���rB����SEND_WINDOWrE���rD����do_resume_sendrq���r ���r ���r!���r`���N��s����zChannel.do_pongc�����������������C���s���dS�)z<Called to indicate that the channel may start sending again.Nr ���r9���r ���r ���r!���r����W��s����zChannel.do_resume_send����)�indentzClassVar[json.JSONEncoder]r����)rM���rz���r2���c�����������������K���s���|�j�|�j|d�fi�|���d�S�r����Zsend_channel_controlrP���)r-���rM���rz���r ���r ���r!���ru���]��s����zChannel.send_controlc�����������������C���s���|���|�jd|��d�S�)NrY���r����rq���r ���r ���r!���rr���`��s����zChannel.send_pong)N)N)N)2r;���r<���r=���r����r����rC���r?���r>���rD����intrE���rI���r���rP���rS���r7���r���rb���rg���rj���r[���r\���r]���r^���ra���r_���rR���rw���ry���rx���r ���rU���r���rV���r����r����r����r����rW���r����r����r����r����r`���r�����jsonZJSONEncoderr����ru���rr���r ���r ���r ���r!���rB���]���sV��� rB���c�������������������@���sV��e�Zd�ZU�dZdZded<�dZeed<�dZded<�dZ d ed <�dZ ded<�dZeed <�dZeed<�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)�loopr1���r2���c���������������������s���t��dS�)a��Creates 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����r1���r ���r ���r!����create_transport{��s����z ProtocolChannel.create_transportr5���c�����������������C���s.���t����}t��|��||��|�_|�j�|�j��d�S�r���)r�����get_running_loopr����r����r����r�����create_transport_done)r-���r1���r����r ���r ���r!���r[������s����zProtocolChannel.do_openzasyncio.Task[asyncio.Transport])r����r2���c�������������� ���C���s����||�j�u�sJ��d�|�_�z|���}W�n4�tyT�}�z|��|�����W�Y�d�}~d�S�d�}~0�0�|��|��|�jd�ur~|�jf�i�|�j���n|�����d�S�r���)r�����resultrA���rW���re����connection_mader����rU���)r-���r����� transportrf���r ���r ���r!���r�������s���� z%ProtocolChannel.create_transport_done)r����r2���c�����������������C���s���t�|tj�sJ��||�_d�S�r���)r6���r����� Transportr����)r-���r����r ���r ���r!���r�������s����zProtocolChannel.connection_madern���c�����������������C���s���i�S�r���r ���r9���r ���r ���r!����_get_close_args���s����zProtocolChannel._get_close_argszException | None)rf���r2���c�����������������C���s���|���|������d�S�r���)rW���r����)r-���rf���r ���r ���r!����connection_lost���s����zProtocolChannel.connection_lostrs���c�����������������C���s���|�j�d�usJ��|�j��|��d�S�r���)r�����writerv���r ���r ���r!���rx������s����zProtocolChannel.do_datac�����������������C���s&���|�j�d�usJ��|�j����r"|�j�����d�S�r���)r����Z can_write_eofZ write_eofr9���r ���r ���r!���r]������s���� zProtocolChannel.do_donec�����������������C���s���|�j�d�ur|�j�����d�S�r���)r����rW���r9���r ���r ���r!���r^������s���� zProtocolChannel.do_closec�������������� ���C���s^���|�j�d�usJ��z|��|�s$|�j�����W�n2�tyX�}�z|��|�����W�Y�d�}~n d�}~0�0�d�S�r���)r����r����Z pause_readingrA���rW���re���)r-���rt���rf���r ���r ���r!���� data_received���s���� zProtocolChannel.data_receivedc�����������������C���s���|�j�d�usJ��|�j�����d�S�r���)r����Zresume_readingr9���r ���r ���r!���r�������s����zProtocolChannel.do_resume_sendc�����������������C���s(���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����rW���r9���r ���r ���r!����close_on_eof���s���� zProtocolChannel.close_on_eofc�����������������C���s���d|�_�|�����|�j�S��NT)r����rV���r����r9���r ���r ���r!����eof_received���s����zProtocolChannel.eof_receivedc�����������������C���s���|�j�r|��|��n||�_d�S�r���)r����rr���r����rq���r ���r ���r!���r_������s����zProtocolChannel.do_pingc�����������������C���s ���d|�_�d�S�)NF)r����r9���r ���r ���r!���� pause_writing���s����zProtocolChannel.pause_writingc�����������������C���s&���d|�_�|�jd�ur"|��|�j��d�|�_d�S�r����)r����r����rr���r9���r ���r ���r!����resume_writing���s���� zProtocolChannel.resume_writing)#r;���r<���r=����__doc__r����r>���r����r?���r����r����r����r����r����r�����AbstractEventLoopr���r����r����r[���r����Z BaseTransportr����r����r����rR���rx���r]���r^���r����r����r����r����r_���r����r����r ���r ���r ���r!���r����d��s0��� r����c�������������������@���s����e�Zd�ZU�dZded<�ejed<�dZedd�dd �Z edd�d d�Z dd �dd�Zedd�dd�Z ddddd�dd�Zedd�dd�Zdd �dd�Zedd�dd �Zdd �d!d"�Zdd �d#d$�Zedd%�d&d'�Zeed�d(d)�ZdS�)*�AsyncChannelaA��A 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����NrH���r5���c���������������������s���t��d�S�r���rk���rm���r ���r ���r!����run��s����zAsyncChannel.runc�������������� �������s����z$t����|�_|��|��|�I�d�H���W�nr�t�jy@���|�����Y�nX�typ�}�z|��|�����W�Y�d�}~n0d�}~0��ty����|��dt � ��d�����Y�n0�d�S�)Nzinternal-error)Zproblem�cause)r����r����r����rW���r����ZCancelledErrorrA���re���� BaseException� traceback� format_exc)r-���r1���rf���r ���r ���r!����run_wrapper��s���� "zAsyncChannel.run_wrapperzbytes | Nonern���c���������������������sF���|�j����I�d�H�}|d�u�rd�S�t|t�r2|��|��q�|��|��|S�q�d�S�r���)r����r3���r6���r���rr���rw���)r-����itemr ���r ���r!����read��s���� zAsyncChannel.readrs���c���������������������s&���|���|�s"|�j���|�_|�jI�d�H��d�S�r���)r����r����Z create_future�write_waiterrv���r ���r ���r!���r���� ��s���� zAsyncChannel.writezCallable[_P, _T]z_P.argsz _P.kwargsr���)�fn�argsrz���r2���c���������������������s"���|�j�jd�|g|�R�i�|��I�d�H�S�r���)r�����run_in_executor)r-���r����r����rz���r ���r ���r!���� in_thread%��s����zAsyncChannel.in_thread)�streamr2���c���������������������sf���|�N�|�j��d�|jtj�I�d�H�}|dkr*q<|��|�I�d�H��q|�����W�d�����n1�sX0����Y��d�S�)Nr#���)r����r����r����rB���r����r����rV���)r-���r����rt���r ���r ���r!����sendfile(��s����zAsyncChannel.sendfilec�����������������C���s ���|�j�d�ur|�j��d���d�|�_�d�S�r���)r����Z set_resultr9���r ���r ���r!���r����2��s���� zAsyncChannel.do_resume_sendc�����������������C���s4���t����|�_|�j|��|�|�jj��d|��d�d�|�_d�S�)Nz .run_wrapper(�))r����)r����ZQueuer����r����r����r0���r;���� _run_taskrm���r ���r ���r!���r[���7��s���� �zAsyncChannel.do_openc�����������������C���s���|�j��d���d�S�r����r����Z put_nowaitr9���r ���r ���r!���r]���<��s����zAsyncChannel.do_donec�����������������C���s���|�j�����d�S�r���)r�����cancelr9���r ���r ���r!���r^���?��s����zAsyncChannel.do_closerp���c�����������������C���s���|�j��|��d�S�r���r����rq���r ���r ���r!���r_���B��s����zAsyncChannel.do_pingc�����������������C���s���|�j��|��dS�r����r����rv���r ���r ���r!���rx���E��s����zAsyncChannel.do_data)r;���r<���r=���r����r>���r����r����r����r���r����r����r����rR���r����r����r���r����r����r[���r]���r^���r_���r?���rx���r ���r ���r ���r!���r�������s ��� r����c�������������������@���sH���e�Zd�ZU�dZded<�edd�dd�Zedd�dd �Zdd �dd�ZdS�) �GeneratorChannela��A 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__generatorr5���c�����������������C���s���t��d�S�r���rk���rm���r ���r ���r!���� do_yield_dataS��s����zGeneratorChannel.do_yield_dataNc�����������������C���s���|���|�|�_|�����d�S�r���)r����r����r����rm���r ���r ���r!���r[���V��s����zGeneratorChannel.do_openrn���c�������������� ���C���sT���z|���t|�j��rqW�n8�tyN�}�z |�����|��|j��W�Y�d�}~n d�}~0�0�d�S�r���)r�����nextr����� StopIterationrV���rW����value)r-����stopr ���r ���r!���r����Z��s����zGeneratorChannel.do_resume_send) r;���r<���r=���r����r>���r���r����r[���r����r ���r ���r ���r!���r����J��s ��� r����)+r����r����r����Zloggingr�����typingr���r���r���r���r���r���r���r ���Zjsonutilr���r���r ���r���r���r���r���Zprotocolr���r���r���r���r���Z getLoggerr;���r����� TYPE_CHECKING�TypeVarr���Z ParamSpecr���r���rA���rB����Protocolr����r����r����r ���r ���r ���r!����<module>���s,���($ 3�� �d