
    BfZ                     f   d Z ddlmZmZmZmZ ddlZddlZddlZddl	Z	ddl
mZ ddlZddlZddlZddlZddlZej        j        Zedd         dk    r&	 ddlZ ej        de           dZn# e$ r d	ZY nw xY wd	Ze	j        e	j        fZ ed
          Zd Zd Z G d dee         e	j                   Z!e!e         Z"d Z#d Z$	 	 	 	 	 	 	 d dZ%	 	 	 	 	 	 	 	 	 d!dee&         fdZ'de(de(fdZ) ej*        dd          Z+ ej*        dd          Z, G d de-          Z.d Z/ G d de	j0                  Z1dS )"zHelpers for :mod:`grpc`.    )GenericIteratorOptionalTypeVarN)
exceptions   z3.zSupport for grpcio-gcp is deprecated. This feature will be
            removed from `google-api-core` after January 1, 2024. If you need to
            continue to use this feature, please pin to a specific version of
            `google-api-core`.TFPc                 L    t          | d          s| j        j        | _        dS dS )zFix-up gRPC callable attributes.

    gRPC callable lack the ``__name__`` attribute which causes
    :func:`functools.wraps` to error. This adds the attribute if needed.
    __name__N)hasattr	__class__r   	callable_s    k/home/panchajanya/Development/work/volatility3/lib/python3.11/site-packages/google/api_core/grpc_helpers.py_patch_callable_namer   ;   s4     9j)) :&09	: :    c                 d     t                      t          j                    fd            }|S )z;Map errors for Unary-Unary and Stream-Unary gRPC callables.c                  n    	  | i |S # t           j        $ r}t          j        |          |d }~ww xY wN)grpcRpcErrorr   from_grpc_error)argskwargsexcr   s      r   error_remapped_callablez3_wrap_unary_errors.<locals>.error_remapped_callableI   sQ    	;9d-f---} 	; 	; 	;,S11s:	;s    4/4r   	functoolswrapsr   r   s   ` r   _wrap_unary_errorsr!   E   sG    ###_Y; ; ; ;  ; #"r   c                   j    e Zd ZddZdee         fdZdefdZd Zd Z	d Z
d	 Zd
 Zd Zd Zd ZdS )_StreamingResponseIteratorTc                     || _         	 |rt          | j                   | _        d S d S # t          $ r Y d S t          $ r Y d S w xY wr   )_wrappednext_stored_first_result	TypeErrorStopIteration)selfwrappedprefetch_first_results      r   __init__z#_StreamingResponseIterator.__init__T   sx    
		$ @,0,?,?)))@ @ 	 	 	 DD 	 	 	DD	s   ( 
A	AAreturnc                     | S )z6This iterator is also an iterable that returns itself. r*   s    r   __iter__z#_StreamingResponseIterator.__iter__e   s    r   c                     	 t          | d          r| j        }| `|S t          | j                  S # t          j        $ r}t          j        |          |d}~ww xY w)zGet the next response from the stream.

        Returns:
            protobuf.Message: A single response from the stream.
        r'   N)r   r'   r&   r%   r   r   r   r   )r*   resultr   s      r   __next__z#_StreamingResponseIterator.__next__i   sq    	;t344 2-&&&} 	; 	; 	;,S11s:	;s   1 1 A AAc                 6    | j                             |          S r   )r%   add_callbackr*   callbacks     r   r7   z'_StreamingResponseIterator.add_callback{   s    }))(333r   c                 4    | j                                         S r   )r%   cancelr1   s    r   r;   z!_StreamingResponseIterator.cancel~   s    }##%%%r   c                 4    | j                                         S r   )r%   coder1   s    r   r=   z_StreamingResponseIterator.code   s    }!!###r   c                 4    | j                                         S r   )r%   detailsr1   s    r   r?   z"_StreamingResponseIterator.details   s    }$$&&&r   c                 4    | j                                         S r   )r%   initial_metadatar1   s    r   rA   z+_StreamingResponseIterator.initial_metadata   s    }--///r   c                 4    | j                                         S r   )r%   	is_activer1   s    r   rC   z$_StreamingResponseIterator.is_active   s    }&&(((r   c                 4    | j                                         S r   )r%   time_remainingr1   s    r   rE   z)_StreamingResponseIterator.time_remaining   s    }++---r   c                 4    | j                                         S r   )r%   trailing_metadatar1   s    r   rG   z,_StreamingResponseIterator.trailing_metadata   s    }..000r   N)T)r   
