
    
                     >    S r SSKJr  SSKJr  SSKJr  \4S jrS rg)z@Functions for working with dictionaries representing yaml files.    )absolute_import)division)unicode_literalsc                     US   USS pCU(       a  X0;  a  [        5       X'   [        X   XB5      $ X0;  a	  U" 5       X'   X   $ )a  Get or create the object by following the field names in the path.

not exist, create the appropriate value.

Args:
  obj: A dictionary representing a yaml dictionary
  path: A list of strings representing fields to follow.
  constructor: If the object at the end of the path does not exist, create an
    object using the constructor given.

Returns:
  An object at found by following the path.
r      N)dictGetOrCreate)objpathconstructorfirstrests        2lib/googlecloudsdk/command_lib/code/yaml_helper.pyr	   r	      sM     Qab	6cjsz455=cj:    c              #   L  #    U(       d  U v   gUS   USS p2X ;   a  [        X   [        5      (       a  [        X   U5       H  nUv   M	     g[        X   [        5      (       a"  X    H  n[        XS5       H  nUv   M	     M     gU(       a  [	        US-   5      eX   v   gg7f)a  Given a yaml object, yield all objects found by following a path.

Given a yaml object, read each field in the path and return the object
found at the end. If a field has a list value, follow the path for each
object in the list.

E.g.
>>> X = {'A': {'B': [{'C': {'D': 1}}, {'C': {'D': 2}}]}}
>>> sorted(list(GetAll(X, path=('A', 'B', 'C', 'D'))))
[1, 2]

Args:
  obj: A dictionary representing a yaml dictionary
  path: A list of strings representing fields to follow.

Yields:
  Values that are found by following the given path.
Nr   r   z is not a dictionary or a list)
isinstancer   GetAlllist
ValueError)r
   r   r   r   extracted_objxs         r   r   r   /   s     & 

I
Qab
\#*d##!#*d3- 4	CJ	%	%z!#A_M
 -  
!AABBj s   B"B$N)__doc__
__future__r   r   r   r   r	   r    r   r   <module>r      s#    G &  ' (, 4$r   