
    
                     <    d Z ddlmZ ddlmZ ddlmZ efdZd Zy)z@Functions for working with dictionaries representing yaml files.    )absolute_import)division)unicode_literalsc                     |d   |dd }}|r!|| vrt               | |<   t        | |   ||      S || vr
 |       | |<   | |   S )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	      s]     Qab%	C6c%js5z455C=c%ju:    c              #   $  K   |s|  y|d   |dd }}|| v rwt        | |   t              rt        | |   |      D ]  }|  yt        | |   t              r | |   D ]  }t        ||      D ]  }|   y|rt	        |dz         | |    yyw)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%
c\#e*d#!#e*d3- 4	CJ	%5z!#At_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   