__module____qualname__r-   r   r	   r2   r5   r7   r;   r=   r?   rA   rC   rE   rG   r0   r   r   r#   r#   S   s           "(1+    ;! ; ; ; ;$4 4 4& & &$ $ $' ' '0 0 0) ) ). . .1 1 1 1 1r   r#   c                 d     t                      t          j                    fd            }|S )a  Wrap errors for Unary-Stream and Stream-Stream gRPC callables.

    The callables that return iterators require a bit more logic to re-map
    errors when iterating. This wraps both the initial invocation and the
    iterator of the return value to re-map errors.
    c                      	  | i |}t          dd          }t          ||          S # t          j        $ r}t	          j        |          |d }~ww xY w)N_prefetch_first_result_T)r,   )getattrr#   r   r   r   r   )r   r   r4   prefetch_firstr   r   s        r   r   z4_wrap_stream_errors.<locals>.error_remapped_callable   s    	;Y///F
 %Y0I4PPN-n    } 	; 	; 	;,S11s:	;s   )- AAAr   r    s   ` r   _wrap_stream_errorsrO      sI     ###_Y; ; ; ;  ; #"r   c                 h    t          | t                    rt          |           S t          |           S )a.  Wrap a gRPC callable and map :class:`grpc.RpcErrors` to friendly error
    classes.

    Errors raised by the gRPC callable are mapped to the appropriate
    :class:`google.api_core.exceptions.GoogleAPICallError` subclasses.
    The original `grpc.RpcError` (which is usually also a `grpc.Call`) is
    available from the ``response`` property on the mapped exception. This
    is useful for extracting metadata from the original error.

    Args:
        callable_ (Callable): A gRPC callable.

    Returns:
        Callable: The wrapped gRPC callable.
    )
isinstance_STREAM_WRAP_CLASSESrO   r!   r   s    r   wrap_errorsrS      s3      )122 -"9---!),,,r   c                    | r|rt          j        d          |r&t          j                            |||          \  } }nN| r(t          j        j                            | ||          } n$t          j                            ||          \  } }|r9t          | t          j        j        j	                  r| 
                    |          } t          j        j        j                                        }t          j        j        j                            | ||          }	t          j        |	          }
|rt          j        ||
          S t          j        |
          S )a  Create the composite credentials for secure channels.

    Args:
        credentials (google.auth.credentials.Credentials): The credentials. If
            not specified, then this function will attempt to ascertain the
            credentials from the environment using :func:`google.auth.default`.
        credentials_file (str): A file with credentials that can be loaded with
            :func:`google.auth.load_credentials_from_file`. This argument is
            mutually exclusive with credentials.
        default_scopes (Sequence[str]): A optional list of scopes needed for this
            service. These are only used when credentials are not specified and
            are passed to :func:`google.auth.default`.
        scopes (Sequence[str]): A optional list of scopes needed for this
            service. These are only used when credentials are not specified and
            are passed to :func:`google.auth.default`.
        ssl_credentials (grpc.ChannelCredentials): Optional SSL channel
            credentials. This can be used to specify different certificates.
        quota_project_id (str): An optional project to use for billing and quota.
        default_host (str): The default endpoint. e.g., "pubsub.googleapis.com".

    Returns:
        grpc.ChannelCredentials: The composed channel credentials object.

    Raises:
        google.api_core.DuplicateCredentialArgs: If both a credentials object and credentials_file are passed.
    z<'credentials' and 'credentials_file' are mutually exclusive.)scopesdefault_scopes)default_host)r   DuplicateCredentialArgsgoogleauthload_credentials_from_filecredentialswith_scopes_if_requireddefaultrQ   CredentialsWithQuotaProjectwith_quota_project	transportrequestsRequestr   AuthMetadataPluginmetadata_call_credentialscomposite_channel_credentials"compute_engine_channel_credentials)r\   credentials_filerV   rU   ssl_credentialsquota_project_idrW   _requestmetadata_plugingoogle_auth_credentialss              r   _create_composite_credentialsro      s   F  
' 
0J
 
 	
  
??VN @ 
 
QQ 
 
k-EE~ F 
 
  ,,. - 
 
Q  GJV[,H  G "445EFFk#,4466G k+0CC! D  O #<_MM
  P 14
 
 	
 67NOOOr   attempt_direct_pathc
           	      n   |r|	rt          d          t          |||||||          }t          r`|/|t          j        j        k    rt          j        dt                     |	rt          j        dt                     t          j
        | |fi |
