
    Vh                     P    d dl mZmZmZ eZd dlZ G d de      Z G d de      Z	y)    )absolute_importdivisionprint_functionNc                       e Zd Z e       ZddZd Zd Zd Zd Z	 e
ee      Z e
ee	      ZddddedfdZddZd	 Zd
 Ze
d        Ze
d        Zd Zy)	_VariableNc                     d| _         d | _        d | _        d | _        d | _        d | _        d | _        d | _        | j                  |||||       y )NF)outputdiffchangefact	verbosity)	initinitial_valuevaluer
   _changer	   r   
_verbosityset_meta)selfr
   r	   r   r   r   s         r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/module_utils/vardict.py__init__z_Variable.__init__   sR    	!
		V$vDT]^    c                 J    | j                   | j                  S | j                   S N)r   r
   r   s    r   	getchangez_Variable.getchange   s     LL0tyyBdllBr   c                     || _         y r   )r   r   r   s     r   	setchangez_Variable.setchange   s	    r   c                     | j                   S r   )r   r   s    r   getverbosityz_Variable.getverbosity"   s    r   c                 V    d|cxk  rdk  st        d       t        d      || _        y )Nr      z,verbosity must be an int in the range 0 to 4)
ValueErrorr   )r   vs     r   setverbosityz_Variable.setverbosity%   s1    Q!KLL KLLr   c                     ||| _         ||| _        ||| _        ||| _        |t        j
                  urt        j                  |      | _        ||| _	        yy)aQ  Set the metadata for the variable

        Args:
            output (bool, optional): flag indicating whether the variable should be in the output of the module. Defaults to None.
            diff (bool, optional): flag indicating whether to generate diff mode output for this variable. Defaults to None.
            change (bool, optional): flag indicating whether to track if changes happened to this variable. Defaults to None.
            fact (bool, optional): flag indicating whether the variable should be exposed as a fact of the module. Defaults to None.
            initial_value (any, optional): initial value of the variable, to be used with `change`. Defaults to NOTHING.
            verbosity (int, optional): level of verbosity in which this variable is reported by the module as `output`, `fact` or `diff`. Defaults to None.
        N)
r	   r   r
   r   r   NOTHINGcopydeepcopyr   r   )r   r	   r
   r   r   r   r   s          r   r   z_Variable.set_meta-   si      DK DKDIDI	 1 11!%}!=D &DN !r   c                     | j                   | j                  | j                  | j                  | j                  d}|s1t        j                  | j                        |d<   | j                  |d<   |S )N)r
   r   r	   r   r   r   r   )	r
   r   r	   r   r   r(   r)   r   r   )r   	meta_onlyds      r   as_dictz_Variable.as_dictE   s\    IIkkkkII
 !%t/A/A!BAoAgJr   c                 n    | j                   s!t        j                  |      | _        d| _         || _        | S )NT)r   r(   r)   r   r   r   s     r   	set_valuez_Variable.set_valueR   s-    yy!%u!5DDI
