
    )                        S 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KJr  SSK	J
r
  SS	KJr  SSKr \R                  rS
rSr\R&                  " \R(                  \R*                  R,                  R.                  \R*                  R0                  S9  \R&                  " \R(                  \R*                  R2                  R.                  \R*                  R4                  S9  \R&                  " \" S5      S \R*                  R4                  S9   " S S\R8                  5      r " S S\5      r " S S\5      rSSS\S4S jrS\S4S jr SS\S4S jr!\S4S jr"S!S jr#S"S jr$S"S jr%S r&S r'S r(S r)S  r*g! \ a    \r GNDf = f)#a  Wrapper module for ensuring consistent usage of yaml parsing.

This module forces parsing to use version 1.1 of the YAML spec if not
otherwise specified by the loading method arguments.
However, dumping uses version 1.2.
It also prevents use of unsafe loading and dumping.
    )absolute_import)division)unicode_literalsN)
exceptions)yaml_location_value)files)yamlz1.1z1.2)Dumperc                 &    U R                  SS5      $ )Nztag:yaml.org,2002:nullnull)represent_scalar)self_s     lib/googlecloudsdk/core/yaml.py<lambda>r   B   s    D))*BFK    c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )ErrorF   a  Top level error for this module.

Attributes:
  inner_error: Exception, The original exception that is being wrapped. This
    will always be populated.
  file: str, The path to the thing being loaded (if applicable). This is not
    necessarily a literal file (it could be a URL or any hint the calling
    code passes in). It should only be used for more descriptive error
    messages.
c                    > U(       a  SR                  U5      OSn[        [        U ]  SR                  X$U5      5        Xl        X0l        g )Nz
 from [{}] zFailed to {} YAML{}: {})formatsuperr   __init__inner_errorfile)r   everbf	file_text	__class__s        r   r   Error.__init__R   sA    *+##A&I	%!((!<>Ir   )r   r   N__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classcell__r!   s   @r   r   r   F   s    	 r   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )YAMLParseErrorZ   z,An error that wraps all YAML parsing errors.c                 ,   > [         [        U ]  USUS9  g )Nparser   r   )r   r.   r   r   r   r   r!   s      r   r   YAMLParseError.__init__]   s    	.$(A(>r    r#   r$   r,   s   @r   r.   r.   Z   s    4? ?r   r.   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )FileLoadErrora   z6An error that wraps errors when loading/reading files.c                 ,   > [         [        U ]  USUS9  g )Nloadr2   )r   r7   r   r3   s      r   r   FileLoadError.__init__d   s    	-'!'<r   r5   r$   r,   s   @r   r7   r7   a   s    >= =r   r7   Fc                      U(       a  [         R                  " U 5      $ U(       a  [        R                  O[        R                  n[        R
                  " XXES9$ ! [        R                   a  n[        XqS9eSnAff = f)a  Loads YAML from the given steam.

Args:
  stream: A file like object or string that can be read from.
  file_hint: str, The name of a file or url that the stream data is coming
    from. This is used for better error handling. If you have the actual file,
    you should use load_file() instead. Sometimes the file cannot be read
    directly so you can use a stream here and hint as to where the data is
    coming from.
  round_trip: bool, True to use the RoundTripLoader which preserves ordering
    and line numbers.
  location_value: bool, True to use a loader that preserves ordering and line
    numbers for all values. Each YAML data item is an object with value and lc
    attributes, where lc.line and lc.col are the line and column location for
    the item in the YAML source file.
  version: str, YAML version to use when parsing.
  preserve_quotes: bool, True preserve all the quotes.

Raises:
  YAMLParseError: If the data could not be parsed.

Returns:
  The parsed YAML data.
)versionpreserve_quotesr   N)r   LocationValueLoadr	   RoundTripLoader
SafeLoaderr:   	YAMLErrorr.   )stream	file_hint
round_triplocation_valuer=   r>   loaderr   s           r   r:   r:   h   sf    @) 226::%/T!!T__F99  
 )

(()s   A ;A A=/	A88A=c              #      #    U(       a  [         R                  O[         R                  n [         R                  " XUS9 H  nUv   M	     g! [         R                   a  n[        XaS9eSnAff = f7f)a  Loads multiple YAML documents from the given steam.

Args:
  stream: A file like object or string that can be read from.
  file_hint: str, The name of a file or url that the stream data is coming
    from. See load() for more information.
  version: str, YAML version to use when parsing.
  round_trip: bool, True to use the RoundTripLoader which preserves ordering
    and line numbers.

Raises:
  YAMLParseError: If the data could not be parsed.

Yields:
  The parsed YAML data.
)r=   r?   N)r	   rA   rB   load_allrC   r.   )rD   rE   r=   rF   rH   xr   s          r   rJ   rJ      sW     " $.44??&)]]67;g <	 )

(()s(   (A1 A A1A. 	A))A..A1c           
           [         R                  " U 5       n[        UU UUUUS9sSSS5        $ ! , (       d  f       g= f! [         R                   a  n[	        X`S9eSnAff = f)a  Loads YAML from the given file path.

Args:
  path: str, A file path to open and read from.
  round_trip: bool, True to use the RoundTripLoader which preserves ordering
    and line numbers.
  location_value: bool, True to use a loader that preserves ordering and line
    numbers for all values. Each YAML data item is an object with value and lc
    attributes, where lc.line and lc.col are the line and column location for
    the item in the YAML source file.
  version: str, YAML version to use when parsing.
  preserve_quotes: bool, True preserve all the quotes.

Raises:
  YAMLParseError: If the data could not be parsed.
  FileLoadError: If the file could not be opened or read.

Returns:
  The parsed YAML data.
)rE   rF   rG   r=   r>   Nr?   )r   
FileReaderr:   r   r7   )pathrF   rG   r=   r>   fpr   s          r   	load_pathrP      s]    6#			$	2
') 
 		 
 #

