
    Vh                     L    d dl mZmZmZ eZd dlZd dlZd dlZddZ	ddZ
ddZy)	    )absolute_importdivisionprint_functionNc           	          	 t        | d      5 }|j                         cddd       S # 1 sw Y   yxY w# t        $ r7}| |j                  dj	                  | t        |                   Y d}~yd}~ww xY w)z*
    Load the file as a bytes string.
    rbNError while loading {0} - {1})openread	Exception	fail_jsonformatstr)pathmodulefexcs       l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/crypto/plugins/module_utils/io.py	load_filer      sn    Q$ 	668	 	 	 Q>8??c#hOPPQs(   4 (	4 14 4 	A4-A//A4c           	         	 t        | d      5 }|j                         cddd       S # 1 sw Y   yxY w# t        $ r`}|j                  t        j                  k(  rY d}~y|rY d}~y| |j                  dj                  | t        |                   Y d}~yd}~wt        $ r>}|rY d}~y| |j                  dj                  | t        |                   Y d}~yd}~ww xY w)a8  
    Load the file as a bytes string. If the file does not exist, ``None`` is returned.

    If ``ignore_errors`` is ``True``, will ignore errors. Otherwise, errors are
    raised as exceptions if ``module`` is not specified, and result in ``module.fail_json``
    being called when ``module`` is specified.
    r   Nr   )	r	   r
   EnvironmentErrorerrnoENOENTr   r   r   r   )r   r   ignore_errorsr   r   s        r   load_file_if_existsr      s    Q$ 	668	 	 	 Q99$>8??c#hOPP Q>8??c#hOPPQsF   4 (	4 14 4 	C"BB&-BC"$C+-CC"c                 
   	 | j                  | j                  |      }|d   ||d<   t        j                  d      \  }}	 t        j                  |       | j                  |       	 	 t        j                  |t
        j                  t
        j                  z  t
        j                  z  d      }t        j                  ||       t        j                  |       t
        j"                  j%                  |d         r| j'                  |d
       | j)                  t
        j"                  j+                  |      t
        j"                  j+                  |d                | j-                  |d         s| j'                  |d
       yy# t        $ r& | j                  | j                        }|||d<   Y w xY w# t        $ r Y nw xY w# t        $ rR}	 t        j                  |       n# t        $ r Y nw xY w| j                  dj!                  |      	       Y d}~Cd}~ww xY w# t        $ rQ}	 t        j                  |       n# t        $ r Y nw xY w| j                  dj!                  |      	       Y d}~yd}~ww xY w)zl
    Writes content into destination file as securely as possible.
    Uses file arguments from module.
    )r   Nr   modes   .ansible_tmp)prefixi  z3Error while writing result into temporary file: {0})msgFzError while writing result: {0})load_file_common_argumentsparams	TypeErrortempfilemkstemposcloser   add_cleanup_filer	   O_WRONLYO_CREATO_TRUNCwriteremover   r   r   existsset_fs_attributes_if_differentatomic_moveabspathcheck_file_absent_if_check_mode)	r   contentdefault_moder   	file_argstmp_fdtmp_namefilees	            r   
write_filer8   :   s:   %55fmm$5O	  (	&''?FH
 H%J	778R[[2::%=

%JERDHHT7#HHTN 77>>)F+,11)UCGGOOH%rwwy7H'I	
 55i6GH11)UC IK  % 55fmmD	 $If%    			(# IPPQRS   	$  J	IIh 		>EEaHIIJs   F F: +A2G
 B)H( +F76F7:	GG
	H%G*)H *	G63H 5G66$H H(  H%%H( (	J2II=	II=I$I==J)N)NF)NN)
__future__r   r   r   type__metaclass__r   r$   r"   r   r   r8        r   <module>r>      s2    A @   	 
QQ64Jr=   