
    ݅                    
   S 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K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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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"r" " S S\RF                  5      r# " S S\RH                  \RJ                  \RL                  \RN                  5      r( " S S\RR                  RH                  \RR                  RJ                  \RR                  RL                  \RR                  RN                  5      r*S r+ " S S\RH                  \RL                  5      r,S r-S  r. " S! S"\RH                  \RL                  5      r/S# r0 " S$ S%\
Rb                  5      r2 " S& S'\Rf                  " S'S(5      \Rh                  5      r5S) r6S* r7S+ r8S,r9S-r:S. r;S/ r<S0 r=S1 r>S2 r?S3 r@S4 rAS5 rBS6 rCS7 rDS8 rES9 rFS: rGS; rHS< rI " S= S>\R                  \R                  5      rL " S? S@\RH                  \RJ                  \RL                  \RN                  5      rM " SA SB\RH                  5      rNSC rOSD rPSE rQSF rRSG rS    SJSH jrT  SKSI jrUg)Lz=Internal Helper Classes for creating gapic clients in gcloud.    )absolute_import)annotations)division)unicode_literalsN)bidi)error_details_pb2)api_enablement)base)config)context_aware)
exceptions)log)metrics)
properties)	transport)encoding)files)http_proxy_types)urllibc                      \ rS rSrSrSrg)Error/   z Exceptions for the gapic module. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       .lib/googlecloudsdk/core/gapic_util_internal.pyr   r   /   s    (r    r   c                  <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)ClientCallDetailsInterceptor3   z?Generic Client Interceptor that modifies the ClientCallDetails.c                    Xl         g N_fnselffns     r!   __init__%ClientCallDetailsInterceptor.__init__9       Hr    c                4    U R                  U5      nU" XC5      $ a|  Intercepts a RPC.

Args:
  continuation: A function that proceeds with the invocation by
    executing the next interceptor in chain or invoking the
    actual RPC on the underlying Channel. It is the interceptor's
    responsibility to call it if it decides to move the RPC forward.
    The interceptor can use
    `response_future = continuation(client_call_details, request)`
    to continue with the RPC.
  client_call_details: A ClientCallDetails object describing the
    outgoing RPC.
  request: The request value for the RPC.

Returns:
    If the response is unary:
      An object that is both a Call for the RPC and a Future.
      In the event of RPC completion, the return Call-Future's
      result value will be the response message of the RPC.
      Should the event terminate with non-OK status, the returned
      Call-Future's exception value will be an RpcError.

    If the response is streaming:
      An object that is both a Call for the RPC and an iterator of
      response values. Drawing response values from the returned
      Call-iterator may raise RpcError indicating termination of
      the RPC with non-OK status.
