
                             S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SSKr " S S	\	R                  5      r " S
 S\5      rS r " S S\	R                  5      rS rS r " S S\R&                  5      rg)zDCommon command line processing utilities for access context manager.    N)encoding)waiter)base)
exceptions)yamlc                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )ParseFileError   z-Error raised when a file could not be parsed.c                 J   > [         [        U ]  SR                  X5      5        g)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   ParseFileError.__init__   s"     
.$(%,,T:     __name__
__module____qualname____firstlineno____doc__r   __static_attributes____classcell__r   s   @r   r	   r	      s    5	 	r   r	   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )InvalidMessageParseError+   zAError raised when a message could not be parsed from a YAML file.c           
         > UR                  5        Vs/ s H  oUR                  PM     nn[        [        U ]  USR                  UU(       a  SOSSR                  U5      5      5        gs  snf )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   !InvalidMessageParseError.__init__.   sf     %2$<$<$>?$>qFF$>L?	
"D2 &(IhIIl#
 @s   A)r   r   r   s   @r   r!   r!   +   s    I r   r!   c                 X   [         R                  " U 5      nU(       d  [        U S5      e U(       a(  U Vs/ s H  n[        R                  " XA5      PM     nnU$ [        R                  " X15      /n U$ s  snf ! [
         a&  n[        U [        R                  " U5      X5      eSnAff = f)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   )ParseAccessContextManagerMessagesFromYamlr9   I   s      
	$	

//DHIDq(((:DhI 
/ ((=>h 
/ J 
 
"cmmC - s.   A9  A4A9 A9 4A9 9
B)!B$$B)c                   (   ^  \ rS rSrU 4S jrSrU =r$ )ParseResponseErrori   c                 J   > [         [        U ]  SR                  U5      5        g )NzIssue parsing response: {})r   r;   r   r   )r   r   r   s     r   r   ParseResponseError.__init__k   s"    	

5<<VDEr   r   )r   r   r   r   r   r   r   r   s   @r   r;   r;   i   s    F Fr   r;   c                 J    [         R                  " SSR                  U 5      S9$ )Nz--descriptionzLong-form description of {}.helpr   Argumentr   nouns    r   GetDescriptionArgrF   p   s$    	)006
 r   c                 J    [         R                  " SSR                  U 5      S9$ )Nz--titlez%Short human-readable title of the {}.r@   rB   rD   s    r   GetTitleArgrH   w   s$    	299$?
 r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )BulkAPIOperationPoller~   zA 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                    > [         [        U ]  UU5        [        R                  " SUR                  5       5      nU(       a  UR                  5       U l        g [        S5      e)Nz^accessPolicies/\d+z=Could not determine Access Policy ID from operation response.)	r   rJ   r   researchNamegrouppolicy_numberr;   )r   result_serviceoperation_serviceoperation_ref	policy_idr   s        r   r   BulkAPIOperationPoller.__init__   sY    	
 $01BD 		0-2D2D2FGI$??,d  5 6 6r   c                     AU R                   R                  S5      nU R                   R                  U" U R                  S95      $ )NList)parent)rR   GetRequestTyperX   rQ   )r   	operationrequest_types      r   	GetResult BulkAPIOperationPoller.GetResult   s=    &&55f=L##L8J8J$KLLr   )rQ   )	r   r   r   r   r   r   r]   r   r   r   s   @r   rJ   rJ   ~   s    6M Mr   rJ   )r   rM   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   googlecloudsdk.corer   r   r2   Errorr	   r!   r9   r;   rF   rH   CloudOperationPollerrJ   r   r   r   <module>re      sx    K 
 % . ( * $ 
Z%% ~ <@F)) FMV88 Mr   