
                             S r SSKJr  SSKJr  SSKJ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Jr  Sr " S S\5      rSS jrS rg)z"Helpers for making batch requests.    )absolute_import)division)unicode_literalsN)batch)
exceptions)operation_quota_utils)utils)apis)
propertiesi  c                   $    \ rS rSrSrS rS rSrg)BatchChecker$   z>Class to conveniently curry the prompted_service_tokens cache.c                     Xl         g)zInitialize class.

Args:
  prompted_service_tokens: a set of string tokens that have already been
    prompted for enablement.
Nprompted_service_tokens)selfr   s     2lib/googlecloudsdk/api_lib/compute/batch_helper.py__init__BatchChecker.__init__'   s
     $;     c                 B   Ub7  [         R                  R                  R                  R	                  5       (       d  g[
        R                  " U5      nU(       d  gUu  pEnXPR                  ;  a2  U R                  R                  U5        [
        R                  " XEUSS9  gg)a  Callback for apitools batch responses.

This will use self.prompted_service_tokens to cache service tokens that
have already been prompted. In this way, if the same service has multiple
batch requests and is enabled on the first, the user won't get a bunch of
superflous messages. Note that this cannot be reused between batch uses
because of the mutation.

Args:
  http_response: Deserialized http_wrapper.Response object.
  exception: apiclient.errors.HttpError object if an error occurred.
NT)is_batch_request)
r   VALUEScoreshould_prompt_to_enable_apiGetBoolr
   GetApiEnablementInfor   addPromptToEnableApi)r   http_response	exceptionenablement_infoprojectservice_tokens         r   
BatchCheckBatchChecker.BatchCheck1   s      	  %%AAIIKK//	:O(7%GI888
""&&}5
WY.24 9r   r   N)__name__
__module____qualname____firstlineno____doc__r   r%   __static_attributes__ r   r   r   r   $   s    F;4r   r   c                 l   / n[         R                  R                  R                  R	                  5       (       a  UR                  [        R                  5        [        R                  " UUS9nU  H  u  pVnUR                  XVU5        M     [        [        5       5      nUR                  U[        UR                  S9n	/ n
/ nU	 GHZ  nU
R                  UR                   5        UR"                  (       d  M2  Sn[%        UR&                  [(        R*                  5      (       a   [,        R.                  " UR&                  R0                  5      n[2        R4                  " U5      (       a"  UR&                  R6                  [9        U5      4nO8UR&                  R6                  UR;                  S0 5      R;                  S5      4n U(       d,  UR&                  R6                  UR&                  R0                  4nOSUR&                  R>                  4nUR                  U5        GM]     X4$ ! [<         a     Nqf = f)aZ  Makes batch requests.

Args:
  requests: A list of tuples. Each tuple must be of the form
      (service, method, request object).
  http: An HTTP object.
  batch_url: The URL to which to send the requests.

Returns:
  A tuple where the first element is a list of all objects returned
  from the calls and the second is a list of error messages.
)	batch_urlretryable_codes)max_batch_sizebatch_request_callbackNerrormessage) r   r   r   r   r   appendr
   )API_ENABLEMENT_ERROR_EXPECTED_STATUS_CODEr   BatchApiRequestAddr   setExecute_BATCH_SIZE_LIMITr%   responseis_error
isinstancer!   r   	HttpErrorjsonloadscontentr	   JsonErrorHasDetailsstatus_codeBuildMessageForErrorWithDetailsget
ValueErrorr4   )requestshttpr/   r0   batch_requestservicemethodrequestbatch_checker	responsesobjectserrorsr<   error_messagedatas                  r   MakeRequestsrT   N   s    /77??AA
 4IIJ'')8GI-"*gwgw/ #+
 su%-##
,*55 $ 7) '&hNN8$$%m	H&&
(<(<	=	=		H..667$&&t,,%//;;<TBDM &//;;!XXgr266yACM #--99#--557- x1199:mmM"/ 2 
  	
	s   "A&H&	7H&&
H32H3c                     [         R                  " U R                  S0 5      5      (       a  [         R                  " U 5      $ U R                  S0 5      R                  S5      $ )Nr3   r4   )r   IsJsonOperationQuotaErrorrF   CreateOperationQuotaExceededMsg)	json_datas    r   rE   rE      sP    55mmGR " " @@KK=="%)))44r   )N)r+   
__future__r   r   r   r@   apitools.base.pyr   r   googlecloudsdk.api_lib.computer   r	   googlecloudsdk.api_lib.utilr
   googlecloudsdk.corer   r;   objectr   rT   rE   r-   r   r   <module>r_      sH    ) &  '  " ' @ 0 , *  '46 '4T<~5r   