
                         l    S r SSKJr  SSKJr  SSKJr  SSKr\" S/5      rS S S	.rS
 r	S r
S rS rg)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                     U R                   $ N)boolean_valuevalues    0lib/googlecloudsdk/api_lib/dataflow/step_json.py<lambda>r   #   s
    u/B/B    c                     U R                   $ r   )string_valuer
   s    r   r   r   $   s
    E,>,>r   )zhttp://schema.org/Booleanzhttp://schema.org/Textc                    0 nU R                   (       aT  U R                   R                   H:  nUR                  [        ;  d  M  [	        UR
                  5      XR                  '   M<     U R                  U R                  U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   (   sg     *##88	-	-,TZZ8
88 9
 mmmm
 r   c                    0 nU R                   R                   H  nUR                  XR                  '   M     UR	                  SS5      nU=(       a     [
        R	                  UR                  S5      nU(       a  U(       d&  [        S [        R                  " U5       5       5      $  U" US   5      $ ! [         a    SR                  UR                  U 5      s $ f = f)zExtracts 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   @   #    U  H  u  pU[        U5      4v   M     g 7fr   )r   ).0kvs      r   	<genexpr>*_ExtractDecoratedObject.<locals>.<genexpr>R   s     K2J$!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**Ihh , }}Wd#"A&**2??DA)	9
 K#--	2JKKK
 Yw'((	  8??
    s   (
B3 3&CCc                 "   U R                   (       a  [        U 5      $ U R                  (       a0  U R                  R                   Vs/ s H  n[	        U5      PM     sn$ U R
                  (       a  U R
                  $ SR                  U 5      $ s  snf )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   Bc                 X    U R                    Vs/ s H  n[        U5      PM     sn$ s  snf )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   ExtractStepsr7   l   s%     *-	3,t
	33	3s   ')__doc__
__future__r   r   r   r'   setr   r%   r   r/   r   r7    r   r   <module>r<      sL   
 '  ' 
O,-  "C> * B74r   