HEX
Server: Apache
System: Linux nc-ph-4101.simplemoneygoals.com 5.14.0-503.21.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Jan 12 09:45:05 EST 2025 x86_64
User: dailygoldindex (1004)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //lib64/python3.9/site-packages/lsm/__pycache__/_transport.cpython-39.opt-1.pyc
a

V��d��@s�ddlZddlZddlZddlZddlZddlmZmZddlmZ	ddl
mZddl
m
ZGdd�de�Zdd	�ZGd
d�dej�Zedkr�e��dS)
�N)�LsmError�ErrorNumber)�	SocketEOF)�DataDecoder)�DataEncoderc@s|eZdZdZdZdd�Zdd�Zdd�Zd	d
�Ze	dd��Z
d
d�Zdd�Zdd�Z
dd�Zddd�Zddd�Zdd�ZdS)�	TransPorta�
    Provides wire serialization by using json.  Loosely conforms to json-rpc,
    however a length header was added so that we would have the ability to use
    non sax like json parsers, which are more abundant.

    <Zero padded 10 digit number [1..2**32] for the length followed by
    valid json.

    Notes:
    id field (json-rpc) is present but currently not being used.
    This is available to be expanded on later.
    �
cCsT|dkrtd��t�}t|�|krJ|j�|t|��}|s@t��||7}q|�d�S)z�
        Reads l number of bytes before returning.  Will raise a SocketEOF
        if socket returns zero bytes (i.e. socket no longer connected)
        �z Trying to read less than 1 byte!�utf-8)�
ValueError�	bytearray�len�sZrecv�
_SocketEOF�decode)�self�l�data�r�r�4/usr/lib64/python3.9/site-packages/lsm/_transport.py�	_read_all#s
zTransPort._read_allcCsP|dust|�dkrtd��t�tt|��|j�|}|j�t|�d���dS)z]
        Sends the json formatted message by pre-appending the length
        first.
        Nr	zMsg argument emptyr
)	r
r�str�zfill�HDR_LENrZsendall�bytes�encode)r�msgrrrr�	_send_msg5szTransPort._send_msgc
Csxz|�|j�}|�t|��}WnTtjyV}zttjdt|���WYd}~n&d}~0t	yrttjd��Yn0|S)zk
        Reads header first to get the length and then the remaining
        bytes of the message.
        z.Error while reading a message from the plug-inNz3Error while reading a message from the plug-in, EOF)
rr�int�socket�errorrr�TRANSPORT_COMMUNICATIONrr)rZ	num_bytesr�errr�	_recv_msgCs��
zTransPort._recv_msgcCs
||_dS)N)r)rZsocket_descriptorrrr�__init__VszTransPort.__init__cCs�zZt�tjtj�}tj�|�rLt�|tjtjB�r>|�	|�qXt
tjd��nt
tj
d��Wn tjyzt
tjd��Yn0|S)zE
        Returns a connected socket from the passed in path.
        z-Permissions are incorrect for IPC socket filezPlug-in appears to not existz*Unable to connect to lsmd, daemon started?)r �AF_UNIX�SOCK_STREAM�os�path�exists�access�R_OK�W_OKZconnectrrZPLUGIN_SOCKET_PERMISSIONZPLUGIN_NOT_EXISTr!ZPLUGIN_IPC_FAIL)r)rrrr�
get_socketYs"���
zTransPort.get_socketcCs|j��dS)z@
        Closes the transport and the underlying socket
        N)r�close�rrrrr/rszTransPort.closec
Csfz(|d|d�}tj|td�}|�|�Wn8tjy`}zttjdt	|���WYd}~n
d}~00dS)z�
        Sends a request given a method and arguments.
        Note: arguments must be in the form that can be automatically
        serialized to json
        �d��method�id�params��clsz,Error while sending a message to the plug-inN)
�json�dumps�_DataEncoderrr r!rrr"r)rr3�argsrrZserrr�send_reqxs�zTransPort.send_reqcCs"|��}t|�rtj|td�SdS)zG
        Reads a message and returns the parsed version of it.
        r6N)r$r
r8�loads�_DataDecoder)rrrrr�read_req�szTransPort.read_reqcCs|�||�|��\}}|S)z;
        Sends a request and waits for a response.
        )r<�	read_resp)rr3r;�reply�msg_idrrr�rpc�sz
TransPort.rpcNcCs*||||d�d�}|�tj|td��dS)z,
        Used to transmit an error.
        )�code�messager)r4r!r6N�rr8r9r:)rrBZ
error_coderrr#rrr�
send_error�s��zTransPort.send_errorr1cCs"||d�}|�tj|td��dS)z-
        Used to transmit a response
        )r4�resultr6NrF)rrHrBrrrr�	send_resp�s
zTransPort.send_respcCsH|��}tj|td�}d|vr.|d|dfS|d}tfi|���dS)Nr6rHr4r!)r$r8r=r>r)rr�respr#rrrr@�szTransPort.read_resp)N)r1)�__name__�
__module__�__qualname__�__doc__rrrr$r%�staticmethodr.r/r<r?rCrGrIr@rrrrrs

		

rcCs�t|�}|��}zn|ddkrf|ddkrN|�|d|dd|dd�n|�|d�|��}q|�|d�W|��n
|��0dS)	z)
    Test echo server for test case.
    r3�doner!r4r5�	errorcode�errormsgN)rr?rGrIr/)rZsrvrrrr�_server�s
�
rSc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�_TestTransportcCsFt�tjtj�\|_|_t|j�|_tj	t
|jfd�|_|j��dS)N)�targetr;)
r Z
socketpairr&r'�crr�client�	threading�ThreadrS�server�startr0rrr�setUp�s�z_TestTransport.setUpcCsNgd�}|D]<}|j�d|�|j��\}}|�|dk�|�||k�qdS)N)�0� z   z{}:""zSome text messageZDEADBEEF�testr1)rWr<r@�
assertTrue)rZtc�trArBrrr�test_simple�sz_TestTransport.test_simplec
Cs�d}d}|j�d||d��|�t|jj�z"|j�d||d��|j��WnDty�}z,|�|j|k�|�|j|k�WYd}~n
d}~00dS)NzTest error messager1r!)rQrR)rWr<ZassertRaisesrr@r`rDr)rZe_msgZe_coder#rrr�test_exceptions�s�z_TestTransport.test_exceptionsc
Cs�tddd�D]�}d|}dd|d�}tj|td�}tt|��}|�tj�|}|�	t|�dk�|D]}|j
�t|d	��qd|j
��\}}	|�	||k�qdS)
Nr	ir�xZdripr1r2r6r
)�ranger8r9r:rr
rrrr`rV�sendrrWr@)
rrZpayloadrrZhdrZwire�irArBrrr�	test_slow�sz_TestTransport.test_slowcCsB|j�dd�|j��\}}|�|du�|j��|j��dS)NrP)rWr<r@r`rZ�joinr/)rrJrBrrr�tearDown
s

z_TestTransport.tearDownN)rKrLrMr\rbrcrhrjrrrrrT�s
		rT�__main__)r8r r(ZunittestrXZlsm._commonrrrrZ	lsm._datarr>rr:�objectrrSZTestCaserTrK�mainrrrr�<module>s'C