S |	rt          |           } t          j
        | |fd|i|
S )a  Create a secure channel with credentials.

    Args:
        target (str): The target service address in the format 'hostname:port'.
        credentials (google.auth.credentials.Credentials): The credentials. If
            not specified, then this function will attempt to ascertain the
            credentials from the environment using :func:`google.auth.default`.
        scopes (Sequence[str]): A optional list of scopes needed for this
            service. These are only used when credentials are not specified and
            are passed to :func:`google.auth.default`.
        ssl_credentials (grpc.ChannelCredentials): Optional SSL channel
            credentials. This can be used to specify different certificates.
        credentials_file (str): A file with credentials that can be loaded with
            :func:`google.auth.load_credentials_from_file`. This argument is
            mutually exclusive with credentials.
        quota_project_id (str): An optional project to use for billing and quota.
        default_scopes (Sequence[str]): Default scopes passed by a Google client
            library. Use 'scopes' for user-defined scopes.
        default_host (str): The default endpoint. e.g., "pubsub.googleapis.com".
        compression (grpc.Compression): An optional value indicating the
            compression method to be used over the lifetime of the channel.
        attempt_direct_path (Optional[bool]): If set, Direct Path will be attempted
            when the request is made. Direct Path is only available within a Google
            Compute Engine (GCE) environment and provides a proxyless connection
            which increases the available throughput, reduces latency, and increases
            reliability. Note:

            - This argument should only be set in a GCE environment and for Services
              that are known to support Direct Path.
            - If this argument is set outside of GCE, then this request will fail
              unless the back-end service happens to have configured fall-back to DNS.
            - If the request causes a `ServiceUnavailable` response, it is recommended
              that the client repeat the request with `attempt_direct_path` set to
              `False` as the Service may not support Direct Path.
            - Using `ssl_credentials` with `attempt_direct_path` set to `True` will
              result in `ValueError` as this combination  is not yet supported.

        kwargs: Additional key-word args passed to
            :func:`grpc_gcp.secure_channel` or :func:`grpc.secure_channel`.
            Note: `grpc_gcp` is only supported in environments with protobuf < 4.0.0.

    Returns:
        grpc.Channel: The created channel.

    Raises:
        google.api_core.DuplicateCredentialArgs: If both a credentials object and credentials_file are passed.
        ValueError: If `ssl_credentials` is set and `attempt_direct_path` is set to `True`.
    z7Using ssl_credentials with Direct Path is not supported)r\   rh   rV   rU   ri   rj   rW   NzKThe `compression` argument is ignored for grpc_gcp.secure_channel creation.zSThe `attempt_direct_path` argument is ignored for grpc_gcp.secure_channel creation.compression)