r'   r*   continuationclient_call_detailsrequestnew_detailss        r!   intercept_call+ClientCallDetailsInterceptor.intercept_call<       : ((./K--r    c                &    U R                  XU5      $ z3Intercepts a unary-unary invocation asynchronously.r6   r*   r2   r3   r4   s       r!   intercept_unary_unary2ClientCallDetailsInterceptor.intercept_unary_unary\       |'JJr    c                &    U R                  XU5      $ z%Intercepts a unary-stream invocation.r;   r<   s       r!   intercept_unary_stream3ClientCallDetailsInterceptor.intercept_unary_stream`   s     |'JJr    c                &    U R                  XU5      $ z4Intercepts a stream-unary invocation asynchronously.r;   r*   r2   r3   request_iterators       r!   intercept_stream_unary3ClientCallDetailsInterceptor.intercept_stream_unarye        |/1 1r    c                &    U R                  XU5      $ z&Intercepts a stream-stream invocation.r;   rF   s       r!   intercept_stream_stream4ClientCallDetailsInterceptor.intercept_stream_streamk   rJ   r    r'   Nr   r   r   r   r   r,   r6   r=   rB   rH   rM   r   r   r    r!   r#   r#   3   s)     H.@KK
11r    r#   c                  <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)!AsyncClientCallDetailsInterceptorr   zEGeneric Async Client Interceptor that modifies the ClientCallDetails.c                    Xl         g r&   r'   r)   s     r!   r,   *AsyncClientCallDetailsInterceptor.__init__x   r.   r    c                4    U R                  U5      nU" XC5      $ r0   r'   r1   s        r!   r6   0AsyncClientCallDetailsInterceptor.intercept_call{   r8   r    c                .   #    U R                  XU5      $ 7fr:   r;   r<   s       r!   r=   7AsyncClientCallDetailsInterceptor.intercept_unary_unary         |'JJ   c                .   #    U R                  XU5      $ 7frA   r;   r<   s       r!   rB   8AsyncClientCallDetailsInterceptor.intercept_unary_stream   rY   rZ   c                .   #    U R                  XU5      $ 7frE   r;   rF   s       r!   rH   8AsyncClientCallDetailsInterceptor.intercept_stream_unary         |/1 1rZ   c                .   #    U R                  XU5      $ 7frL   r;   rF   s       r!   rM   9AsyncClientCallDetailsInterceptor.intercept_stream_stream   r_   rZ   r'   NrO   r   r    r!   rQ   rQ   r   s)     N.@K
K
11r    rQ   c                    ^ SSS.mU4S jn U $ )z6Returns a callback for checking API enablement errors.Falready_prompted_to_enableapi_enabledc                  > U R                  5       [        R                  R                  :w  a  g[        R
                  " U R                  5       5      nU(       a4  TS   (       a  TS   $ STS'   [        R                  " U6 nU(       a  UTS'   gg)NFrd   re   T)codegrpc
StatusCodePERMISSION_DENIEDr	   GetApiEnablementInfodetailsPromptToEnableApi)responseenablement_infoapi_enable_attemptedstates      r!   _ShouldRecover6ShouldRecoverFromAPIEnablement.<locals>._ShouldRecover   s}    }}$//;;;$99(:J:J:LMO	+	,]##,0e()+==O	3mr    r   )rr   rq   s    @r!   ShouldRecoverFromAPIEnablementrt      s    ).!% 
r    c                  0    \ rS rSrSrS rS rS rS rSr	g)	APIEnablementInterceptor   8API Enablement Interceptor for prompting to enable APIs.c                     SU l         SU l        g NFrc   r*   s    r!   r,   !APIEnablementInterceptor.__init__   s    &+D#Dr    c                   U" X#5      nUR                  5       [        R                  R                  :w  a  U$ [        R
                  " UR                  5       5      nU(       a\  U R                  (       a  U R                  (       a  U" X#5      $ U$ SU l        [        R                  " U6 nU(       a  SU l        U" X#5      $ U$ )NT)
rg   rh   ri   rj   r	   rk   rl   rd   re   rm   )r*   r2   r3   r4   rn   ro   rp   s          r!   r6   'APIEnablementInterceptor.intercept_call   s    /9H}}$//;;;o$99O		(	(1;
;(,d%+==O	/99Or    c                &    U R                  XU5      $ r:   r;   r<   s       r!   r=   .APIEnablementInterceptor.intercept_unary_unary   r?   r    c                &    U R                  XU5      $ rE   r;   rF   s       r!   rH   /APIEnablementInterceptor.intercept_stream_unary   rJ   r    rc   N
r   r   r   r   r   r,   r6   r=   rH   r   r   r    r!   rv   rv      s    @&K1r    rv   c                   U  H~  nUR                   S:X  d  M  [        R                  R                  UR                  5      nUR
                  [        R                  :X  d  M^  UR                  [        R                  :X  d  M~    g   g)Nzgoogle.rpc.errorinfo-binTF)
keyr   	ErrorInfo
FromStringvaluereasonr   USER_PROJECT_ERROR_REASONdomainUSER_PROJECT_ERROR_DOMAIN)trailing_metadata	metadatum
error_infos      r!   IsUserProjectErrorr      sc    $i}}22$..99)//Jj


yBB
B


yBB
B % 
r    c                N   ^  [         R                  " 5       (       d  S $ U 4S jnU$ )z7Returns a callback for handling Quota Project fallback.c                    grz   r   )_s    r!   <lambda>/ShouldRecoverFromQuotaProject.<locals>.<lambda>   s    Ur    c                   > U R                  5       [        R                  R                  :w  a  g[	        U R                  5       5      (       a  S Tl        ggNFT)rg   rh   ri   rj   r   r   _quota_project_id)rn   credentialss    r!   rr   5ShouldRecoverFromQuotaProject.<locals>._ShouldRecover   s@    }}$//;;;(44677&*k#r    )r
   #UserProjectQuotaWithFallbackEnabled)r   rr   s   ` r!   ShouldRecoverFromQuotaProjectr      s%    		1	1	3	3 