r   c                      | j                   |k  S r   )r   )r   r   s     r   
is_visiblez_Variable.is_visibleY   s    ~~**r   c                 P    | j                   xr | j                  | j                  k7  S r   )r   r   r   r   s    r   has_changedz_Variable.has_changed\   s     {{A 2 2djj @Ar   c                 f    | j                   r%| j                  r| j                  | j                  dS y )Nbeforeafter)r
   r3   r   r   r   s    r   diff_resultz_Variable.diff_result`   s)    99))"004::FFr   c                     dj                  | j                  | j                  | j                  | j                  | j
                  | j                        S )NzW<Variable: value={0!r}, initial={1!r}, diff={2}, output={3}, change={4}, verbosity={5}>)formatr   r   r
   r	   r   r   r   s    r   __str__z_Variable.__str__f   s?    hooJJ**DIIt{{DKKQUQ_Q_
 	
r   )FTNFr   )F)__name__
__module____qualname__objectr'   r   r   r   r    r%   propertyr   r   r   r-   r/   r1   r3   r8   r;    r   r   r   r      s    hG
_C
 i+F|4I"dU\hl '0+ B B  

r   r   c                        e Zd ZdZd Zd Zd Z fdZ fdZd Z	d Z
d	 Zd
 Zd ZddZddZddZed        Zd Z xZS )VarDict)__vars___varvarr   get_metasetr	   r
   factsr3   r-   c                 "    t               | _        y r   )dictrD   r   s    r   r   zVarDict.__init__o   s    r   c                 4    | j                   |   j                  S r   )rD   r   )r   items     r   __getitem__zVarDict.__getitem__r   s    }}T"(((r   c                 (    | j                  ||       y r   )rH   )r   keyr   s      r   __setitem__zVarDict.__setitem__u   s    er   c                     	 | j                   |   j                  S # t        $ r t        t	        t
        |       |      cY S w xY wr   )rD   r   KeyErrorgetattrsuperrC   )r   rM   	__class__s     r   __getattr__zVarDict.__getattr__x   s@    	7==&,,, 	75$/66	7s    #AAc                 ^    |dk(  rt         t        |   ||       y | j                  ||       y )NrD   )rU   rC   __setattr__rH   )r   rP   r   rV   s      r   rY   zVarDict.__setattr__~   s*    *'4,S%8HHS% r   c                      | j                   |   S r   )rD   r   names     r   rE   zVarDict._var   s    }}T""r   c                 @    | j                  |      j                         S r   rE   r-   r[   s     r   rF   zVarDict.var   s    yy&&((r   c                 F     | j                  |      j                  di | y)a  Set the metadata for the variable

        Args:
            name (str): name of the variable having its metadata changed
            output (bool, optional): flag indicating whether the variable should be in the output of the module. Defaults to None.
            diff (bool, optional): flag indicating whether to generate diff mode output for this variable. Defaults to None.
            change (bool, optional): flag indicating whether to track if changes happened to this variable. Defaults to None.
            fact (bool, optional): flag indicating whether the variable should be exposed as a fact of the module. Defaults to None.
            initial_value (any, optional): initial value of the variable, to be used with `change`. Defaults to NOTHING.
            verbosity (int, optional): level of verbosity in which this variable is reported by the module as `output`, `fact` or `diff`. Defaults to None.
        NrA   )rE   r   )r   r\   kwargss      r   r   zVarDict.set_meta   s     	!		$  *6*r   c                 D    | j                  |      j                  d      S )NT)r+   r^   r[   s     r   rG   zVarDict.get_meta   s    yy&&&66r   c                    || j                   v rt        dj                  |            || j                  v r$| j	                  |      } |j
                  di | nt        di |}|j                  |       || j                  |<   y)a  Set the value and optionally metadata for a variable. The variable is not required to exist prior to calling `set`.

        For details on the accepted metada see the documentation for method `set_meta`.

        Args:
            name (str): name of the variable being changed
            value (any): the value of the variable, it can be of any type

        Raises:
            ValueError: Raised if trying to set a variable with a reserved name.
        zName {0} is reservedNrA   )reserved_namesr#   r:   rD   rE   r   r   r/   )r   r\   r   r`   rF   s        r   rH   zVarDict.set   sz     4&&&3::4@AA4== ))D/CCLL"6"%f%Ce!dr   c                     | j                   j                         D ci c]1  \  }}|j                  s|j                  |      s%||j                  3 c}}S c c}}w r   )rD   itemsr	   r1   r   )r   r   nr$   s       r   r	   zVarDict.output   sA    '+}}':':'<etq!Q\\ZcMd177
eees   AAAc                 D   | j                   j                         D cg c]2  \  }}|j                  s|j                  |      s%||j                  f4 }}}|r5|D ci c]  \  }}||d    }}}|D ci c]  \  }}||d    }}}||dS y c c}}w c c}}w c c}}w )Nr6   r7   r5   )rD   re   r8   r1   )r   r   rf   r$   diff_resultsdrr6   r7   s           r   r
   zVarDict.diff   s    7;}}7J7J7Lztq!PQP]P]bcbnbnoxbyAMM*zz3?@%!RaHo@F@1=>2Q7^>E>$u55 {@>s   BBBB7Bc                     | j                   j                         D ci c]1  \  }}|j                  s|j                  |      s%||j                  3 }}}|r|S d S c c}}w r   )rD   re   r   r1   r   )r   r   rf   r$   facts_results        r   rI   zVarDict.facts   sV    /3}}/B/B/Dktq!STS_S_`iSj177
kk+|55 ls   AAAc                 V    t        d | j                  j                         D              S )Nc              3   4   K   | ]  }|j                     y wr   )r3   ).0rF   s     r   	<genexpr>z&VarDict.has_changed.<locals>.<genexpr>   s     Es3??Es   )anyrD   valuesr   s    r   r3   zVarDict.has_changed   s     Edmm.B.B.DEEEr   c                 ~    | j                   j                         D ci c]  \  }}||j                   c}}S c c}}w r   )rD   re   r   )r   r\   rF   s      r   r-   zVarDict.as_dict   s/    151D1D1FGID#ciiGGGs   9)r   )r<   r=   r>   rc   r   rN   rQ   rW   rY   rE   rF   r   rG   rH   r	   r
   rI   r@   r3   r-   __classcell__)rV   s   @r   rC   rC   l   si     EN)7!#)+7",f6 F FHr   rC   )

__future__r   r   r   type__metaclass__r(   r?   r   rC   rA   r   r   <module>rw      s5    A @ \
 \
~YHf YHr   