
                         l    d Z ddlmZ ddlmZ ddlmZ ddlZ edg      Zd d d	Zd
 Z	d Z
d Zd Zy)a  Code to clean-up transform the JSON description of a dataflow.

Example clean-ups:

1. Dictionaries representing primitives with a schema will be converted to the
  primitive:
  Ex: { '@type': "https://schema.org/Text", 'value': "Hello" } becomes "Hello"
2. Fields that are unlikely to be human consumable may be hidden.
  Ex: The serialized_fn field will be hidden, since humans are unlikely to try
  to read the serialized Java object.
    )absolute_import)division)unicode_literalsNserialized_fnc                     | j                   S N)boolean_valuevalues    0lib/googlecloudsdk/api_lib/dataflow/step_json.py<lambda>r   #   s
    u/B/B    c                     | j                   S r   )string_valuer
   s    r   r   r   $   s
    E,>,>r   )zhttp://schema.org/Booleanzhttp://schema.org/Textc                     i }| j                   rP| j                   j                  D ]7  }|j                  t        vst	        |j
                        ||j                  <   9 | j                  | j                  |dS )zConverts a Step message into a dict with more sensible structure.

  Args:
    step_msg: A Step message.
  Returns:
    A dict with the cleaned up information.
  )kindname
properties)r   additionalPropertieskey_EXCLUDED_PROPERTIES_ExtractValuer   r   r   )step_msgr   props      r   _ExtractStepr   (   si     *##88	-	-,TZZ8
488 9
 mmmm
 r   c                    i }| j                   j                  D ]  }|j                  ||j                  <    |j	                  dd      }|xr  t
        j	                  |j                  d      }|r|s%t        d t        j                  |      D              S 	  ||d         S # t        $ r dj                  |j                  |       cY S w xY w)a  Extracts an object from the proto representation of the JSON object.

  Args:
    proto: A protocol representation of a JSON object.
  Returns:
    A clean representation of the JSON object. If it was an object
    representing a primitive, then that primitive.
  z@typeNc              3   <   K   | ]  \  }}|t        |      f  y wr   )r   ).0kvs      r   	<genexpr>z*_ExtractDecoratedObject.<locals>.<genexpr>R   s!     K2J$!QM!$%2Js   r   z+Missing value for type [{0}] in proto [{1}])object_valuer   r   r   get_VALUE_RETRIEVERSr   dictsix	iteritemsKeyErrorformat)proto	prop_dictr   ty	retrievers        r   _ExtractDecoratedObjectr.   =   s     )  ++d**Idhh , }}Wd#"A&**2??DA)	9
 K#--	2JKKK
 Yw'((	  8??
    s   
B" "%C
	C
c                     | j                   rt        |       S | j                  r-| j                  j                  D cg c]  }t	        |       c}S | j
                  r| j
                  S dj                  |       S c c}w )NzNo decoding provided for: {0})r"   r.   array_valueentriesr   r   r)   )r*   r    s     r   r   r   ^   su     "5))
&+&7&7&?&?@&?M!&?@@
	(	/	/	66 As   A:c                 R    | j                   D cg c]  }t        |       c}S c c}w )zExtract the cleaned up step dictionary for all the steps in the job.

  Args:
    job: A Job message.
  Returns:
    A list of cleaned up step dictionaries.
  )stepsr   )jobsteps     r   ExtractStepsr6   l   s%     *-	3,t
	33	3s   $)__doc__
__future__r   r   r   r&   setr   r$   r   r.   r   r6    r   r   <module>r;      sL   
 '  ' 
O,-  "C> * B74r   