r    c                  0    \ rS rSrSrS rS rS rS rSr	g)	QuotaProjectInterceptori	  rx   c                    Xl         g r&   r   )r*   r   s     r!   r,    QuotaProjectInterceptor.__init__  s    "r    c                X   U" X#5      nUR                  5       [        R                  R                  :w  a  U$ [	        UR                  5       5      (       d  U$ U R                  R                  nS U R                  l         U" X#5      XPR                  l        $ ! XPR                  l        f = fr&   )rg   rh   ri   rj   r   r   r   r   )r*   r2   r3   r4   rn   quota_projects         r!   r6   &QuotaProjectInterceptor.intercept_call  s    /9H}}$//;;;oh88:;;o$$66M)-D&9-7+8(=(s   ?B B)c                &    U R                  XU5      $ r:   r;   r<   s       r!   r=   -QuotaProjectInterceptor.intercept_unary_unary   r?   r    c                &    U R                  XU5      $ rE   r;   rF   s       r!   rH   .QuotaProjectInterceptor.intercept_stream_unary$  rJ   r    r   Nr   r   r    r!   r   r   	  s    @#9 K1r    r   c                >   ^ [        5       [        U 5      /mU4S jnU$ )z$Returns a `should_recover` callable.c                v   > [        U [        R                  5      (       d  gT H  nU" U 5      (       d  M    g   gr   )
isinstancerh   RpcError)futuremethodrecovery_methodss     r!   rr   %ShouldRecover.<locals>._ShouldRecover1  s2    fdmm,,"	 # r    )rt   r   )r   rr   r   s     @r!   ShouldRecoverr   +  s(     %&#K0 
r    c                  :   ^  \ rS rSrSr  S SU 4S jjjrSrU =r$ )BidiRpci;  z3Bidi implementation to be used throughout codebase.c                T   > [         [        U ]  UUU[        UR                  5      S9  g)a  Initializes a BidiRpc instances.

Args:
    client: GAPIC Wrapper client to use.
    start_rpc (grpc.StreamStreamMultiCallable): The gRPC method used to
      start the RPC.
    initial_request: The initial request to yield. This is useful if an
      initial request is needed to start the stream.
    metadata: The metadata headers to use for the RPC. It is a list of
      tuples. The first string in the tuple is the header name and the
      second is the header value.
)initial_requestmetadatashould_recoverN)superr   r,   r   r   )r*   client	start_rpcr   r   	__class__s        r!   r,   BidiRpc.__init__>  s0    & 
'4!'$V%7%78	 " r    r   )NN)r   zlist[tuple[str, str]] | None)r   r   r   r   r   r,   r   __classcell__)r   s   @r!   r   r   ;  s"    ; /3
 - r    r   c                      \ rS rSrSrg)_ClientCallDetailsiY  r   N)r   r   r   r   r   r   r    r!   r   r   Y  s     r    r   )r   timeoutr   r   wait_for_readycompressionc                "   ^ U " 5       mU4S jnU$ )z<Returns a function that adds headers to client call details.c                >  > T(       d  U $ / nU R                   b  [        U R                   5      nT H&  u  p#UR                  UR                  5       U45        M(     [	        U R
                  U R                  UU R                  U R                  U R                  5      nU$ r&   )
r   listappendlowerr   r   r   r   r   r   )r3   r   headerr   new_client_call_detailsheaderss        r!   
AddHeaders_AddHeaders.<locals>.AddHeaderse  s      H##/)223h oov||~u-. ! 1""$7$?$?'')<)K)K'') #"r    r   )headers_funcr   r   s     @r!   _AddHeadersr   b  s    N'#  
r    c                *    [        [        U 5      5      $ z)Returns an interceptor that adds headers.)r#   r   r   s    r!   HeaderAdderInterceptorr   x  s    	%k,&?	@@r    c                *    [        [        U 5      5      $ r   )rQ   r   r   s    r!   AsyncHeaderAdderInterceptorr   }  s     
+;|+D	EEr    zx-goog-iam-authority-selectorzx-goog-iam-authorization-tokenc                    / n [         R                  R                  R                  R	                  5       nU(       a  U R                  [        U45        Sn[         R                  R                  R                  R	                  5       nU(       a   [        R                  " U5      nU(       a%  U R                  [        UR                  5       45        U $ ! [        R                   a  n[        U5      eSnAff = f)z1Returns the IAM authorization headers to be used.N)r   VALUESauthauthority_selectorGetr   IAM_AUTHORITY_SELECTOR_HEADERauthorization_token_filer   ReadFileContentsr   IAM_AUTHORIZATION_TOKEN_HEADERstrip)r   r   authorization_tokenr   es        r!   _GetIAMAuthHeadersr     s    '!((--@@DDFNN13EFG5599; !223KL NN&!!#  
. ;; !Hns   C C7'C22C7c                      [        [        5      $ z-Returns an interceptor that adds IAM headers.)r   r   r   r    r!   IAMAuthHeadersInterceptorr     s    	 2	33r    c                      [        [        5      $ r   )r   r   r   r    r!   AsyncIAMAuthHeadersInterceptorr     s    	$%7	88r    c                     / n [         R                  R                  R                  R	                  5       nU(       a  U R                  SU45        U $ )z.Returns the request reason headers to be used.zx-goog-request-reason)r   r   corerequest_reasonr   r   )r   r   s     r!   _GetRequestReasonHeaderr     sA    '$$))88<<>.NN+^<=	.r    c                      [        [        5      $ z9Returns an interceptor that adds a request reason header.)r   r   r   r    r!   RequestReasonInterceptorr     s    	 7	88r    c                      [        [        5      $ r   )r   r   r   r    r!   AsyncRequestReasonInterceptorr     s    	$%<	==r    c                 ^    [         R                  " 5       n S[        R                  S-   U -   4/$ )z*Returns the user agent headers to be used.z
user-agent )core_transportMakeUserAgentStringr   CLOUDSDK_USER_AGENT)
user_agents    r!   _GetUserAgentHeaderr     s.    113*33c9JF
G	HHr    c                      [        [        5      $ z5Returns an interceptor that adds a user agent header.)r   r   r   r    r!   UserAgentInterceptorr     s    	 3	44r    c                      [        [        5      $ r   )r   r   r   r    r!   AsyncUserAgentInterceptorr     s    	$%8	99r    c                 x   ^ [         R                  R                  R                  R	                  5       mU4S jn U $ )z>Returns a function that sets a timeout on client call details.c                   > T(       d  U $ [        U R                  TU R                  U R                  U R                  U R
                  5      nU$ r&   )r   r   r   r   r   r   )r3   r   r   s     r!   
AddTimeout_AddTimeout.<locals>.AddTimeout  sN      0""G-@-I-I'')<)K)K'') #"r    )r   r   r   http_timeoutGetInt)r   r   s    @r!   _AddTimeoutr    s0    ""//668'# 
r    c                 (    [        [        5       5      $ z+Returns an interceptor that adds a timeout.)r#   r  r   r    r!   TimeoutInterceptorr    s    	%km	44r    c                 (    [        [        5       5      $ r  )rQ   r  r   r    r!   AsyncTimeoutInterceptorr    s    	*;=	99r    c                     / n [         R                  R                  R                  R	                  5       nU(       a  U R                  SU45        U $ )z/Returns the org restriction headers to be used.zx-goog-allowed-resources)r   r   resource_policyorg_restriction_headerr   r   )r   request_org_restriction_headerss     r!   _GetOrgRestrictionHeaderr    sH    '$.$5$5$E$E$\$\$`$` %!$NN	#%DEG	.r    c                      [        [        5      $ zBReturns an interceptor that adds a request org restriction header.)r   r  r   r    r!    RequestOrgRestrictionInterceptorr    s    	 8	99r    c                      [        [        5      $ r  )r   r  r   r    r!   %AsyncRequestOrgRestrictionInterceptorr    s    	$%=	>>r    c                      \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rSS jrSS jrSS jrS rS rS rS rS rS rSrg)WrappedStreamingResponsei  a  Wrapped streaming response.

Attributes:
  _response: A grpc.Call/grpc.Future instance representing a service response.
  _fn: Function called on each iteration of this iterator. Takes a lambda
       that produces the next response in the _response iterator.
c                    Xl         X l        g r&   )	_responser(   )r*   rn   r+   s      r!   r,   !WrappedStreamingResponse.__init__  s    NHr    c                6    U R                   R                  5       $ r&   )r  initial_metadatar{   s    r!   r  )WrappedStreamingResponse.initial_metadata  s    >>**,,r    c                6    U R                   R                  5       $ r&   )r  r   r{   s    r!   r   *WrappedStreamingResponse.trailing_metadata  s    >>++--r    c                6    U R                   R                  5       $ r&   )r  rg   r{   s    r!   rg   WrappedStreamingResponse.code      >>  r    c                6    U R                   R                  5       $ r&   )r  rl   r{   s    r!   rl    WrappedStreamingResponse.details      >>!!##r    c                6    U R                   R                  5       $ r&   )r  debug_error_stringr{   s    r!   r#  +WrappedStreamingResponse.debug_error_string  s    >>,,..r    c                6    U R                   R                  5       $ r&   )r  cancelr{   s    r!   r&  WrappedStreamingResponse.cancel  s    >>  ""r    c                6    U R                   R                  5       $ r&   )r  	cancelledr{   s    r!   r)  "WrappedStreamingResponse.cancelled      >>##%%r    c                6    U R                   R                  5       $ r&   )r  runningr{   s    r!   r-   WrappedStreamingResponse.running  r!  r    c                6    U R                   R                  5       $ r&   )r  doner{   s    r!   r0  WrappedStreamingResponse.done   r  r    Nc                4    U R                   R                  US9$ N)r   )r  resultr*   r   s     r!   r4  WrappedStreamingResponse.result#  s    >>   11r    c                4    U R                   R                  US9$ r3  )r  	exceptionr5  s     r!   r8  "WrappedStreamingResponse.exception&      >>##G#44r    c                4    U R                   R                  US9$ r3  )r  	tracebackr5  s     r!   r<  "WrappedStreamingResponse.traceback)  r:  r    c                8    U R                   R                  U5      $ r&   )r  add_done_callbackr)   s     r!   r?  *WrappedStreamingResponse.add_done_callback,  s    >>++B//r    c                8    U R                   R                  U5      $ r&   )r  add_callback)r*   callbacks     r!   rB  %WrappedStreamingResponse.add_callback/  s    >>&&x00r    c                6    U R                   R                  5       $ r&   )r  	is_activer{   s    r!   rF  "WrappedStreamingResponse.is_active2  r+  r    c                6    U R                   R                  5       $ r&   )r  time_remainingr{   s    r!   rI  'WrappedStreamingResponse.time_remaining5  s    >>((**r    c                    U $ r&   r   r{   s    r!   __iter__!WrappedStreamingResponse.__iter__8  s    Kr    c                .   ^  T R                  U 4S j5      $ )Nc                 .   > [        T R                  5      $ r&   )nextr  r{   s   r!   r   3WrappedStreamingResponse.__next__.<locals>.<lambda><  s    D0r    r'   r{   s   `r!   __next__!WrappedStreamingResponse.__next__;  s    88011r    )r(   r  r&   )r   r   r   r   r   r,   r  r   rg   rl   r#  r&  r)  r-  r0  r4  r8  r<  r?  rB  rF  rI  rL  rR  r   r   r    r!   r  r    sf    -.!$/#&$!25501&+2r    r  c                  ^    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rS rS rSrg)LoggingInterceptori?  zLogging Interceptor for logging requests and responses.

Logging is enabled if the --log-http flag is provided on any command.
Nc                    Xl         X l        g r&   _credentials_redact_request_body_reason)r*   r   redact_request_body_reasons      r!   r,   LoggingInterceptor.__init__H  s    #'A$r    c                @   [         R                  R                  R                  R	                  5       n[        U=(       d    / S S9 HT  u  p4U(       a  UR                  5       [        :X  a  Sn[        R                  R                  SR                  X45      5        MV     g)zgLogs the metadata.

Args:
  metadata: `metadata` to be transmitted to
    the service-side of the RPC.
c                    U S   $ )Nr   r   )xs    r!   r   1LoggingInterceptor.log_metadata.<locals>.<lambda>T  s    qtr    )r   z--- Token Redacted ---z{0}: {1}N)r   r   r   log_http_redact_tokenGetBoolsortedr   r   r   statusPrintformat)r*   r   redact_tokenhvs        r!   log_metadataLoggingInterceptor.log_metadataL  sn     $$))??GGILR^<	!'')'EE$	jjz((./ =r    c                   [         R                  R                  R                  R	                  5       n[
        R                  R                  S5        [
        R                  R                  S5        [
        R                  R                  SR                  UR                  5      5        [
        R                  R                  S5        U R                  (       ai  U(       a   [
        R                  R                  S5        OB[
        R                  R                  SR                  U R                  R                  5      5        U R                  UR                  5        [
        R                  R                  S5        [
        R                  R                  S5        [         R                  R                  R                  R	                  5       nU R                  b  U(       a/  [
        R                  R                  S
R                  U5      5        O8[
        R                  R                  SR                  U R                  5      5        [
        R                  R                  S5        [
        R                  R                  S5        g	)zLogs information about the request.

Args:
    client_call_details: a grpc._interceptor._ClientCallDetails
        instance containing request metadata.
    request: the request value for the RPC.
z=======================z==== request start ====z
method: {}z== headers start ==z%authorization: --- Token Redacted ---zauthorization: {}z== headers end ==z== body start ==N{}zBody redacted: {}z== body end ==z==== request end ====)r   r   r   r`  ra  r   rc  rd  re  r   rX  tokenri  r   log_http_show_request_bodyrY  )r*   r3   r4   rf  show_request_bodys        r!   log_requestLoggingInterceptor.log_requestY  s    $$))??GGILJJ./JJ./JJ\(()<)C)CDEJJ*+	

@A

,33D4E4E4K4KLM)223JJ()JJ'(99AAC  	((05F	jjt{{7+,	jj

$
$T%E%E
F JJ%&JJ,-r    c                r   [         R                  R                  S5        [         R                  R                  SR                  UR	                  5       5      5        [         R                  R                  S5        [         R                  R                  SR                  UR                  5       5      5        [         R                  R                  S5        U R                  UR                  5       5        [         R                  R                  S5        U R                  UR                  5       5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S	R                  UR                  5       5      5        [         R                  R                  S
5        [         R                  R                  SR                  U5      5        [         R                  R                  S5        [         R                  R                  S5        g)zLogs information about the request.

Args:
    response: A grpc.Call/grpc.Future instance representing a service
        response.
    time_taken: time, in seconds, it took for the RPC to complete.
---- response start ----code: {}-- headers start --details: {}-- initial metadata ---- trailing metadata ---- headers end ---- body start --rl  -- body end --z6total round trip time (request+response): {0:.3f} secs---- response end --------------------------N)
r   rc  rd  re  rg   rl   ri  r  r   r4  )r*   rn   
time_takens      r!   log_responseLoggingInterceptor.log_response{  sm    JJ/0JJZ&&x}}78JJ*+JJ]))(*:*:*<=>JJ-.h//12JJ./h0023JJ()JJ'(JJT[[!234JJ%&JJ@GG	 JJ-.JJ-.r    c              #  H   #    U H  nU R                  X5        Uv   M     g 7fr&   )rp  )r*   r3   rG   r4   s       r!   log_requestsLoggingInterceptor.log_requests  s#     #
*4m $s    "c                   [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        U R                  UR	                  5       5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  SR                  U5      5        [         R                  R                  S5        [         R                  R                  SR                  U5      5        [         R                  R                  S	5        [         R                  R                  S
5        g)zLogs information about the response.

Args:
    responses: A grpc.Call/grpc.Future instance representing a service
        response.
    response: response to log.
    time_taken: time, in seconds, it took for the RPC to complete.
rs  ru  rw  ry  rz  rl  r{  z#total time (response): {0:.3f} secsr|  r}  N)r   rc  rd  ri  r  re  )r*   	responsesrn   r~  s       r!   log_streaming_response)LoggingInterceptor.log_streaming_response  s     JJ/0JJ*+JJ-.i0023JJ()JJ'(JJT[[*+JJ%&JJ-44Z@BJJ-.JJ-.r    c                Z   ^ ^ U 4S jnUU 4S jnTR                  U5        [        TU5      $ )Nc                  > [         R                  R                  S5        [         R                  R                  SR                  U R	                  5       5      5        [         R                  R                  S5        [         R                  R                  SR                  U R                  5       5      5        [         R                  R                  S5        TR                  U R                  5       5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        g )	Nrs  rt  ru  rv  rx  ry  r|  r}  )r   rc  rd  re  rg   rl   ri  r   )rn   r*   s    r!   OnDone0LoggingInterceptor.log_responses.<locals>.OnDone  s    	jj12	jjz((9:	jj,-	jj}++H,<,<,>?@	jj01
2245	jj*+	jj/0	jj/0r    c                   > [         R                   " 5       nU " 5       n[         R                   " 5       U-
  nTR                  TX#5        U$ r&   )timer  )result_generator_func
start_timern   r~  r  r*   s       r!   LogResponse5LoggingInterceptor.log_responses.<locals>.LogResponse  s;    99;j&(h99;+j
!!)XBor    )r?  r  )r*   r  r  r  s   ``  r!   log_responses LoggingInterceptor.log_responses  s*    	1 '#I{;;r    c                    U R                  X#5        [        R                  " 5       nU" X#5      n[        R                  " 5       U-
  nU R                  XV5        U$ a  Intercepts and logs API interactions.

Overrides abstract method defined in grpc.UnaryUnaryClientInterceptor.
Args:
    continuation: a function to continue the request process.
    client_call_details: a grpc._interceptor._ClientCallDetails
        instance containing request metadata.
    request: the request value for the RPC.
Returns:
    A grpc.Call/grpc.Future instance representing a service response.
)rp  r  r  r*   r2   r3   r4   r  rn   r~  s          r!   r=   (LoggingInterceptor.intercept_unary_unary  sL     	(2J/9Hz)Jh+Or    c                V    U R                  X#5        U" X#5      nU R                  U5      $ rA   )rp  r  )r*   r2   r3   r4   rn   s        r!   rB   )LoggingInterceptor.intercept_unary_stream  s/     	(2/9Hh''r    c                    [         R                   " 5       nU" UU R                  X#5      5      n[         R                   " 5       U-
  nU R                  XV5        U$ rE   )r  r  r  )r*   r2   r3   rG   r  rn   r~  s          r!   rH   )LoggingInterceptor.intercept_stream_unary  sQ     J-@BH z)Jh+Or    c                T    U" UU R                  X#5      5      nU R                  U5      $ rL   )r  r  )r*   r2   r3   rG   rn   s        r!   rM   *LoggingInterceptor.intercept_stream_stream  s4     -@BH h''r    rW  r&   )r   r   r   r   r   r,   ri  rp  r  r  r  r  r=   rB   rH   rM   r   r   r    r!   rU  rU  ?  s@    
B0 .D/4
/,<,*(	(r    rU  c                      \ rS rSrSrS rSrg)RPCDurationReporterInterceptori  zInterceptor for reporting RPC Durations.

We only report durations for unary-unary RPCs as some streaming RPCs have
arbitrary duration. i.e. How long they take is decided by the user.
c                    [         R                   " 5       nU" X#5      n[         R                   " 5       U-
  n[        R                  " U5        U$ r  )r  r   RPCDurationr  s          r!   r=   4RPCDurationReporterInterceptor.intercept_unary_unary  s=     J/9Hz)J
#Or    r   N)r   r   r   r   r   r=   r   r   r    r!   r  r    s    r    r  c                <   [         R                  R                  R                  R	                  5       nSnSn[
        R                  " 5       nU (       a  U(       ax  UR                  [
        R                  R                  :X  a.  [        R                  " S5        UR                  UR                  p2O"[        R                  " SUR                  5        gU(       d  U(       d  U(       a6  U(       a  [        R                  " U5      nOSn[         R"                  " UUUS9$ g)zReturns SSL credentials.Nz%Using On Disk Certificate for mTLS...z7Not using On Disk Certificate for mTLS, config type: %s)root_certificatescertificate_chainprivate_key)r   r   r   custom_ca_certs_filer   r   Configconfig_type
ConfigTypeON_DISK_CERTIFICATEr   debugclient_cert_bytesclient_key_bytesr   ReadBinaryFileContentsrh   ssl_channel_credentials)mtls_enabledca_certs_filer  r  	ca_configca_certss         r!   GetSSLCredentialsr    s    ##((==AAC-+""$)i 8 8 L LL	ii78

%
%

$
$ %
 
ii
C


 ';--m<hh''"+! ! 
r    c                    [         R                  R                  R                  R	                  5       n [         R                  R                  R
                  R	                  5       n[         R                  R                  R                  R                  5       n[        XU4 Vs/ s H  o3(       d  M  UPM     sn5      nUS:  a  US:w  a  [         R                  " S5      eU(       d  g[         R                  R                  R                  R	                  5       n[         R                  R                  R                  R	                  5       n[        R                  U    nU[        R                  :w  a  [!        SR#                  U 5      5      eU(       d  U(       a  SR%                  S XV4 5       5      nUS-  nOS	nS
R#                  XU5      $ s  snf )z@Returns the proxy string for use by grpc from gcloud properties.r      z\Please set all or none of the following properties: proxy/type, proxy/address and proxy/portNz#Unsupported proxy type for gRPC: {}:c              3  r   #    U  H-  n[         R                  R                  U5      =(       d    S v   M/     g7f) N)r   parsequote).0r^  s     r!   	<genexpr>*MakeProxyFromProperties.<locals>.<genexpr>L  s,      G-E1##-Es   57@r  zhttp://{}{}:{})r   r   proxy
proxy_typer   addressportr  lenInvalidValueErrorusernamepasswordr   PROXY_TYPE_MAPsocksPROXY_TYPE_HTTP
ValueErrorre  join)	r  proxy_address
proxy_portfproxy_prop_set
proxy_user
proxy_passhttp_proxy_type
proxy_auths	            r!   MakeProxyFromPropertiesr  4  sz     &&11557*##))11557-  &&++224*j9?9QQq9?A.aNa/

&
&	34 4 

  &&//335*  &&//335*$33J?/---
:AA*M
NN: G.8-EG GJ#JJ		 	 J	GG- @s   "
G0Gc                 v    S H3  n [         R                  " [        R                  U 5      nU(       d  M1  Us  $    g)zCReturns the proxy string for use by grpc from environment variable.)
GRPC_PROXY
HTTP_PROXYHTTPS_PROXYN)r   GetEncodedValueosenviron)envr  s     r!   !MakeProxyFromEnvironmentVariablesr  T  s3    
 9c$$RZZ5Eul 9 
r    c                 x    SSS.n [        5       nU(       d
  [        5       nU(       a  XS'   U R                  5       $ )zReturns channel arguments for the underlying gRPC channel.

See https://grpc.github.io/grpc/python/glossary.html#term-channel_arguments.
)zgrpc.max_send_message_lengthzgrpc.max_receive_message_lengthzgrpc.http_proxy)r  r  items)optionsr  s     r!   MakeChannelOptionsr  `  s>     '))+'
 "
#%	-/E
!&	r    c                b    U(       a  U R                   $ U R                  nU(       a  U" U5      nU$ r&   )DEFAULT_MTLS_ENDPOINTDEFAULT_ENDPOINT)client_classaddress_override_funcr  r  s       r!   _GetAddressr  t  s.    ---))'#G,G	.r    c                   U R                  5       n[        XU5      nUR                  UU[        U5      [	        5       US9n	/ n
U
R                  [        5       5        U
R                  [        5       5        U
R                  [        5       5        U
R                  [        5       5        U
R                  [        5       5        U
R                  [        U5      5        U
R                  [        5       5        U
R                  [        5       5        [        R                  R                   R"                  R%                  5       (       a  U
R                  ['        UUS95        Ub  U
R)                  U5        [*        R,                  " U	/U
Q76 n	U" XS9$ )Instantiates a grpc transport.)hostr   ssl_credentialsr  attempt_direct_path)rZ  channelr  )get_transport_classr  create_channelr  r  r   r   r   r  r   r  r   rv   r  r   r   r   log_httpra  rU  extendrh   intercept_channel)r  r   r  r  r  rZ  custom_interceptorstransport_classr  r  interceptorss              r!   MakeTransportr  ~  sW    !446/\J'**'5 "- + ' ,.01*,-(*+/12467-k:;.01689$$,,..'A	
 $+,""7:\:'		77r    c           	        U R                  S5      n[        XU5      n/ nUR                  [        5       5        UR                  [	        5       5        UR                  [        5       5        UR                  [        5       5        UR                  [        5       5        UR                  UU[        U5      [        5       UUS9nU" UUS9$ )r  grpc_asyncio)r  r   r  r  r  r  r  )r  r  r   r   r   r  r   r  r  r  r  )	r  r   r  r  r  r  r  r  r  s	            r!   MakeAsyncTransportr    s     !44^D/\J',356/12-/0467;=>**'5 "- + ' 

 r    )FFNN)FF)Vr   
__future__r   r   r   r   collectionsr  r  google.api_corer   
google.rpcr   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   googlecloudsdk.corer   r   r   r   r   r   r   r   googlecloudsdk.core.credentialsgooglecloudsdk.core.utilr   r   r   rh   	six.movesr   r  r   UnaryUnaryClientInterceptorUnaryStreamClientInterceptorStreamUnaryClientInterceptorStreamStreamClientInterceptorr#   aiorQ   rt   rv   r   r   r   r   ResumableBidiRpcr   
namedtupleClientCallDetailsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  CallFuturer  rU  r  r  r  r  r  r  r  r  r   r    r!   <module>r     sa   D & "  '  	    ( 6 ( & - * # ' * ; 5 - * 5   )J )<14#C#C#'#D#D#'#D#D#'#E#E<1~=1(L(L(,(M(M(,(M(M(,(N(N=1@*#1t??#@@#1L$1d>>"??1D d## < 	 	,A
F !@ !A 24
9
9
>
I5
:
5
:
:
?
A2tyy$++ A2Hu(99::::;;u(pT%E%E 6DH@	( #)8` r    