ValueErrorro   HAS_GRPC_GCPr   CompressionNoCompressionwarningswarnDeprecationWarninggrpc_gcpsecure_channel_modify_target_for_direct_path)targetr\   rU   ri   rh   rj   rV   rW   rr   rp   r   composite_credentialss               r   create_channelr   #  s   B  T. TRSSS9)%')!    P"{d6F6T'T'TM]"    	Mi"   &v/DOOOOO 8/77% 3>BH  r   r}   r.   c                     d}|                      |d          } d}|| vr"|                     d          d         }d| | } | S )ag  
    Given a target, return a modified version which is compatible with Direct Path.

    Args:
        target (str): The target service address in the format 'hostname[:port]' or
            'dns://hostname[:port]'.

    Returns:
        target (str): The target service address which is converted into a format compatible with Direct Path.
            If the target contains `dns:///` or does not contain `:///`, the target will be converted in
            a format compatible with Direct Path; otherwise the original target will be returned as the
            original target may already denote Direct Path.
    zdns:/// z:///:r   z
google-c2p)replacesplit)r}   
dns_prefixdirect_path_separatortarget_without_ports       r   r|   r|     s_    " J ^^J++F"F**$ll3//2J3J5HJJMr   _MethodCall)rl   timeoutmetadatar\   rr   _ChannelRequest)methodrl   c                   "    e Zd ZdZd Z	 ddZdS )_CallableStubz,Stub for the grpc.*MultiCallable interfaces.c                 `    || _         || _        d | _        	 d | _        	 g | _        	 g | _        d S r   )_method_channelresponse	responsesrb   calls)r*   r   channels      r   r-   z_CallableStub.__init__  sJ    	
 	C I
	E 	Er   Nc           	      B   | j         j                            t          | j        |                     | j                            t          |||||                     | j                            |           | j        }| j        ?|t          | j                  }n(t          d                    | j                            t          |          r ||          S t          |t                    r|||S t          d                    | j                            )Nz@{method}.response and {method}.responses are mutually exclusive.r   z%Method stub for "{}" has no response.)r   rb   appendr   r   r   r   r   r   r&   rs   formatcallablerQ   	Exception)r*   rl   r   r   r\   rr   r   s          r   __call__z_CallableStub.__call__  s    	%%odlG&L&LMMM
(KMM	
 	
 	
 	W%%%=>%// !!'t|!<!<  
 H 	%8G$$$h	** 	NO@GGUUVVVr   )NNNN)r   rH   rI   __doc__r-   r   r0   r   r   r   r     sM        66E E E* SWW W W W W Wr   r   c                 R    |                      dd                                          S )am  Simplifies a gRPC method name.

    When gRPC invokes the channel to create a callable, it gives a full
    method name like "/google.pubsub.v1.Publisher/CreateTopic". This
    returns just the name of the method, in this case "CreateTopic".

    Args:
        method (str): The name of the method.

    Returns:
        str: The simplified name of the method.
    /   )rsplitpopr   s    r   _simplify_method_namer     s$     ==a  $$&&&r   c                   t    e Zd ZdZg fdZd Zd Z	 	 	 ddZ	 	 	 ddZ	 	 	 dd	Z		 	 	 dd
