
                         |   S 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 " S S\R                  R                  5      r
 " S	 S
\R                  R                  5      r " S S\R                  R                  5      r " S S\R                  R                  5      r " S S\R"                  R$                  5      rS rg)a  Module for loading location/value YAML objects.

ruamel round trip loading splices, if possible, an lc attribute to each
data item, where lc.line and lc.col are the YAML source line and column for the
data. "if possible" leaves a lot to be desired. Without Python shenanigans it
does not work for str, bool, int or float values. Shenanigans only get str
values to work.

The location/value loader defined here effectively subclasses the following
object in every data item:

  Attributes:
    value: The data value.
    lc.line: The data value YAML source line.
    lc.col: The data value YAML source column.

"effectively" because we do similar Python shenanigans when it's easy.
    )absolute_import)division)unicode_literals)yamlNc                   &    \ rS rSrSrSrSrS rSrg)	_LvString,   zLocation/value string type.lcvalue c                 T    [         R                  R                  R                  X5      $ N)r   scalarstringScalarString__new__)clsr   s     .lib/googlecloudsdk/core/yaml_location_value.pyr   _LvString.__new__2   s    ))11#==     N)	__name__
__module____qualname____firstlineno____doc__	__slots__styler   __static_attributes__r   r   r   r   r   ,   s    #)
%>r   r   c                       \ rS rSrSrSrSrg)_LvPreservedScalarString6   z,Location/value preserved scalar string type.r
   r   Nr   r   r   r   r   r   r   r   r   r   r!   r!   6   s
    4)r   r!   c                       \ rS rSrSrSrSrg)_LvDoubleQuotedScalarString<   z0Location/value double quoted scalar string type.r
   r   Nr#   r   r   r   r%   r%   <   
    8)r   r%   c                       \ rS rSrSrSrSrg)_LvSingleQuotedScalarStringB   z0Location/value single quoted scalar string type.r
   r   Nr#   r   r   r   r)   r)   B   r'   r   r)   c                      ^  \ rS rSrSrSrU 4S jr\S 5       rS r	SS jr
S rS	 rS
 rS rS rU 4S jrU 4S jrU 4S jrSrU =r$ )_LvObjectConstructorH   zLocation/value object constructor that works for all types.

The object has these attributes:
  lc.line: The start line of the value in the input file.
  lc.col: The start column of the value in the input file.
  value: The value.
Fc                 N   > [         [        U ]
  " U0 UD6  U R                  5         g r   )superr,   __init___Initialize)selfargskwargs	__class__s      r   r0   _LvObjectConstructor.__init__S   s$    	
.??r   c                    U R                   (       d  SU l         U R                  SU R                  5        U R                  SU R                  5        U R                  SU R                  5        U R                  SU R
                  5        U R                  SU R                  5        U R                  SU R                  5        U R                  SU R                  5        g g )	NTztag:yaml.org,2002:nullztag:yaml.org,2002:boolztag:yaml.org,2002:intztag:yaml.org,2002:floatztag:yaml.org,2002:mapztag:yaml.org,2002:omapztag:yaml.org,2002:seq)	_initializedadd_constructorconstruct_yaml_nullconstruct_yaml_boolconstruct_yaml_intconstruct_yaml_floatconstruct_yaml_mapconstruct_yaml_omapconstruct_yaml_seq)r   s    r   r1    _LvObjectConstructor._InitializeW   s    c	2C4K4KL	2C4K4KL	133I3IJ	3S5M5MN	133I3IJ	2C4K4KL	133I3IJ r   c                 ~   [        UR                  [        R                  5      (       a  UR                  S:X  a  [        UR                  5      $ U R                  (       aJ  UR                  S:X  a  [        UR                  5      $ UR                  S:X  a  [        UR                  5      $ [        UR                  5      $ )N|'")

isinstancer   sixstring_typesr   r!   _preserve_quotesr)   r%   r   r2   nodes     r   _ScalarType _LvObjectConstructor._ScalarTypec   s    $**c..//	s	'

33			::,TZZ8
8::,TZZ8
8TZZ  r   c                    [        U[        R                  R                  5      (       dE  [        R                  R                  S S SR                  UR                  5      UR                  5      eU(       a  UR                  OU R                  U5      n[        R                  R                  5       Ul        UR                  R                  UR                  l        UR                  R                  UR                  l        X$l	        U$ )Nz$expected a scalar node, but found {})rF   r   nodes
ScalarNodeconstructorConstructorErrorformatid
start_markr   rL   commentsLineColr   linecolumncol)r2   rK   r   rawret_vals        r   _ScalarObject"_LvObjectConstructor._ScalarObjectn   s    dDJJ1122--

0
7
7
@
// 
  djjT%5%5d%;G&&(GJoo**GJJO__++GJJNMNr   c                 8    U R                  XR                  5      $ r   )r]   r   rJ   s     r   construct_scalar%_LvObjectConstructor.construct_scalar}   s    dJJ//r   c                 &    U R                  US 5      $ r   )r]   rJ   s     r   r:   (_LvObjectConstructor.construct_yaml_null   s    dD))r   c                 Z    U R                  XR                  R                  5       S:H  5      $ )Ntrue)r]   r   lowerrJ   s     r   r;   (_LvObjectConstructor.construct_yaml_bool   s%    dJJ$4$4$6&$@AAr   c                 L    U R                  U[        UR                  5      5      $ r   )r]   intr   rJ   s     r   r<   '_LvObjectConstructor.construct_yaml_int   s    dC

O44r   c                 L    U R                  U[        UR                  5      5      $ r   )r]   floatr   rJ   s     r   r=   )_LvObjectConstructor.construct_yaml_float   s    dE$**$566r   c                 R   > [        [        [        U ]  U5      5      S   nX"l        U$ Nr   )listr/   r,   r>   r   r2   rK   r\   r5   s      r   r>   '_LvObjectConstructor.construct_yaml_map   1    "D<TBDDEGGMNr   c                 R   > [        [        [        U ]  U5      5      S   nX"l        U$ ro   )rp   r/   r,   r?   r   rq   s      r   r?   (_LvObjectConstructor.construct_yaml_omap   s1    "D=dCEEFHGMNr   c                 R   > [        [        [        U ]  U5      5      S   nX"l        U$ ro   )rp   r/   r,   r@   r   rq   s      r   r@   '_LvObjectConstructor.construct_yaml_seq   rs   r   r   )F)r   r   r   r   r   r8   r0   classmethodr1   rL   r]   r`   r:   r;   r<   r=   r>   r?   r@   r   __classcell__)r5   s   @r   r,   r,   H   sb     , 	K 	K	!0*B57 r   r,   c                 d    [         R                  " 5       n[        Ul        UR	                  U 5      $ )a{  Loads location/value objects from YAML source.

Call this indirectly by:

  core.yaml.load(source, location_value=True)

Args:
  source: A file like object or string containing YAML data.

Returns:
  The YAML data, where each 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.
)r   YAMLr,   Constructorload)sourceymls     r   LocationValueLoadr      s%      			#(#/	&	r   )r   
__future__r   r   r   ruamelr   rG   r   r   r   PreservedScalarStringr!   DoubleQuotedScalarStringr%   SingleQuotedScalarStringr)   rQ   RoundTripConstructorr,   r   r   r   r   <module>r      s    & '  '  
>!!.. >t00FF $"3"3"L"L $"3"3"L"L W4++@@ Wtr   