
                            d Z ddlmZ ddlmZ ddlmZ ddl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 ddlZ G d dej                         Z G d de      Zd Z G d dej                         Zd Zd Z G d de	j.                        Zy)zDCommon command line processing utilities for access context manager.    )absolute_import)division)unicode_literalsN)encoding)waiter)base)
exceptions)yamlc                   "     e Zd ZdZ fdZ xZS )ParseFileErrorz-Error raised when a file could not be parsed.c                 L    t         t        |   dj                  ||             y)zInitializes a ParseFileError.

    Args:
      path: The path of the file that could not be parsed.
      reason: The reason the file could not be parsed.
    zIssue parsing file [{}]: {}N)superr   __init__format)selfpathreason	__class__s      =lib/googlecloudsdk/command_lib/accesscontextmanager/common.pyr   zParseFileError.__init__"   s$     
.$(%,,T6:    __name__
__module____qualname____doc__r   __classcell__r   s   @r   r   r      s    5	 	r   r   c                   "     e Zd ZdZ fdZ xZS )InvalidMessageParseErrorzAError raised when a message could not be parsed from a YAML file.c           
          |j                         D cg c]  }|j                   }}t        t        |   |dj                  ||rdnddj                  |                   yc c}w )a,  Initializes an InvalidMessageParseError.

    Args:
      path: The path of the file that could not be parsed.
      reason: The reason the file could not be parsed.
      message_class: The message class that could not be parsed.
      pluralize_error: Whether the error meessage is pluralized.
    zfThe YAML-compliant file provided contains errors: {}

The {} in this file can contain the fields [{}].objectsobjectz, N)
all_fieldsnamer   r   r   r   join)r   r   r   message_classpluralize_errorfvalid_fieldsr   s          r   r   z!InvalidMessageParseError.__init__1   sh     %2$<$<$>?$>qAFF$>L?	
"D2 &(IhIIl#
 @s   A"r   r   s   @r   r   r   .   s    I r   r   c                 :   t        j                  |       }|st        | d      	 |r%|D cg c]  }t        j                  ||       }}|S t        j                  ||      g}	 |S c c}w # t
        $ r&}t        | t        j                  |      ||      d}~ww xY w)a  Parse a YAML representation of a message(s).

  Args:
    path: str, path to YAML file containing data to parse
    message_class: obj, message type to parse the contents of the yaml file to
    is_list: bool, whether the file contains a list of messages or a single
      message

  Returns:
    list of message object(s).

  Raises:
    ParseFileError: if the file could not be read into the proper object(s)
  zFile is emptyN)	r
   	load_pathr   r   DictToMessage	Exceptionr   six	text_type)r   r&   is_listdatacmessageserrs          r   )ParseAccessContextManagerMessagesFromYamlr5   L   s      
	$	

//DHIDq(((M:DhI 
/ ((}=>h 
/ J 
 
"cmmC - s.   A+ A&A+ A+ &A+ +	B4!BBc                        e Zd Z fdZ xZS )ParseResponseErrorc                 J    t         t        |   dj                  |             y )NzIssue parsing response: {})r   r7   r   r   )r   r   r   s     r   r   zParseResponseError.__init__n   s"    	

5<<VDEr   )r   r   r   r   r   r   s   @r   r7   r7   l   s    F Fr   r7   c                 N    t        j                  ddj                  |             S )Nz--descriptionzLong-form description of {}.helpr   Argumentr   nouns    r   GetDescriptionArgr@   s   s$    	)006
 r   c                 N    t        j                  ddj                  |             S )Nz--titlez%Short human-readable title of the {}.r:   r<   r>   s    r   GetTitleArgrB   z   s$    	299$?
 r   c                   (     e Zd ZdZ fdZd Z xZS )BulkAPIOperationPollerzA Poller used by the Bulk API.

  Polls ACM Operations endpoint then calls LIST instead of GET.

  Attributes:
    policy_number: The Access Policy ID that the Poller needs in order to call
      LIST.
  c                     t         t        |   ||       t        j                  d|j                               }|r|j                         | _        y t        d      )Nz^accessPolicies/\d+z=Could not determine Access Policy ID from operation response.)	r   rD   r   researchNamegrouppolicy_numberr7   )r   result_serviceoperation_serviceoperation_ref	policy_idr   s        r   r   zBulkAPIOperationPoller.__init__   sY    	
 $01BD 		0-2D2D2FGI$??,d  5 6 6r   c                     ~| j                   j                  d      }| j                   j                   || j                              S )NList)parent)rK   GetRequestTyperP   rJ   )r   	operationrequest_types      r   	GetResultz BulkAPIOperationPoller.GetResult   s=    &&55f=L##L8J8J$KLLr   )r   r   r   r   r   rU   r   r   s   @r   rD   rD      s    6Mr   rD   )r   
__future__r   r   r   rF   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   googlecloudsdk.corer	   r
   r.   Errorr   r   r5   r7   r@   rB   CloudOperationPollerrD    r   r   <module>r^      s    K &  ' 	 % . ( * $ 
Z%% ~ <@F)) FMV88 Mr   