
                             S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	J
r
  SSK	Jr  SSKrSS	KJr   " S
 S\
R                  5      rg)zYAML format printer.    )absolute_import)division)unicode_literalsN)log)resource_printer_base)resource_transform)rangec                   f   ^  \ rS rSrSrU 4S jr " S S\R                  5      rS r	S	S jr
SrU =r$ )
YamlPrinter!   a  Prints the YAML representations of JSON-serializable objects.

[YAML](http://www.yaml.org), YAML ain't markup language.

Printer attributes:
  null="string": Display string instead of `null` for null/None values.
  no-undefined: Does not display resource data items with null values.
  version=VERSION: Prints using the specified YAML version, default 1.2.

For example:

  printer = YamlPrinter(log.out)
  printer.AddRecord({'a': ['hello', 'world'], 'b': {'x': 'bye'}})

produces:

  ---
  a:
    - hello
    - world
  b:
    - x: bye

Attributes:
  _yaml: Reference to the `yaml` module. Imported locally to improve startup
      performance.
c                   >^	^
 [         [        U ]
  " USS0UD6  SSKJm
  T
R                  SSS9U l        SU R                  l        [        R                  U R                  l
        SU R                  l        [        R                  U R                  l        U R                  R!                  S5      m	U R                  R!                  S	5      nU(       a  [#        U5      U R                  l        U
4S
 jnS nU	4S jnS nS nU R                  R&                  R)                  [*        U5        U R                  R&                  R)                  [        R,                  U5        U R                  R&                  R)                  S U5        U R                  R&                  R)                  [/        S 5      U5        U R                  R&                  R)                  [0        R2                  U5        g )Nretain_none_valuesTr   )yamlsafe)typpureFnullversionc                 d   > TR                   R                  S[        R                  " U5      5      $ )Nztag:yaml.org,2002:float)nodes
ScalarNoder   TransformFloat)unused_dumperdatar   s     0lib/googlecloudsdk/core/resource/yaml_printer.py_FloatPresenter-YamlPrinter.__init__.<locals>._FloatPresenterS   s-    ZZ""
#%7%F%Ft%LN N    c                 $    U R                  SUSS9$ )Ntag:yaml.org,2002:str|)stylerepresent_scalardumperr   s     r   _LiteralLinesPresenter4YamlPrinter.__init__.<locals>._LiteralLinesPresenterW   s    $$%<d#$NNr   c                 X   > TS;   a  U R                  SS5      $ U R                  ST5      $ )N)r   Nztag:yaml.org,2002:nullr   r    r#   )r&   unused_datar   s     r   _NullPresenter,YamlPrinter.__init__.<locals>._NullPresenterZ   s3    		&&'?HH$$%<dCCr   c                 B    U R                  SUR                  5       5      $ )Nztag:yaml.org,2002:map)represent_mappingitemsr%   s     r   _OrderedDictPresenter3YamlPrinter.__init__.<locals>._OrderedDictPresenter_   s    %%&=tzz|LLr   c                     [        U5      nUS:X  a  U R                  / 5      $ US:X  a  U R                  0 5      $ U R                  U5        g )Nz[]z{})reprrepresent_listrepresent_dictrepresent_undefined)r&   r   rs      r   _UndefinedPresenter1YamlPrinter.__init__.<locals>._UndefinedPresenterb   sI    
t*a	
d$$R((	
d$$R((  &r   )superr   __init__ruamelr   YAML_yamldefault_flow_styler   STRUCTURED_INDENTATION
old_indentallow_unicoder   LOG_FILE_ENCODINGencoding
attributesgetstrr   representeradd_representerfloat_LiteralLinestypecollectionsOrderedDict)selfargskwargsr   r   r'   r+   r0   r8   r   r   	__class__s            @@r   r;   YamlPrinter.__init__>   so   	+t%tOOO vD1DJ$)DJJ!1HHDJJ#DJJ//DJJ??v&Doo!!),Gw<djjNOD
M' 	JJ**5+:<JJ**;+D+D+ACJJ**4+>@JJ**4:+9;JJ**;+B+B+@Br   c                       \ rS rSrSrSrg)YamlPrinter._LiteralLinesu   z@A yaml representer hook for literal strings containing newlines. N)__name__
__module____qualname____firstlineno____doc____static_attributes__rW   r   r   rK   rU   u   s    Jr   rK   c                 j   SSK Jn  SSK Jn  [        U[        R
                  5      (       a  SU;   a  [        R                  U5      $ U" U5      (       a2  [        [        U5      5       H  nU R                  X   5      X'   M     U$ U" U5      (       a   U H  nU R                  X   5      X'   M     U$ U$ )zDig through a dict of list of primitives to help yaml output.

Args:
  val: A dict, list, or primitive object.

Returns:
  An updated version of val.
r   )	dict_like)	list_like
)googlecloudsdk.core.yamlr_   r`   
isinstancesixstring_typesr   rK   r	   len_UpdateTypesForOutput)rO   valr_   r`   ikeys         r   rg   !YamlPrinter._UpdateTypesForOutputx   s     32 #s''((TS[&&s++~~SX!++CF3 j~~#--ch7 jJr   c                    U R                   n[        R                  (       a>  [        U R                   [        R
                  5      (       a  [        R                  " 5       nU R                  U5      nX R                  l	        U R                  R                  UUS9  X0R                   LaG  U R                   R                  UR                  5       R                  [        R                  5      5        gg)zImmediately prints the given record as YAML.

Args:
  record: A YAML-serializable Python object.
  delimit: Prints resource delimiters if True.
)streamN)_outrd   PY2rc   ioStringIOBytesIOrg   r>   explicit_startdumpwritegetvaluedecoder   rC   )rO   recorddelimitrm   s       r   
_AddRecordYamlPrinter._AddRecord   s     YYF wwJtyy"++66zz|f''/F 'JJJJOO   YY
iioofoo'..s/D/DEF r   )r>   )T)rX   rY   rZ   r[   r\   r;   rd   	text_typerK   rg   rz   r]   __classcell__)rR   s   @r   r   r   !   s2    85BnKcmm K4G Gr   r   )r\   
__future__r   r   r   rM   rp   googlecloudsdk.corer   googlecloudsdk.core.resourcer   r   rd   	six.movesr	   ResourcePrinterr   rW   r   r   <module>r      s?      &  '  	 # > ; 
 CG'77 CGr   