
    )                     
   S SK Jr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr   " S S\	5      r
 " S	 S
\	5      r " S S\R                  5      r\R                  R                  4S jr\R                  R                  4S jrg)    )absolute_import)
validation)yaml_builder)yaml_errors)yaml_listener)yamlc                   *    \ rS rSrSrS rS rS rSrg)_ObjectMapper   a  Wrapper used for mapping attributes from a yaml file to an object.

This wrapper is required because objects do not know what property they are
associated with a creation time, and therefore can not be instantiated
with the correct class until they are mapped to their parents.
c                 0    SU l         [        5       U l        g)z*Object mapper starts off with empty value.N)valuesetseenselfs    /lib/googlecloudsdk/appengine/api/yaml_object.py__init___ObjectMapper.__init__'   s    DJDI    c                     Xl         g)zTSet value of instance to map to.

Args:
  value: Instance that this mapper maps to.
N)r   )r   r   s     r   	set_value_ObjectMapper.set_value,   s	     Jr   c                     XR                   ;   a  [        R                  " SU-  5      eU R                   R                  U5        g )NzDuplicate attribute '%s'.)r   r   DuplicateAttributeadd)r   keys     r   see_ObjectMapper.see4   s3    
ii**+F+LMMIIMM#r   )r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__ r   r   r
   r
      s    
r   r
   c                   $    \ rS rSrSrS rS rSrg)_ObjectSequencer:   a  Wrapper used for building sequences from a yaml file to a list.

This wrapper is required because objects do not know what property they are
associated with a creation time, and therefore can not be instantiated
with the correct class until they are mapped to their parents.
c                      / U l         SU l        g)z-Object sequencer starts off with empty value.N)r   constructorr   s    r   r   _ObjectSequencer.__init__B   s    DJDr   c                     Xl         g)zSet object used for constructing new sequence instances.

Args:
  constructor: Callable which can accept no arguments.  Must return
    an instance of the appropriate class for the container.
N)r*   )r   r*   s     r   set_constructor _ObjectSequencer.set_constructorG   s
     #r   )r*   r   N)r   r    r!   r"   r#   r   r-   r$   r%   r   r   r'   r'   :   s    
#r   r'   c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)ObjectBuilderQ   aS  Builder used for constructing validated objects.

Given a class that implements validation.ValidatedBase, it will parse a YAML
document and attempt to build an instance of the class.
ObjectBuilder will only map YAML fields that are accepted by the
ValidatedBase's GetValidator function.
Lists are mapped to validated.  Repeated attributes and maps are mapped to
validated.Type properties.

For a YAML map to be compatible with a class, the class must have a
constructor that can be called with no parameters.  If the provided type
does not have such a constructor a parse time error will occur.
c                     Xl         g)zInitialize validated object builder.

Args:
  default_class: Class that is instantiated upon the detection of a new
    document.  An instance of this class will act as the document itself.
