
    Vh*                    $   d dl mZ dZd dlZd dlZd dlZd dlZd dlmZm	Z	 d dl
mZ d dlmZmZ d dlmZ d Zd	 Zd
 Z	 d dlmZ d dlmZ erd dlmZ nd dlmZ  G d de      Zd Z  G d de      Zy# e$ r dZd dlmZ  G d de      ZY )w xY w)    )annotationsa  
author: Unknown (!UNKNOWN)
name: yaml
type: stdout
short_description: YAML-ized Ansible screen output
deprecated:
  removed_in: 12.0.0
  why: Starting in ansible-core 2.13, the P(ansible.builtin.default#callback) callback has support for printing output in
    YAML format.
  alternative: Use O(ansible.builtin.default#callback:result_format=yaml).
description:
  - Ansible output that can be quite a bit easier to read than the default JSON formatting.
extends_documentation_fragment:
  - default_callback
requirements:
  - set as stdout in configuration
seealso:
  - plugin: ansible.builtin.default
    plugin_type: callback
    description: >-
      There is a parameter O(ansible.builtin.default#callback:result_format) in P(ansible.builtin.default#callback) that allows
      you to change the output format to YAML.
notes:
  - With ansible-core 2.13 or newer, you can instead specify V(yaml) for the parameter O(ansible.builtin.default#callback:result_format)
    in P(ansible.builtin.default#callback).
N)MappingSequence)to_text)strip_internal_keysmodule_response_deepcopy)CallbackModulec                    dD ]  }|| v s y y)z0Returns true if string should be in block formatu   
  TF )valuecs     k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/callback/yaml.pyshould_use_blockr   0   s     ? :     c                    | j                         } dj                  d | D              } | j                         } t        j                  dd|       } t        j                  dd|       } | S )N c              3  b   K   | ]'  }|t         j                  v st        |      d k\  s$| ) yw)   N)string	printableord).0xs     r   	<genexpr>z-adjust_str_value_for_block.<locals>.<genexpr>=   s'     P!V-=-=(=Q4APs   %//z[\x0b\x0c\r]z +\n
)rstripjoin
expandtabsresub)r   s    r   adjust_str_value_for_blockr!   8   sZ     LLNEGGPuPPEEFF?B.EFF7D%(ELr   c                    |t        |      rd}t        |      }n|}t        j                  j	                  | ||      S )N|)style)r   r!   yamlrepresenter
ScalarNode)tagr   r$   default_styles       r   create_string_noder*   G   sA    }E"E.u5E!E&&sE&??r   )HAS_LIBYAMLtransform_to_native_types)CSafeDumper)
SafeDumperc                      e Zd ZddZy)MyDumperNc                    t        |||| j                        }| j                  || j                  | j                  <   |S z'Uses block style for multi-line stringsr*   r)   	alias_keyrepresented_objectsselfr(   r   r$   nodes        r   represent_scalarzMyDumper.represent_scalar]   ;    %c5%9K9KLD~~);?((8Kr   N__name__
__module____qualname__r:   r   r   r   r1   r1   \       	r   r1   )AnsibleDumperc                      e Zd ZddZy)r1   Nc                    t        |||| j                        }| j                  || j                  | j                  <   |S r3   r4   r7   s        r   r:   zMyDumper.represent_scalarq   r;   r   r<   r=   r   r   r   r1   r1   p   rA   r   c                    t        | t              r0| j                         D ci c]  \  }} ||       ||       c}}S t        | t              r,t        | t        t
        f      s| D cg c]
  } ||       c}S  ||       S c c}}w c c}w r<   )
isinstancer   itemsr   strbytes)r   	transformkves        r   transform_recursivelyrN   y   st    %!7<{{}Etq!	!il*EE%":ec5\+J&+,	!,,U F,s   B+Bc                  <     e Zd ZdZdZdZdZ fdZddZd Z	 xZ
S )	r	   zs
    Variation of the Default output which uses nicely readable YAML instead
    of JSON for printing results.
    g       @stdoutzcommunity.general.yamlc                *    t         t        |           y r<   )superr	   __init__)r8   	__class__s    r   rS   zCallbackModule.__init__   s    nd,.r   c           
        |j                  dd      rt        j                  t        d            S t	        t        |            }|s | j                  j                  dk  rd|v r|d= | j                  j                  dk  rd|v r|d= d|v r|d= d	}d
|v r&|dt        |d
         j                          dz  }|d
= d|v r&|dt        |d         j                          dz  }|d= d|v r	d|v rd|d<   d|v r	d|v rd|d<   |rB|dz  }t        t        |d       }|t        t        j                  |ddt        d            z  }dj!                  |j#                  d            j%                         }|S )N_ansible_no_logFz\The output has been hidden due to the fact that 'no_log: true' was specified for this result)censored   
invocationdiff	exceptionr   changedzchanged= skippedzskipped=rP   stdout_linesz	<omitted>stderrstderr_linesr   c                    t        | d      S )NF)redactr,   )rL   s    r   <lambda>z.CallbackModule._dump_results.<locals>.<lambda>   s    Slmnw|S} r   T  allow_unicodewidthDumperdefault_flow_stylez
  )getjsondumpsdictr   r   _display	verbosityrH   lowerr-   rN   r   r%   dumpr1   r   splitr   )r8   resultindent	sort_keyskeep_invocationabridged_resultdumpeds          r   _dump_resultszCallbackModule._dump_results   s   ::'/::d  -K  L  M  M ..Fv.NO 4==#:#:Q#><SYCY- ==""Q&6V+;' /), '_Y%?!@!F!F!H IKKF	*'_Y%?!@!F!F!H IKKF	* &>_+L.9ON+ &>_+L.9ON+dNF(4"7I}"~gdiitSW`h  ~C  D  E  EF V\\$/0779r   c           	     P    t        t        j                  |ddt        d            S )NTre   Frf   )r   r%   rr   rB   )r8   rZ   s     r   _serialize_diffzCallbackModule._serialize_diff   s    tyyTmpuvwwr   )NTF)r>   r?   r@   __doc__CALLBACK_VERSIONCALLBACK_TYPECALLBACK_NAMErS   rz   r|   __classcell__)rT   s   @r   r	   r	      s+    
 M,M/.`xr   r	   )!
__future__r   DOCUMENTATIONr%   rl   r   r   collections.abcr   r   +ansible.module_utils.common.text.convertersr   ansible.plugins.callbackr   r    ansible.plugins.callback.defaultr	   Defaultr   r!   r*    ansible.module_utils.common.yamlr+   ansible.utils.varsr-   
yaml.cyamlr.   r/   r1   ImportErroransible.parsing.yaml.dumperrB   rN   r   r   r   <module>r      s    #6   	  - ? R F@%< =8#: :?xW ?x;   !%9= s   &A4 4BB