관리-도구
편집 파일: protocol.cpython-39.pyc
a ������g&����������������������@���s����d�dl�Z�d�dlZd�dlZd�dlZddlmZmZmZmZm Z m Z mZmZ�e� e�ZG�dd��de�ZG�dd��de�ZG�dd ��d e�j�ZG�d d��de�ZdS�)�����N����)� JsonError� JsonObject� JsonValue� create_object�get_int�get_str�get_str_or_none�typecheckedc�����������������������sF���e�Zd�ZU�dZeed<�dededd���fdd� Zed�d d �Z ���Z S�)�CockpitProblema���A type of exception that carries a problem code and a message. Depending on the scope, this is used to handle shutting down: - an individual channel (sends problem code in the close message) - peer connections (sends problem code in close message for each open channel) - the main stdio interaction with the bridge It is usually thrown in response to some violation of expected protocol when parsing messages, connecting to a peer, or opening a channel. �attrsN�JsonObject | None)�problem�msg�kwargs�returnc��������������������s.���||d<�t�||�|�_t���t|�jd|���d�S�)Nr����message)r���r����super�__init__r���)�selfr���r���r����� __class__���4/usr/lib/python3.9/site-packages/cockpit/protocol.pyr���*���s����zCockpitProblem.__init__�r���c�����������������C���sD���|�j�d�dkr:|�jd�ur:t|�j�t�|�jj|�j|�jj�d�S�|�j�S�d�S�)Nr���zinternal-error)�cause)r���� __cause__�dict� traceback�format_exceptionr���� __traceback__�r���r���r���r���� get_attrs/���s ���� �zCockpitProblem.get_attrs)N)�__name__� __module__�__qualname__�__doc__r����__annotations__�strr���r���r"���� __classcell__r���r���r���r���r������s��� r���c�����������������������s&���e�Zd�Zdeed���fdd� Z���ZS�)�CockpitProtocolError�protocol-error)r���r���c��������������������s���t���j||d��d�S�)N)r���)r���r���)r���r���r���r���r���r���r���9���s����zCockpitProtocolError.__init__)r+���)r#���r$���r%���r(���r���r)���r���r���r���r���r*���8���s���r*���c�������������������@���s8��e�Zd�ZU�dZdZded<�dZdZeed<�dZ ded <�dd �dd�Z d dd�dd�Zee dd�dd�Zeee dd�dd�Zeedd�dd�Zedd�dd�Zedd�dd�Zeed�d d!�Zejdd"�d#d$�Zd dd�d%d&�Zd4d dd�d'd(�Zeedd)�d*d+�Zd5d,edd-�d.d/�Zedd�d0d1�Zed �d2d3�ZdS�)6�CockpitProtocolz�A naive implementation of the Cockpit frame protocol We need to use this because Python's SelectorEventLoop doesn't supported buffered protocols. Nzasyncio.Transport | None� transport�����F�_closedzasyncio.Future[None] | None�_communication_doner���c�����������������C���s���d�S��Nr���r!���r���r���r����do_readyH���s����zCockpitProtocol.do_readyzException | None)�excr���c�����������������C���s���d�S�r1���r����r���r3���r���r���r���� do_closedK���s����zCockpitProtocol.do_closed��commandr���r���c�����������������C���s���t��d�S�r1�����NotImplementedError�r���r7���r���r���r���r����transport_control_receivedN���s����z*CockpitProtocol.transport_control_received)�channelr7���r���r���c�����������������C���s���t��d�S�r1���r8���)r���r<���r7���r���r���r���r����channel_control_receivedQ���s����z(CockpitProtocol.channel_control_received)r<����datar���c�����������������C���s���t��d�S�r1���r8���)r���r<���r>���r���r���r����channel_data_receivedT���s����z%CockpitProtocol.channel_data_received)�framer���c�����������������C���sP���|��d�\}}}|dkrB|�d�}t�dt|�|��|��||��n |��|��d�S�)N���� r.����asciiz.data received: %d bytes of data for channel %s)� partition�decode�logger�debug�lenr?����control_received)r���r@����header�_r>���r<���r���r���r����frame_receivedW���s���� zCockpitProtocol.frame_received)r>���r���c�������������� ���C���s����zft�t�|�t�}t|d�}t|dd��}|d�urLt�d|��|��|||��nt�d|��|��||��W�n:�tj t fy��}�ztd|���|�W�Y�d�}~n d�}~0�0�d�S�)Nr7���r<���zchannel control received %sztransport control received %szcontrol message: )r ����json�loadsr���r���rE���rF���r=���r;���ZJSONDecodeErrorr���r*���)r���r>���r���r7���r<���r3���r���r���r���rH���b���s���� z CockpitProtocol.control_receivedc�������������� ���C���s����z|��d�}W�nR�ty`�}�z:t|�dk�rBt|�d�W��Y�d}~S�td�|�W�Y�d}~n d}~0�0�zt|d|���}W�n.�ty��}�ztd�|�W�Y�d}~n d}~0�0�|d�}||�}|t|�kr�t|�|�S�|��|||����|S�)z�Consumes a single frame from view. Returns positive if a number of bytes were consumed, or negative if no work can be done because of a given number of bytes missing. rA���� ���Nzsize line is too longzframe size is not an integerr���)�index� ValueErrorrG���r*����intrK���)r���r>����newliner3����length�start�endr���r���r����consume_one_framer���s ���� z!CockpitProtocol.consume_one_frame)r-���r���c�����������������C���sF���t��d|��t|tj�sJ��||�_|�����|�jrBt��d��|����d�S�)Nzconnection_made(%s)z; but the protocol already was closed, so closing transport) rE���rF���� isinstance�asyncioZ Transportr-���r2���r/����close)r���r-���r���r���r����connection_made����s���� zCockpitProtocol.connection_madec�����������������C���s,���t��d��|�jd�usJ��d�|�_|��|��d�S�)N�connection_lost)rE���rF���r-���rY���r4���r���r���r���r[�������s���� zCockpitProtocol.connection_lostc�����������������C���s.���|�j�r d�S�d|�_�|�jr |�j����|��|��d�S�)NT)r/���r-���rY���r5���r4���r���r���r���rY�������s���� zCockpitProtocol.close)r<����payloadr���c�����������������C���sb���t�|d��t�|��}|��d|��d��d�}|�jdurTt�d|�j��|�j�||���n t�d��dS�)z0Send a given payload (bytes) on channel (string)� rB���Nzwriting to transport %sz cannot write to closed transport)rG����encoder-���rE���rF����write)r���r<���r\���Zframe_lengthrI���r���r���r����write_channel_data����s���� z"CockpitProtocol.write_channel_datar ���)r���r���r���c�����������������K���s:���t��d||��tjt||�dd�d�}|��d|�����dS�)zCWrite a control message. See jsonutil.create_object() for details.zsending control message %r %r����)�indentr]�����N)rE���rF���rL����dumpsr���r`���r^���)r���r���r���Zprettyr���r���r���� write_control����s����zCockpitProtocol.write_controlc�������������� ���C���sx���zD|��j�|7��_�|�j�rB|��|�j��}|dkr0W�d�S�|�j�|d���|�_�qW�n.�tyr�}�z|��|��W�Y�d�}~n d�}~0�0�d�S�)Nr���)�bufferrV���r*���rY���)r���r>����resultr3���r���r���r���� data_received����s����zCockpitProtocol.data_receivedc�����������������C���s���dS�)NFr���r!���r���r���r����eof_received����s����zCockpitProtocol.eof_received)N)N) r#���r$���r%���r&���r-���r'���rf���r/����boolr0���r2���r5���r(���r���r;���r=����bytesr?���rK���rH���rQ���rV���rX���Z BaseTransportrZ���r[���rY���r`���r���re���rh���ri���r���r���r���r���r,���=���s(��� r,���c�������������������@���s����e�Zd�ZU�dZded<�dZded<�dZdd�dd �Zedd �dd�Z ddedd �dd�Z eedd�dd�Zdd�dd�Z dedeed�dd�Zdedeed�dd�Zedd �dd�ZdS�)�CockpitProtocolServerNz str | None� init_hostz,dict[str, asyncio.Future[JsonObject]] | None�authorizationsr���r���c�����������������C���s���t��d�S�r1���r8���r!���r���r���r����do_send_init����s����z"CockpitProtocolServer.do_send_init)r���r���c�����������������C���s���d�S�r1���r���)r���r���r���r���r����do_init����s����zCockpitProtocolServer.do_init)�host�groupr���r���c�����������������C���s���t��d�S�r1���r8���)r���rq���rr���r���r���r���r����do_kill����s����zCockpitProtocolServer.do_killr6���c�����������������C���s����|dkr6t�|d�dkrtd��t|d�|�_|��|��nL|dkr^|��t|dd��t|dd��|��n$|dkrr|��|��ntd |��d ���d�S�)N�init�versionr���zincorrect version numberrq����killrr���� authorizezunexpected control message z received)r���r*���r���rm���rp���rs���r ����do_authorizer:���r���r���r���r;�������s���� z0CockpitProtocolServer.transport_control_receivedc�����������������C���s���|������d�S�r1���)ro���r!���r���r���r���r2�������s����zCockpitProtocolServer.do_readyz int | None)� challenge�timeoutr���r���c�������������� �������s����|�j�d�u�ri�|�_�t|�j�}|��jd7��_t������}zB||�j�|<�|�jdd||d�|���t�||�I�d�H�W�|�j��|��S�|�j��|��0�d�S�)Nr���rw���)r7���ry����cookie)N) rn���r(����next_auth_idrX���Zget_running_loopZ create_futurere����wait_for�pop)r���ry���rz���r���r{���Zfuturer���r���r����request_authorization_object����s���� �z2CockpitProtocolServer.request_authorization_objectc���������������������s ���t�|�j||fi�|��I�d�H�d�S�)NZresponse)r���r���)r���ry���rz���r���r���r���r����request_authorization����s����z+CockpitProtocolServer.request_authorizationc�����������������C���s@���t�|d�}|�jd�u�s||�jvr,t�d��d�S�|�j|��|��d�S�)Nr{���zno matching authorize request)r���rn���rE���ZwarningZ set_result)r���r���r{���r���r���r���rx�������s ���� z"CockpitProtocolServer.do_authorize)N)N)r#���r$���r%���rm���r'���rn���r|���ro���r���rp���rs���r(���r;���r2���r���r���r����rx���r���r���r���r���rl�������s&��� ������rl���)rX���rL���Zloggingr���Zjsonutilr���r���r���r���r���r���r ���r ���Z getLoggerr#���rE���� Exceptionr���r*����Protocolr,���rl���r���r���r���r����<module>���s���( �