Z
ddZd Zd ZdS )ChannelStuba  A testing stub for the grpc.Channel interface.

    This can be used to test any client that eventually uses a gRPC channel
    to communicate. By passing in a channel stub, you can configure which
    responses are returned and track which requests are made.

    For example:

    .. code-block:: python

        channel_stub = grpc_helpers.ChannelStub()
        client = FooClient(channel=channel_stub)

        channel_stub.GetFoo.response = foo_pb2.Foo(name='bar')

        foo = client.get_foo(labels=['baz'])

        assert foo.name == 'bar'
        assert channel_stub.GetFoo.requests[0].labels = ['baz']

    Each method on the stub can be accessed and configured on the channel.
    Here's some examples of various configurations:

    .. code-block:: python

        # Return a basic response:

        channel_stub.GetFoo.response = foo_pb2.Foo(name='bar')
        assert client.get_foo().name == 'bar'

        # Raise an exception:
        channel_stub.GetFoo.response = NotFound('...')

        with pytest.raises(NotFound):
            client.get_foo()

        # Use a sequence of responses:
        channel_stub.GetFoo.responses = iter([
            foo_pb2.Foo(name='bar'),
            foo_pb2.Foo(name='baz'),
        ])

        assert client.get_foo().name == 'bar'
        assert client.get_foo().name == 'baz'

        # Use a callable

        def on_get_foo(request):
            return foo_pb2.Foo(name='bar' + request.id)

        channel_stub.GetFoo.response = on_get_foo

        assert client.get_foo(id='123').name == 'bar123'
    c                 $    g | _         	 i | _        d S r   )rb   _method_stubs)r*   r   s     r   r-   zChannelStub.__init__*  s    	  r   c                 j    t          |          }t          ||           | j        |<   | j        |         S r   )r   r   r   )r*   r   s     r   _stub_for_methodzChannelStub._stub_for_method1  s4    &v..%264%@%@6"!&))r   c                 H    	 | j         |         S # t          $ r t          w xY wr   )r   KeyErrorAttributeError)r*   keys     r   __getattr__zChannelStub.__getattr__6  s6    	!%c** 	! 	! 	!  	!s    !NFc                 ,    |                      |          S )z(grpc.Channel.unary_unary implementation.r   r*   r   request_serializerresponse_deserializer_registered_methods        r   unary_unaryzChannelStub.unary_unary<       $$V,,,r   c                 ,    |                      |          S )z)grpc.Channel.unary_stream implementation.r   r   s        r   unary_streamzChannelStub.unary_streamF  r   r   c                 ,    |                      |          S )z)grpc.Channel.stream_unary implementation.r   r   s        r   stream_unaryzChannelStub.stream_unaryP  r   r   c                 ,    |                      |          S )z*grpc.Channel.stream_stream implementation.r   r   s        r   stream_streamzChannelStub.stream_streamZ  r   r   c                     dS )z&grpc.Channel.subscribe implementation.Nr0   )r*   r9   try_to_connects      r   	subscribezChannelStub.subscribed      r   c                     dS )z(grpc.Channel.unsubscribe implementation.Nr0   r8   s     r   unsubscribezChannelStub.unsubscribeh  r   r   c                     dS )z"grpc.Channel.close implementation.Nr0   r1   s    r   closezChannelStub.closel  r   r   )NNF)F)r   rH   rI   r   r-   r   r   r   r   r   r   r   r   r   r0   r   r   r   r     s       5 5n "$        * * *
! ! !  " - - - -  " - - - -  " - - - -  " - - - -         r   r   )NNNNNNN)	NNNNNNNNF)2r   typingr   r   r   r   collectionsr   rw   r   google.api_corer   google.authrY   google.auth.credentialsgoogle.auth.transport.grpcgoogle.auth.transport.requestsgoogle.protobufprotobuf__version__PROTOBUF_VERSIONrz   rx   ry   rt   ImportErrorUnaryStreamMultiCallableStreamStreamMultiCallablerR   r	   r   r!   Callr#   
GrpcStreamrO   rS   ro   boolr   strr|   
namedtupler   r   objectr   r   Channelr   r0   r   r   <module>r      s      7 7 7 7 7 7 7 7 7 7 7 7           & & & & & &         ! ! ! ! % % % %    ?.  AaCD  " 	
 	
 	
     L 5t7UV  GCLL: : :# # #>1 >1 >1 >1 >1TY >1 >1 >1D (*
# # #6- - -. WP WP WP WPx */a a "$a a a aH3 3    < %k$S  )+():<QRR3W 3W 3W 3W 3WF 3W 3W 3Wl' ' ' | | | | |$, | | | | |s   A, ,A65A6