""#s.   A 0	A 
>A A A#	AA#c              #      #     [         R                  " U 5       n[        UU UUS9 H  nUv   M	     SSS5        g! , (       d  f       g= f! [         R                   a  n[	        XPS9eSnAff = f7f)a  Loads multiple YAML documents from the given file path.

Args:
  path: str, A file path to open and read from.
  version: str, YAML version to use when parsing.
  round_trip: bool, True to use the RoundTripLoader which preserves ordering
    and line numbers.

Raises:
  YAMLParseError: If the data could not be parsed.
  FileLoadError: If the file could not be opened or read.

Yields:
  The parsed YAML data.
)rE   r=   rF   Nr?   )r   rM   rJ   r   r7   )rN   r=   rF   rO   rK   r   s         r   load_all_pathrR      sh      
#			$	2"& '#-/! 	/ 
 		 
 # 
""#sG   A1A ;A A1
A	A A1	A A. 	A))A..A1c                 j    U(       a  [         R                  O[         R                  nU" U 4USSS.UD6$ )a  Dumps the given YAML data to the stream.

Args:
  data: The YAML serializable Python object to dump.
  stream: The stream to write the data to or None to return it as a string.
  round_trip: bool, True to use the RoundTripDumper which preserves ordering
    and line numbers if the yaml was loaded in round trip mode.
  **kwargs: Other arguments to the dump method.

Returns:
  The string representation of the YAML data if stream is None.
F   rD   default_flow_styleindent)r	   round_trip_dump	safe_dump)datarD   rF   kwargsmethods        r   dumpr]      s9     $.44>>&	 
Va 

 r   c                 8    [         R                  " U 4USSS.UD6$ )a@  Dumps multiple YAML documents to the stream.

Args:
  documents: An iterable of YAML serializable Python objects to dump.
  stream: The stream to write the data to or None to return it as a string.
  **kwargs: Other arguments to the dump method.

Returns:
  The string representation of the YAML data if stream is None.
FrT   rU   )r	   safe_dump_all	documentsrD   r[   s      r   dump_allrb     s2     
		
N5
NFL
N Nr   c                 V    [         R                  " U 4USS[         R                  S.UD6$ )aZ  Dumps multiple YAML documents to the stream using the RoundTripDumper.

Args:
  documents: An iterable of YAML serializable Python objects to dump.
  stream: The stream to write the data to or None to return it as a string.
  **kwargs: Other arguments to the dump method.

Returns:
  The string representation of the YAML data if stream is None.
FrT   )rD   rV   rW   r
   )r	   rb   RoundTripDumperr`   s      r   dump_all_round_tripre     s5     

-5!!
-%+
- -r   c                 B    [         R                  R                  U 5        g)a8  This processes the given dict or list so it will render as block text.

By default, the yaml dumper will write multiline strings out as a double
quoted string that just includes '\n'. Calling this on the data strucuture
will make it use the '|-' notation.

Args:
  data: {} or [], The data structure to process.
N)r	   scalarstring	walk_tree)rZ   s    r   convert_to_block_textri   #  s     d#r   c                 6    [        U [        R                  5      $ )z:Return True if the item is like a list: a MutableSequence.)
isinstancecollections_abcMutableSequenceitems    r   	list_likerp   0  s    	D/99	::r   c                 6    [        U [        R                  5      $ )z9Return True if the item is like a dict: a MutableMapping.)rk   rl   MutableMappingrn   s    r   	dict_likers   5  s    	D/88	99r   c                 J    [        U [        R                  R                  5      $ )z9Return True if the item is like a scalar: a ScalarString.)rk   r	   rg   ScalarStringrn   s    r   scalar_likerv   :  s    	D$++88	99r   c                    [        U 5      (       a  U  Vs/ s H  n[        U5      PM     sn$ [        U 5      (       a5  [        R                  " U 5       VVs0 s H  u  p#U[        U5      _M     snn$ U R
                  $ s  snf s  snnf r#   )rp   strip_locationsrs   six	iteritemsvalue)objro   keyr{   s       r   rx   rx   ?  sl    s^^.12cdOD!c22s^^:=--:LM:LJCC'':LMM	 3Ms   A>B)NFr#   )+r)   
__future__r   r   r   collectionsgooglecloudsdk.corer   r   googlecloudsdk.core.utilr   ruamelr	   ry   abcrl   AttributeErrorVERSION_1_1VERSION_1_2add_representerOrderedDictdumperSafeRepresenterrepresent_dict
SafeDumperRoundTripRepresenterrd   typer   r.   r7   r:   rJ   rP   rR   r]   rb   re   ri   rp   rs   rv   rx   r5   r   r   <module>r      s    '  '  * 3 *  
 OO/
    KK..;;!!#   KK$$33;;&&(   JK;;&&(J (?U ?=E = ()V  $[U )6 &#R !, #:$N- 
$;
:
:
o   / s   E; ;FF