
    Vh                     j    d dl mZmZmZ eZd dlmZmZ d dl	m
Z
 d dlmZ d dlmZmZ  G d de      Zy)	    )absolute_importdivisionprint_function)PIPEPopen)get_bin_path)	to_native)GPGError	GPGRunnerc                       e Zd ZddZddZy)PluginGPGRunnerNc                 l    |	 t        d      }|| _        || _        y # t        $ r t        d      w xY w)Ngpgz2Cannot find the `gpg` executable on the controller)r   
ValueErrorr
   
executablecwd)selfr   r   s      o/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/crypto/plugins/plugin_utils/gnupg.py__init__zPluginGPGRunner.__init__   sG    U)%0
 %  USTTUs    3c                    | j                   g|z   }t        |d| j                  t        t        t              }|j	                  |      \  }}t        |d      }t        |d      }|r\|j                  dk7  rMt        dj                  dj                  |      |j                  t        |d      t        |d      	            |j                  ||fS )
an  
        Run ``[gpg] + command`` and return ``(rc, stdout, stderr)``.

        If ``data`` is not ``None``, it will be provided as stdin.
        The code assumes it is a bytes string.

        Returned stdout and stderr are native Python strings.
        Pass ``check_rc=False`` to allow return codes != 0.

        Raises a ``GPGError`` in case of errors.
        F)shellr   stdinstdoutstderr)inputsurrogate_or_replace)errorsr   zVRunning {cmd} yielded return code {rc} with stdout: "{stdout}" and stderr: "{stderr}") )cmdrcr   r   )
r   r   r   r   communicater	   
returncoder
   formatjoin)r   commandcheck_rcdatapr   r   s          r   run_commandzPluginGPGRunner.run_command   s     ??#g-5dhhd4PT
 T26*@A6*@A)hoo)||$V4JK$V4JK	 p   ||VV++    )NN)TN)__name__
__module____qualname__r   r)    r*   r   r   r      s    ,r*   r   N)
__future__r   r   r   type__metaclass__
subprocessr   r   #ansible.module_utils.common.processr   +ansible.module_utils.common.text.convertersr	   Cansible_collections.community.crypto.plugins.module_utils.gnupg.clir
   r   r   r.   r*   r   <module>r6      s/    A @  " < A&,i &,r*   