
    	                     n    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  G d dej                        Z
y	)
#Refine server response for display.    )absolute_import)division)unicode_literals)encoding)utilc                   X     e Zd ZdZ fdZed        Zed        Zed        Zd Z	 xZ
S )DisplayHelperr   c                 `    t         t        |   t        j                  |             || _        y )N)superr
   __init__r   MessageToDict_job)selfjob	__class__s     5lib/googlecloudsdk/api_lib/dataproc/display_helper.pyr   zDisplayHelper.__init__   s$    	-'(>(>s(CDDI    c                 $    | j                  d      S )NJobgetTruncatedFieldNameBySuffixr   s    r   jobTypezDisplayHelper.jobType!   s    --e44r   c                 $    | j                  d      S )NBatchr   r   s    r   	batchTypezDisplayHelper.batchType%   s    --g66r   c                 $    | j                  d      S )NSessionr   r   s    r   sessionTypezDisplayHelper.sessionType)   s    --i88r   c                 :   | j                   j                         D cg c]  }|j                   c}D ]H  }|j                  |      s|j	                  |      \  }}}| j                   j                  |      sF|c S  t        dj                  |            c c}w )aP  Get a field name by suffix and truncate it.

    The one_of fields in server response have their type name as field key.
    One can retrieve the name of those fields by iterating through all the
    fields.

    Args:
      suffix: the suffix to match.

    Returns:
      The first matched truncated field name.

    Raises:
      AttributeError: Error occur when there is no match for the suffix.

    Usage Example:
      In server response:
      {
        ...
        "sparkJob":{
          ...
        }
        ...
      }
      type = helper.getTruncatedFieldNameBySuffix('Job')
    z(Response has no field with {} as suffix.)r   
all_fieldsnameendswith
rpartitionget_assigned_valueAttributeErrorformat)r   suffixfieldtoken_s        r   r   z+DisplayHelper.getTruncatedFieldNameBySuffix-   s    6 +/))*>*>*@A*@%***@A		&&v.q!99''.,	 B
 C &.* * Bs   B)__name__
__module____qualname____doc__r   propertyr   r   r    r   __classcell__)r   s   @r   r
   r
      sL    + 5 5 7 7 9 9!*r   r
   N)r0   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.dataprocr   Bunchr
    r   r   <module>r8      s)     * &  ' % 04*DJJ 4*r   