Ndefault_class)r   r4   s     r   r   ObjectBuilder.__init__`   s
     'r   c                     [        U[        R                  5      (       a  UR                  n[        U[        R                  5      (       a  UR
                  $ [        $ )a  Get the ultimate type of a repeated validator.

Looks for an instance of validation.Repeated, returning its constructor.

Args:
  attribute: Repeated validator attribute to find type for.

Returns:
  The expected class of of the Type validator, otherwise object.
)
isinstancer   Optional	validatorRepeatedr*   object)r   	attributes     r   _GetRepeatedObjectBuilder._GetRepeatedi   sF     )Z0011%%i)Z0011"""Mr   c                 "    U R                  5       $ )zUInstantiate new root validated object.

Returns:
  New instance of validated object.
r3   r   s    r   BuildDocumentObjectBuilder.BuildDocumentz   s     r   c                 Z    [        5       n[        XR                  5      (       a  Xl        U$ )zNew instance of object mapper for opening map scope.

Args:
  top_value: Parent of nested object.

Returns:
  New instance of object mapper.
)r
   r7   r4   r   )r   	top_valueresults      r   BuildMappingObjectBuilder.BuildMapping   s(     _F )//00lMr   c                 R   [        UR                  S5      (       d  [        R                  " S5      e UR                  R	                  5         g! [        R                   a    e [
         a:  n [        U5      nO! [
         a    Sn Of = f[        R                  " XC5      eSnAff = f)zWhen leaving scope, makes sure new object is initialized.

This method is mainly for picking up on any missing required attributes.

Args:
  top_value: Parent of closing mapping object.
  mapping: _ObjectMapper instance that is leaving scope.
CheckInitializedz$Cannot convert map to non-map value.	<unknown>N)hasattrr   r   ValidationErrorrH   	Exceptionstr)r   rC   mappinge	error_strs        r   
EndMappingObjectBuilder.EndMapping   s     7=="455&&'MNN5mm$$&%%  5
 F	  	  &&y445s5   A B&-A98B!9BB!BB!!B&c                     [        5       $ )zNew instance of object sequence.

Args:
  top_value: Object that contains the new sequence.

Returns:
  A new _ObjectSequencer instance.
)r'   )r   rC   s     r   BuildSequenceObjectBuilder.BuildSequence   s     r   c                    [        UR                  [        R                  5      (       d   e UR                  R	                  U5      n[        U[        5      (       a,  UR                  UR                  5       5        UR                  nOA[        U[        5      (       a,  UR                  U R                  U5      5        UR                  nUR                  U5         UR                  R                  X#5        g! [        R
                   a  n[        R                  " U5      eSnAff = f! [        R
                   aX  n [!        U5      nO! ["         a    Sn Of = f [!        U5      nO! ["         a    Sn Of = fSU< SU< SU< 3Ul        UeSnAf["         ag  n [!        U5      nO! ["         a    Sn Of = f [!        U5      nO! ["         a    Sn Of = fSU< SU< SU< 3n	[        R
                  " X5      eSnAff = f)a  Map key-value pair to an objects attribute.

Args:
  subject: _ObjectMapper of object that will receive new attribute.
  key: Key of attribute.
  value: Value of new attribute.

Raises:
  UnexpectedAttribute when the key is not a validated attribute of
  the subject value class.
NrI   zUnable to assign value 'z' to attribute 'z':
)r7   r   r   ValidatedBaseGetValidatorrK   r   UnexpectedAttributer
   r   expected_typer'   r-   r=   r   SetrM   rL   message)
r   subjectr   r   r<   errrO   rP   	value_strr\   s
             r   MapToObjectBuilder.MapTo   s    gmmZ%=%=>>>>1--,,S1i %'' ooi--/0kke	E+	,	,D--i89kkeKK#3mm# %% 1++C001  %% 
 F	  	  J	  	 
 sI/aig 3 F	  	  J	  	 
 S)-g&&w223s   C8 D* 8D'D""D'*H?E
FEFEFE*)F*E96F8E99FHF+*H +F:7H 9F::H >G
	H 
GH G'H  Hc                     [        U[        5      (       aE  UR                  UR                  5       5        UR                  R                  UR                  5        gUR                  R                  U5        g)zAppend a value to a sequence.

Args:
  subject: _ObjectSequence that is receiving new value.
  value: Value that is being appended to sequence.
N)r7   r
   r   r*   r   append)r   r]   r   s      r   AppendToObjectBuilder.AppendTo   sP     %''oog))+,mm5;;' mm5!r   r3   N)r   r    r!   r"   r#   r   r=   r@   rE   rQ   rT   r`   rd   r$   r%   r   r   r0   r0   Q   s2    '"  5@	A3F"r   r0   c                     [        U 5      n[        R                  " U5      n[        R                  " U5      nUR                  XSS9  UR                  5       $ )a6  Build objects from stream.

Handles the basic case of loading all the objects from a stream.

Args:
  default_class: Class that is instantiated upon the detection of a new
    document.  An instance of this class will act as the document itself.
  stream: String document or open file object to process as per the
    yaml.parse method.  Any object that implements a 'read()' method which
    returns a string document will work with the YAML parser.
  loader_class: Used for dependency injection.

Returns:
  List of default_class instances parsed from the stream.
)   rg   )version)r0   r   BuilderHandlerr   EventListenerParse
GetResults)r4   streamloaderbuilderhandlerlisteners         r   BuildObjectsrr     sM      -('''0'((1(
...0				r   c                     [        XU5      n[        U5      S:  a  [        R                  " 5       e[        U5      S:  a  [        R                  " 5       eUS   $ )a  Build object from stream.

Handles the basic case of loading a single object from a stream.

Args:
  default_class: Class that is instantiated upon the detection of a new
    document.  An instance of this class will act as the document itself.
  stream: String document or open file object to process as per the
    yaml.parse method.  Any object that implements a 'read()' method which
    returns a string document will work with the YAML parser.
  loader_class: Used for dependency injection.
rg   r   )rr   lenr   EmptyConfigurationFileMultipleConfigurationFile)r4   rm   rn   definitionss       r   BuildSingleObjectrx   (  sR     ]F;+

,
,
..

/
/
11	Qr   N)
__future__r   googlecloudsdk.appengine.apir   r   r   r   ruamelr   r;   r
   r'   Builderr0   rn   
SafeLoaderrr   rx   r%   r   r   <module>r~      sn   . ' 3 5 4 6 F 6#v #.|"L(( |"~ 04{{/E/E 0 59KK4J4J r   