관리-도구
편집 파일: client.cpython-311.pyc
� >u,g� � � � d dl Z d dlZd dlZd dlZd dlZd dlmZ ddlmZm Z m Z ddlmZm Z mZ dZdZdZd Z G d � d� � ZdS )� N)�Union� )�InvalidArgumentError�JsonRpcClientError�MethodNotFoundError)�Params� ParamsType�Payloadz/var/run/hc_mds/root_mds.socketz/var/run/hc_mds/user_mds.socketz$/var/cpanel/userdata/{}/hc_mds.tokenz2.0c �| � e Zd Z ddeedf deedf fd�Zedefd�� � Ze d� � � Z edefd�� � Ze defd �� � Zd edee df defd �Zededefd�� � Zededefd�� � Ze d� � � Zdedefd�Zededdfd�� � Zddee df d edefd�ZdS )�ClientN�socket_path�tokenc �0 � || _ || _ d | _ d S �N)�_socket_path�_token� _transport)�selfr r s �N/opt/cloudlinux/venv/lib/python3.11/site-packages/hc_json_rpc_client/client.py�__init__zClient.__init__ s � � (����������� �returnc �0 � t j � � dk S )Nr )�os�geteuid��clss r �is_rootzClient.is_root s � ��z�|�|�q� � r c �B � | j s�| � � � s~t t � t j � � � � dd�� � 5 }|� � � � � � | _ d d d � � n# 1 swxY w Y | j S )N�r�utf-8)�encoding) r r �open�DEFAULT_USER_TOKEN_FILE_FMT�format�getpass�getuser�read�strip)r �fs r r zClient.token s� � ��{� /�4�<�<�>�>� /��+�2�2�7�?�3D�3D�E�E�� �� � � /� ��f�f�h�h�n�n�.�.��� /� /� /� /� /� /� /� /� /� /� /���� /� /� /� /� �{�s �,B�B�Bc �F � | � � � rt S t S r )r �DEFAULT_ROOT_SOCKET_PATH�DEFAULT_USER_SOCKET_PATHr s r �_get_socket_pathzClient._get_socket_path* s � ��;�;�=�=� ,�+�+�'�'r c �P � | j s| � � � | _ | j S r )r r. �r s r r zClient.socket_path0 s* � �� � 8� $� 5� 5� 7� 7�D��� � r �method�paramsr c �4 � t |t � � st j |� � }n|� d�� � }| j |j _ t ||t t t j � � � � �� � � � � S )NT)�deep)r1 r2 �jsonrpc�id)� isinstancer � from_dict� model_copyr �metadatar �RPC_VERSION�int�time� model_dump)r r1 r2 �_paramss r �_prepare_payloadzClient._prepare_payload6 s� � � �&�&�)�)� 3��&�v�.�.�G�G��'�'�T�'�2�2�G�!%����������4�9�;�;��� � � � �*�,�,� r �payloadc �P � t j | � � � d� � S �Nr! )�json�dumps�encode�rA s r �_encode_jsonzClient._encode_jsonF s � ��z�'�"�"�)�)�'�2�2�2r c �P � t j | � d� � � � S rC )rD �loads�decoderG s r �_decode_jsonzClient._decode_jsonJ s � ��z�'�.�.��1�1�2�2�2r c � � | j sMt j t j t j � � | _ | j � | j � � | j S r )r �socket�AF_UNIX�SOCK_STREAM�connectr r0 s r � transportzClient.transportN sE � ��� 6�$�m�F�N�F�<N�O�O�D�O��O�#�#�D�$4�5�5�5���r c � � | j � | � |� � � � | j � d� � }| � |� � S )Ni )rR �sendallrH �recvrL )r rA �responses r �_executezClient._executeU sO � �����t�0�0��9�9�:�:�:��>�&�&�t�,�,��� � ��*�*�*r rV c �� � | � dd � � x}r]|d dk rt |d � � �|d dk rt |d � � �t | d d � � �d S )N�error�codei�����messagei����)�getr r r )rV rY s r �_validate_responsezClient._validate_responseZ s� � ��L�L��$�/�/�/�5� C��V�}��&�&�)�%� �*:�;�;�;��V�}��&�&�*�5��+;�<�<�<�$�X�g�%6�y�%A�B�B�B� C� Cr �eventc � � | � | � ||� � � � }| � |� � |S r )rW r@ r] )r r2 r1 rV s r �sendzClient.sendc s<