
    \                     r    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Zd	 Zd
 Zd Zy)z+Helpers for making single request requests.    )absolute_import)division)unicode_literalsN)
exceptions)operation_quota_utils)utilsc                    d}	 t        j                  | j                        }t        | t        j
                        r-t        j                  |      r| j                  t        |      f}n-| j                  |j                  di       j                  d      f}|s| j                  | j                  f}|S # t        $ r Y 'w xY w)z'Generate Error Message given exception.Nerrormessage)jsonloadscontent
isinstancer   	HttpErrorr   JsonErrorHasDetailsstatus_codeBuildMessageForErrorWithDetailsget
ValueError)	exceptionerror_messagedatas      ;lib/googlecloudsdk/api_lib/compute/single_request_helper.py_GenerateErrorMessager      s    -	::i''(D:''

#
#D
)



)$
/m 


((7B

#
#I
.m 
**I,=,=>M		 
 		s   BB3 3	B?>B?c                    g g }}| j                   j                  }d| j                   _        	  t        | |      |      }|j                  |       || j                   _        ||fS # t        j
                  $ r7}t        |      }|j                  |       |j                  d       Y d}~Zd}~wt        j                  $ rI}t        j                  |      dk(  r% t        | |      |      }|j                  |       n|Y d}~d}~ww xY w)zMakes single request.

  Args:
    service: a BaseApiService Object.
    method: a string of method name.
    request_body: a protocol buffer requesting the requests.

  Returns:
    a length-one response list and error list.
  r   )requestNRetry)
clientnum_retriesgetattrappendr   r   r   RequestErrorsix	text_type)	servicemethodrequest_body	responseserrorsr   responser   r   s	            r   MakeSingleRequestr+   5   s     "V)**+ '..'ww'=HX  +'..	F	 
		 ))4M
MM- T 
	 	  
}}Y7*)&),?hx o !s#   $A& &D
9-B++D
?DD
c                     t        j                  | j                  di             rt        j                  |       S | j                  di       j                  d      S )Nr
   r   )r   IsJsonOperationQuotaErrorr   CreateOperationQuotaExceededMsg)	json_datas    r   r   r   Z   sM    44mmGR  !@@KK=="%)))44    )__doc__
__future__r   r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   r   r#   r   r+   r    r0   r   <module>r6      s2    2 &  '  ' @ 0 
0!J5r0   