U
    ڲgA                    @   s  d Z ddl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m	Z
 ddlmZ ddlmZ ddlmZ eee  zddlmZ W n ek
r   d	ZY nX G d
d deZG dd deZG dd dejZejG dd dejZejG dd dejZG dd dejZG dd deZ G dd dejZ!G dd de!ej"dZ#G dd dejZ$G dd  d ejZ%G d!d" d"ejZ&G d#d$ d$ejZ'G d%d& d&ejZ(G d'd( d(e)Z*G d)d* d*e)Z+G d+d, d,ejZ,G d-d. d.ejZ-G d/d0 d0ejZ.G d1d2 d2e)Z/G d3d4 d4e)Z0G d5d6 d6ejZ1G d7d8 d8ejZ2G d9d: d:ejZ3G d;d< d<ejZ4G d=d> d>ejZ5G d?d@ d@e!ej"dZ6G dAdB dBejZ7G dCdD dDejZ8G dEdF dFejZ9G dGdH dHe9ej"dZ:G dIdJ dJejZ;G dKdL dLejZ<ddMdNZ=ddOdPZ>ddQdRZ?ddSdTZ@dUdV ZAddWdXZBddYdZZCdd[d\ZDd]d^ ZEd_d` ZFdadb ZGddddeZHdfdg ZIdhdi ZJddjdkZKddldmZLejG dndo doejZMeMjNfdpdqZOeMjNfdrdsZPddtduZQdvdw ZRdxdy ZSdzd{ ZTdd|d}ZUdd~dZVdd ZWdddZXejYdd ZZejG dd dej[Z\dZ]zddl^Z^ej_`de^i W n ek
rn   Y nX zddlaZaej_`deai W n ek
r   Y nX zddlbZbej_`debi W n ek
r   Y nX ejcdkr
edkr
ddlmdZd ej_`dedi dS )zgRPC's Python API.    N)_compression)cygrpc)protos)protos_and_services)services)__version__Zdev0c                   @   s   e Zd ZdZdS )FutureTimeoutErrorz3Indicates that a method call on a Future timed out.N__name__
__module____qualname____doc__ r   r   1/tmp/pip-unpacked-wheel-8poujhl6/grpc/__init__.pyr   '   s   r   c                   @   s   e Zd ZdZdS )FutureCancelledErrorzAIndicates that the computation underlying a Future was cancelled.Nr	   r   r   r   r   r   +   s   r   c                   @   s   e Zd ZdZejdd Zejdd Zejdd Zejdd	 Z	ejdddZ
ejdddZejdddZejdd Zd
S )FuturezA representation of a computation in another control flow.

    Computations represented by a Future may be yet to be begun,
    may be ongoing, or may have already completed.
    c                 C   s
   t  dS )a  Attempts to cancel the computation.

        This method does not block.

        Returns:
            bool:
            Returns True if the computation was canceled.

            Returns False under all other circumstances, for example:

            1. computation has begun and could not be canceled.
            2. computation has finished
            3. computation is scheduled for execution and it is impossible
                to determine its state without blocking.
        NNotImplementedErrorselfr   r   r   cancel6   s    zFuture.cancelc                 C   s
   t  dS )a  Describes whether the computation was cancelled.

        This method does not block.

        Returns:
            bool:
            Returns True if the computation was cancelled before its result became
            available.

            Returns False under all other circumstances, for example:

            1. computation was not cancelled.
            2. computation's result is available.
        Nr   r   r   r   r   	cancelledI   s    zFuture.cancelledc                 C   s
   t  dS )a.  Describes whether the computation is taking place.

        This method does not block.

        Returns:
            Returns True if the computation is scheduled for execution or
            currently executing.

            Returns False if the computation already executed or was cancelled.
        Nr   r   r   r   r   running[   s    zFuture.runningc                 C   s
   t  dS )a  Describes whether the computation has taken place.

        This method does not block.

        Returns:
            bool:
            Returns True if the computation already executed or was cancelled.
            Returns False if the computation is scheduled for execution or
            currently executing.
            This is exactly opposite of the running() method's result.
        Nr   r   r   r   r   donei   s    zFuture.doneNc                 C   s
   t  dS )a  Returns the result of the computation or raises its exception.

        This method may return immediately or may block.

        Args:
          timeout: The length of time in seconds to wait for the computation to
            finish or be cancelled. If None, the call will block until the
            computations's termination.

        Returns:
          The return value of the computation.

        Raises:
          FutureTimeoutError: If a timeout value is passed and the computation
            does not terminate within the allotted time.
          FutureCancelledError: If the computation was cancelled.
          Exception: If the computation raised an exception, this call will
            raise the same exception.
        Nr   r   timeoutr   r   r   resultx   s    zFuture.resultc                 C   s
   t  dS )a  Return the exception raised by the computation.

        This method may return immediately or may block.

        Args:
          timeout: The length of time in seconds to wait for the computation to
            terminate or be cancelled. If None, the call will block until the
            computations's termination.

        Returns:
            The exception raised by the computation, or None if the computation
            did not raise an exception.

        Raises:
          FutureTimeoutError: If a timeout value is passed and the computation
            does not terminate within the allotted time.
          FutureCancelledError: If the computation was cancelled.
        Nr   r   r   r   r   	exception   s    zFuture.exceptionc                 C   s
   t  dS )a  Access the traceback of the exception raised by the computation.

        This method may return immediately or may block.

        Args:
          timeout: The length of time in seconds to wait for the computation
            to terminate or be cancelled. If None, the call will block until
            the computation's termination.

        Returns:
            The traceback of the exception raised by the computation, or None
            if the computation did not raise an exception.

        Raises:
          FutureTimeoutError: If a timeout value is passed and the computation
            does not terminate within the allotted time.
          FutureCancelledError: If the computation was cancelled.
        Nr   r   r   r   r   	traceback   s    zFuture.tracebackc                 C   s
   t  dS )aT  Adds a function to be called at completion of the computation.

        The callback will be passed this Future object describing the outcome
        of the computation.  Callbacks will be invoked after the future is
        terminated, whether successfully or not.

        If the computation has already completed, the callback will be called
        immediately.

        Exceptions raised in the callback will be logged at ERROR level, but
        will not terminate any threads of execution.

        Args:
          fn: A callable taking this Future object as its single parameter.
        Nr   )r   fnr   r   r   add_done_callback   s    zFuture.add_done_callback)N)N)N)r
   r   r   r   abcabstractmethodr   r   r   r   r   r   r   r    r   r   r   r   r   /   s"   



r   c                   @   sL   e Zd ZdZejjdfZejjdfZ	ejj
dfZejjdfZejjdfZdS )ChannelConnectivityaw  Mirrors grpc_connectivity_state in the gRPC Core.

    Attributes:
      IDLE: The channel is idle.
      CONNECTING: The channel is connecting.
      READY: The channel is ready to conduct RPCs.
      TRANSIENT_FAILURE: The channel has seen a failure from which it expects
        to recover.
      SHUTDOWN: The channel has seen a failure from which it cannot recover.
    idle
connectingreadyztransient failureshutdownN)r
   r   r   r   _cygrpcZConnectivityStater$   ZIDLEr%   Z
CONNECTINGr&   ZREADYZtransient_failureZTRANSIENT_FAILUREr'   ZSHUTDOWNr   r   r   r   r#      s   r#   c                   @   s   e Zd ZdZejjdfZejjdfZ	ejj
dfZejjdfZejjdfZejjdfZejjdfZejjd	fZejjd
fZejjdfZejjdfZejjdfZejjdfZejj dfZ!ejj"dfZ#ejj$dfZ%ejj&dfZ'dS )
StatusCodea  Mirrors grpc_status_code in the gRPC Core.

    Attributes:
      OK: Not an error; returned on success
      CANCELLED: The operation was cancelled (typically by the caller).
      UNKNOWN: Unknown error.
      INVALID_ARGUMENT: Client specified an invalid argument.
      DEADLINE_EXCEEDED: Deadline expired before operation could complete.
      NOT_FOUND: Some requested entity (e.g., file or directory) was not found.
      ALREADY_EXISTS: Some entity that we attempted to create (e.g., file or directory)
        already exists.
      PERMISSION_DENIED: The caller does not have permission to execute the specified
        operation.
      UNAUTHENTICATED: The request does not have valid authentication credentials for the
        operation.
      RESOURCE_EXHAUSTED: Some resource has been exhausted, perhaps a per-user quota, or
        perhaps the entire file system is out of space.
      FAILED_PRECONDITION: Operation was rejected because the system is not in a state
        required for the operation's execution.
      ABORTED: The operation was aborted, typically due to a concurrency issue
        like sequencer check failures, transaction aborts, etc.
      UNIMPLEMENTED: Operation is not implemented or not supported/enabled in this service.
      INTERNAL: Internal errors.  Means some invariants expected by underlying
        system has been broken.
      UNAVAILABLE: The service is currently unavailable.
      DATA_LOSS: Unrecoverable data loss or corruption.
    okr   unknownzinvalid argumentzdeadline exceededz	not foundzalready existszpermission deniedzresource exhaustedzfailed preconditionabortedzout of rangeunimplementedinternalunavailablez	data lossunauthenticatedN)(r
   r   r   r   r(   r)   r*   OKr   Z	CANCELLEDr+   UNKNOWNZinvalid_argumentZINVALID_ARGUMENTZdeadline_exceededZDEADLINE_EXCEEDED	not_found	NOT_FOUNDZalready_existsZALREADY_EXISTSZpermission_deniedZPERMISSION_DENIEDZresource_exhaustedZRESOURCE_EXHAUSTEDZfailed_preconditionZFAILED_PRECONDITIONr,   ZABORTEDZout_of_rangeZOUT_OF_RANGEr-   ZUNIMPLEMENTEDr.   ZINTERNALr/   UNAVAILABLEZ	data_lossZ	DATA_LOSSr0   ZUNAUTHENTICATEDr   r   r   r   r)      s4   r)   c                   @   s   e Zd ZdZdS )Statusa:  Describes the status of an RPC.

    This is an EXPERIMENTAL API.

    Attributes:
      code: A StatusCode object to be sent to the client.
      details: A UTF-8-encodable string to be sent to the client upon
        termination of the RPC.
      trailing_metadata: The trailing :term:`metadata` in the RPC.
    Nr	   r   r   r   r   r6   )  s   r6   c                   @   s   e Zd ZdZdS )RpcErrorzERaised by the gRPC library to indicate non-OK-status RPC termination.Nr	   r   r   r   r   r7   9  s   r7   c                   @   sH   e Zd ZdZejdd Zejdd Zejdd Zejdd	 Z	d
S )
RpcContextz,Provides RPC-related information and action.c                 C   s
   t  dS )zDescribes whether the RPC is active or has terminated.

        Returns:
          bool:
          True if RPC is active, False otherwise.
        Nr   r   r   r   r   	is_activeC  s    zRpcContext.is_activec                 C   s
   t  dS )a8  Describes the length of allowed time remaining for the RPC.

        Returns:
          A nonnegative float indicating the length of allowed time in seconds
          remaining for the RPC to complete before it is considered to have
          timed out, or None if no deadline was specified for the RPC.
        Nr   r   r   r   r   time_remainingM  s    	zRpcContext.time_remainingc                 C   s
   t  dS )zbCancels the RPC.

        Idempotent and has no effect if the RPC has already terminated.
        Nr   r   r   r   r   r   X  s    zRpcContext.cancelc                 C   s
   t  dS )a}  Registers a callback to be called on RPC termination.

        Args:
          callback: A no-parameter callable to be called on RPC termination.

        Returns:
          True if the callback was added and will be called later; False if
            the callback was not added and will not be called (because the RPC
            already terminated or some other reason).
        Nr   r   callbackr   r   r   add_callback`  s    zRpcContext.add_callbackN)
r
   r   r   r   r!   r"   r9   r:   r   r=   r   r   r   r   r8   @  s   
	


r8   c                   @   sH   e Zd ZdZejdd Zejdd Zejdd Zejdd	 Z	d
S )Callz*Invocation-side utility object for an RPC.c                 C   s
   t  dS )zAccesses the initial metadata sent by the server.

        This method blocks until the value is available.

        Returns:
          The initial :term:`metadata`.
        Nr   r   r   r   r   initial_metadatau  s    	zCall.initial_metadatac                 C   s
   t  dS )zAccesses the trailing metadata sent by the server.

        This method blocks until the value is available.

        Returns:
          The trailing :term:`metadata`.
        Nr   r   r   r   r   trailing_metadata  s    	zCall.trailing_metadatac                 C   s
   t  dS )zAccesses the status code sent by the server.

        This method blocks until the value is available.

        Returns:
          The StatusCode value for the RPC.
        Nr   r   r   r   r   code  s    	z	Call.codec                 C   s
   t  dS )zAccesses the details sent by the server.

        This method blocks until the value is available.

        Returns:
          The details string of the RPC.
        Nr   r   r   r   r   details  s    	zCall.detailsN)
r
   r   r   r   r!   r"   r?   r@   rA   rB   r   r   r   r   r>   r  s   





r>   )	metaclassc                   @   s   e Zd ZdZdS )ClientCallDetailsa  Describes an RPC to be invoked.

    Attributes:
      method: The method name of the RPC.
      timeout: An optional duration of time in seconds to allow for the RPC.
      metadata: Optional :term:`metadata` to be transmitted to
        the service-side of the RPC.
      credentials: An optional CallCredentials for the RPC.
      wait_for_ready: An optional flag to enable :term:`wait_for_ready` mechanism.
      compression: An element of grpc.compression, e.g.
        grpc.compression.Gzip.
    Nr	   r   r   r   r   rD     s   rD   c                   @   s   e Zd ZdZejdd ZdS )UnaryUnaryClientInterceptorz-Affords intercepting unary-unary invocations.c                 C   s
   t  dS )ae  Intercepts a unary-unary invocation asynchronously.

        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. `continuation` returns 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.
          client_call_details: A ClientCallDetails object describing the
            outgoing RPC.
          request: The request value for the RPC.

        Returns:
            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.
        Nr   r   continuationclient_call_detailsrequestr   r   r   intercept_unary_unary  s    z1UnaryUnaryClientInterceptor.intercept_unary_unaryN)r
   r   r   r   r!   r"   rJ   r   r   r   r   rE     s   rE   c                   @   s   e Zd ZdZejdd ZdS )UnaryStreamClientInterceptorz.Affords intercepting unary-stream invocations.c                 C   s
   t  dS )a  Intercepts a unary-stream invocation.

        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_iterator = continuation(client_call_details, request)`
            to continue with the RPC. `continuation` returns an object that is
            both a Call for the RPC and an iterator for response values.
            Drawing response values from the returned Call-iterator may
            raise RpcError indicating termination of the RPC with non-OK
            status.
          client_call_details: A ClientCallDetails object describing the
            outgoing RPC.
          request: The request value for the RPC.

        Returns:
            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. This object *should* also fulfill the
            Future interface, though it may not.
        Nr   rF   r   r   r   intercept_unary_stream  s    z3UnaryStreamClientInterceptor.intercept_unary_streamN)r
   r   r   r   r!   r"   rL   r   r   r   r   rK     s   rK   c                   @   s   e Zd ZdZejdd ZdS )StreamUnaryClientInterceptorz.Affords intercepting stream-unary invocations.c                 C   s
   t  dS )aw  Intercepts a stream-unary invocation asynchronously.

        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_iterator)`
            to continue with the RPC. `continuation` returns 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.
          client_call_details: A ClientCallDetails object describing the
            outgoing RPC.
          request_iterator: An iterator that yields request values for the RPC.

        Returns:
          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.
        Nr   r   rG   rH   request_iteratorr   r   r   intercept_stream_unary  s    z3StreamUnaryClientInterceptor.intercept_stream_unaryN)r
   r   r   r   r!   r"   rP   r   r   r   r   rM     s   rM   c                   @   s   e Zd ZdZejdd ZdS )StreamStreamClientInterceptorz/Affords intercepting stream-stream invocations.c                 C   s
   t  dS )a)  Intercepts a stream-stream invocation.

        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_iterator = continuation(client_call_details, request_iterator)`
            to continue with the RPC. `continuation` returns an object that is
            both a Call for the RPC and an iterator for response values.
            Drawing response values from the returned Call-iterator may
            raise RpcError indicating termination of the RPC with non-OK
            status.
          client_call_details: A ClientCallDetails object describing the
            outgoing RPC.
          request_iterator: An iterator that yields request values for the RPC.

        Returns:
          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. This object *should* also fulfill the
          Future interface, though it may not.
        Nr   rN   r   r   r   intercept_stream_stream  s    z5StreamStreamClientInterceptor.intercept_stream_streamN)r
   r   r   r   r!   r"   rR   r   r   r   r   rQ     s   rQ   c                   @   s   e Zd ZdZdd ZdS )ChannelCredentialsad  An encapsulation of the data required to create a secure Channel.

    This class has no supported interface - it exists to define the type of its
    instances and its instances exist to be passed to other functions. For
    example, ssl_channel_credentials returns an instance of this class and
    secure_channel requires an instance of this class.
    c                 C   s
   || _ d S N_credentialsr   credentialsr   r   r   __init__K  s    zChannelCredentials.__init__Nr
   r   r   r   rY   r   r   r   r   rS   B  s   rS   c                   @   s   e Zd ZdZdd ZdS )CallCredentialsa  An encapsulation of the data required to assert an identity over a call.

    A CallCredentials has to be used with secure Channel, otherwise the
    metadata will not be transmitted to the server.

    A CallCredentials may be composed with ChannelCredentials to always assert
    identity for every call over that Channel.

    This class has no supported interface - it exists to define the type of its
    instances and its instances exist to be passed to other functions.
    c                 C   s
   || _ d S rT   rU   rW   r   r   r   rY   \  s    zCallCredentials.__init__NrZ   r   r   r   r   r[   O  s   r[   c                   @   s   e Zd ZdZdS )AuthMetadataContextzProvides information to call credentials metadata plugins.

    Attributes:
      service_url: A string URL of the service being called into.
      method_name: A string of the fully qualified method name being called.
    Nr	   r   r   r   r   r\   `  s   r\   c                   @   s   e Zd ZdZdd ZdS )AuthMetadataPluginCallbackz.Callback object received by a metadata plugin.c                 C   s
   t  dS )zPasses to the gRPC runtime authentication metadata for an RPC.

        Args:
          metadata: The :term:`metadata` used to construct the CallCredentials.
          error: An Exception to indicate error or None to indicate success.
        Nr   )r   metadataerrorr   r   r   __call__l  s    z#AuthMetadataPluginCallback.__call__Nr
   r   r   r   r`   r   r   r   r   r]   i  s   r]   c                   @   s   e Zd ZdZdd ZdS )AuthMetadataPluginz*A specification for custom authentication.c                 C   s
   t  dS )a  Implements authentication by passing metadata to a callback.

        This method will be invoked asynchronously in a separate thread.

        Args:
          context: An AuthMetadataContext providing information on the RPC that
            the plugin is being called to authenticate.
          callback: An AuthMetadataPluginCallback to be invoked either
            synchronously or asynchronously.
        Nr   )r   contextr<   r   r   r   r`   y  s    zAuthMetadataPlugin.__call__Nra   r   r   r   r   rb   v  s   rb   c                   @   s   e Zd ZdZdd ZdS )ServerCredentialszAn encapsulation of the data required to open a secure port on a Server.

    This class has no supported interface - it exists to define the type of its
    instances and its instances exist to be passed to other functions.
    c                 C   s
   || _ d S rT   rU   rW   r   r   r   rY     s    zServerCredentials.__init__NrZ   r   r   r   r   rd     s   rd   c                   @   s   e Zd ZdZdd ZdS )ServerCertificateConfigurationaF  A certificate configuration for use with an SSL-enabled Server.

    Instances of this class can be returned in the certificate configuration
    fetching callback.

    This class has no supported interface -- it exists to define the
    type of its instances and its instances exist to be passed to
    other functions.
    c                 C   s
   || _ d S rT   )Z_certificate_configuration)r   Zcertificate_configurationr   r   r   rY     s    z'ServerCertificateConfiguration.__init__NrZ   r   r   r   r   re     s   
re   c                   @   s@   e Zd ZdZejd	ddZejd
ddZejdddZdS )UnaryUnaryMultiCallablez4Affords invoking a unary-unary RPC from client-side.Nc                 C   s
   t  dS )ay  Synchronously invokes the underlying RPC.

        Args:
          request: The request value for the RPC.
          timeout: An optional duration of time in seconds to allow
            for the RPC.
          metadata: Optional :term:`metadata` to be transmitted to the
            service-side of the RPC.
          credentials: An optional CallCredentials for the RPC. Only valid for
            secure Channel.
          wait_for_ready: An optional flag to enable :term:`wait_for_ready` mechanism.
          compression: An element of grpc.compression, e.g.
            grpc.compression.Gzip.

        Returns:
          The response value for the RPC.

        Raises:
          RpcError: Indicating that the RPC terminated with non-OK status. The
            raised RpcError will also be a Call for the RPC affording the RPC's
            metadata, status code, and details.
        Nr   r   rI   r   r^   rX   wait_for_readycompressionr   r   r   r`     s     z UnaryUnaryMultiCallable.__call__c                 C   s
   t  dS )a  Synchronously invokes the underlying RPC.

        Args:
          request: The request value for the RPC.
          timeout: An optional durating of time in seconds to allow for
            the RPC.
          metadata: Optional :term:`metadata` to be transmitted to the
            service-side of the RPC.
          credentials: An optional CallCredentials for the RPC. Only valid for
            secure Channel.
          wait_for_ready: An optional flag to enable :term:`wait_for_ready` mechanism.
          compression: An element of grpc.compression, e.g.
            grpc.compression.Gzip.

        Returns:
          The response value for the RPC and a Call value for the RPC.

        Raises:
          RpcError: Indicating that the RPC terminated with non-OK status. The
            raised RpcError will also be a Call for the RPC affording the RPC's
            metadata, status code, and details.
        Nr   rg   r   r   r   	with_call  s     z!UnaryUnaryMultiCallable.with_callc                 C   s
   t  dS )a  Asynchronously invokes the underlying RPC.

        Args:
          request: The request value for the RPC.
          timeout: An optional duration of time in seconds to allow for
            the RPC.
          metadata: Optional :term:`metadata` to be transmitted to the
            service-side of the RPC.
          credentials: An optional CallCredentials for the RPC. Only valid for
            secure Channel.
          wait_for_ready: An optional flag to enable :term:`wait_for_ready` mechanism.
          compression: An element of grpc.compression, e.g.
            grpc.compression.Gzip.

        Returns:
            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.
        Nr   rg   r   r   r   future  s    zUnaryUnaryMultiCallable.future)NNNNN)NNNNN)NNNNN	r
   r   r   r   r!   r"   r`   rj   rk   r   r   r   r   rf     s,        !     !     rf   c                   @   s    e Zd ZdZejdddZdS )UnaryStreamMultiCallablez5Affords invoking a unary-stream RPC from client-side.Nc                 C   s
   t  dS )a  Invokes the underlying RPC.

        Args:
          request: The request value for the RPC.
          timeout: An optional duration of time in seconds to allow for
            the RPC. If None, the timeout is considered infinite.
          metadata: An optional :term:`metadata` to be transmitted to the
            service-side of the RPC.
          credentials: An optional CallCredentials for the RPC. Only valid for
            secure Channel.
          wait_for_ready: An optional flag to enable :term:`wait_for_ready` mechanism.
          compression: An element of grpc.compression, e.g.
            grpc.compression.Gzip.

        Returns:
            An object that is a Call for the RPC, an iterator of response
            values, and a Future for the RPC. Drawing response values from the
            returned Call-iterator may raise RpcError indicating termination of
            the RPC with non-OK status.
        Nr   rg   r   r   r   r`     s    z!UnaryStreamMultiCallable.__call__)NNNNNr
   r   r   r   r!   r"   r`   r   r   r   r   rm     s        rm   c                   @   s@   e Zd ZdZejd	ddZejd
ddZejdddZdS )StreamUnaryMultiCallablez5Affords invoking a stream-unary RPC from client-side.Nc                 C   s
   t  dS )a  Synchronously invokes the underlying RPC.

        Args:
          request_iterator: An iterator that yields request values for
            the RPC.
          timeout: An optional duration of time in seconds to allow for
            the RPC. If None, the timeout is considered infinite.
          metadata: Optional :term:`metadata` to be transmitted to the
            service-side of the RPC.
          credentials: An optional CallCredentials for the RPC. Only valid for
            secure Channel.
          wait_for_ready: An optional flag to enable :term:`wait_for_ready` mechanism.
          compression: An element of grpc.compression, e.g.
            grpc.compression.Gzip.

        Returns:
          The response value for the RPC.

        Raises:
          RpcError: Indicating that the RPC terminated with non-OK status. The
            raised RpcError will also implement grpc.Call, affording methods
            such as metadata, code, and details.
        Nr   r   rO   r   r^   rX   rh   ri   r   r   r   r`   4  s    !z!StreamUnaryMultiCallable.__call__c                 C   s
   t  dS )a  Synchronously invokes the underlying RPC on the client.

        Args:
          request_iterator: An iterator that yields request values for
            the RPC.
          timeout: An optional duration of time in seconds to allow for
            the RPC. If None, the timeout is considered infinite.
          metadata: Optional :term:`metadata` to be transmitted to the
            service-side of the RPC.
          credentials: An optional CallCredentials for the RPC. Only valid for
            secure Channel.
          wait_for_ready: An optional flag to enable :term:`wait_for_ready` mechanism.
          compression: An element of grpc.compression, e.g.
            grpc.compression.Gzip.

        Returns:
          The response value for the RPC and a Call object for the RPC.

        Raises:
          RpcError: Indicating that the RPC terminated with non-OK status. The
            raised RpcError will also be a Call for the RPC affording the RPC's
            metadata, status code, and details.
        Nr   rp   r   r   r   rj   W  s    !z"StreamUnaryMultiCallable.with_callc                 C   s
   t  dS )a  Asynchronously invokes the underlying RPC on the client.

        Args:
          request_iterator: An iterator that yields request values for the RPC.
          timeout: An optional duration of time in seconds to allow for
            the RPC. If None, the timeout is considered infinite.
          metadata: Optional :term:`metadata` to be transmitted to the
            service-side of the RPC.
          credentials: An optional CallCredentials for the RPC. Only valid for
            secure Channel.
          wait_for_ready: An optional flag to enable :term:`wait_for_ready` mechanism.
          compression: An element of grpc.compression, e.g.
            grpc.compression.Gzip.

        Returns:
            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.
        Nr   rp   r   r   r   rk   z  s    zStreamUnaryMultiCallable.future)NNNNN)NNNNN)NNNNNrl   r   r   r   r   ro   1  s,        "     "     ro   c                   @   s    e Zd ZdZejdddZdS )StreamStreamMultiCallablez4Affords invoking a stream-stream RPC on client-side.Nc                 C   s
   t  dS )a  Invokes the underlying RPC on the client.

        Args:
          request_iterator: An iterator that yields request values for the RPC.
          timeout: An optional duration of time in seconds to allow for
            the RPC. If not specified, the timeout is considered infinite.
          metadata: Optional :term:`metadata` to be transmitted to the
            service-side of the RPC.
          credentials: An optional CallCredentials for the RPC. Only valid for
            secure Channel.
          wait_for_ready: An optional flag to enable :term:`wait_for_ready` mechanism.
          compression: An element of grpc.compression, e.g.
            grpc.compression.Gzip.

        Returns:
            An object that is a Call for the RPC, an iterator of response
            values, and a Future for the RPC. Drawing response values from the
            returned Call-iterator may raise RpcError indicating termination of
            the RPC with non-OK status.
        Nr   rp   r   r   r   r`     s    z"StreamStreamMultiCallable.__call__)NNNNNrn   r   r   r   r   rq     s        rq   c                   @   s   e Zd ZdZejdddZejdd Zejddd	Zejdd
dZ	ejdddZ
ejdddZejdd Zdd Zdd ZdS )ChannelzAffords RPC invocation via generic methods on client-side.

    Channel objects implement the Context Manager type, although they need not
    support being entered and exited multiple times.
    Fc                 C   s
   t  dS )a|  Subscribe to this Channel's connectivity state machine.

        A Channel may be in any of the states described by ChannelConnectivity.
        This method allows application to monitor the state transitions.
        The typical use case is to debug or gain better visibility into gRPC
        runtime's state.

        Args:
          callback: A callable to be invoked with ChannelConnectivity argument.
            ChannelConnectivity describes current state of the channel.
            The callable will be invoked immediately upon subscription
            and again for every change to ChannelConnectivity until it
            is unsubscribed or this Channel object goes out of scope.
          try_to_connect: A boolean indicating whether or not this Channel
            should attempt to connect immediately. If set to False, gRPC
            runtime decides when to connect.
        Nr   )r   r<   Ztry_to_connectr   r   r   	subscribe  s    zChannel.subscribec                 C   s
   t  dS )zUnsubscribes a subscribed callback from this Channel's connectivity.

        Args:
          callback: A callable previously registered with this Channel from
          having been passed to its "subscribe" method.
        Nr   r;   r   r   r   unsubscribe  s    zChannel.unsubscribeNc                 C   s
   t  dS )a  Creates a UnaryUnaryMultiCallable for a unary-unary method.

        Args:
          method: The name of the RPC method.
          request_serializer: Optional :term:`serializer` for serializing the request
            message. Request goes unserialized in case None is passed.
          response_deserializer: Optional :term:`deserializer` for deserializing the
            response message. Response goes undeserialized in case None
            is passed.
          _registered_method: Implementation Private. A bool representing whether the method
            is registered.

        Returns:
          A UnaryUnaryMultiCallable value for the named unary-unary method.
        Nr   r   methodZrequest_serializerZresponse_deserializerZ_registered_methodr   r   r   unary_unary  s    zChannel.unary_unaryc                 C   s
   t  dS )a  Creates a UnaryStreamMultiCallable for a unary-stream method.

        Args:
          method: The name of the RPC method.
          request_serializer: Optional :term:`serializer` for serializing the request
            message. Request goes unserialized in case None is passed.
          response_deserializer: Optional :term:`deserializer` for deserializing the
            response message. Response goes undeserialized in case None is
            passed.
          _registered_method: Implementation Private. A bool representing whether the method
            is registered.

        Returns:
          A UnaryStreamMultiCallable value for the name unary-stream method.
        Nr   ru   r   r   r   unary_stream  s    zChannel.unary_streamc                 C   s
   t  dS )a  Creates a StreamUnaryMultiCallable for a stream-unary method.

        Args:
          method: The name of the RPC method.
          request_serializer: Optional :term:`serializer` for serializing the request
            message. Request goes unserialized in case None is passed.
          response_deserializer: Optional :term:`deserializer` for deserializing the
            response message. Response goes undeserialized in case None is
            passed.
          _registered_method: Implementation Private. A bool representing whether the method
            is registered.

        Returns:
          A StreamUnaryMultiCallable value for the named stream-unary method.
        Nr   ru   r   r   r   stream_unary  s    zChannel.stream_unaryc                 C   s
   t  dS )a  Creates a StreamStreamMultiCallable for a stream-stream method.

        Args:
          method: The name of the RPC method.
          request_serializer: Optional :term:`serializer` for serializing the request
            message. Request goes unserialized in case None is passed.
          response_deserializer: Optional :term:`deserializer` for deserializing the
            response message. Response goes undeserialized in case None
            is passed.
          _registered_method: Implementation Private. A bool representing whether the method
            is registered.

        Returns:
          A StreamStreamMultiCallable value for the named stream-stream method.
        Nr   ru   r   r   r   stream_stream4  s    zChannel.stream_streamc                 C   s
   t  dS )a  Closes this Channel and releases all resources held by it.

        Closing the Channel will immediately terminate all RPCs active with the
        Channel and it is not valid to invoke new RPCs with the Channel.

        This method is idempotent.
        Nr   r   r   r   r   closeM  s    	zChannel.closec                 C   s
   t  dS )z9Enters the runtime context related to the channel object.Nr   r   r   r   r   	__enter__X  s    zChannel.__enter__c                 C   s
   t  dS )z8Exits the runtime context related to the channel object.Nr   )r   exc_typeexc_valexc_tbr   r   r   __exit__\  s    zChannel.__exit__)F)NNF)NNF)NNF)NNF)r
   r   r   r   r!   r"   rs   rt   rw   rx   ry   rz   r{   r|   r   r   r   r   r   rr     s:   
	            

rr   c                   @   s   e Zd ZdZejdd Zejdd Zejdd Zejdd	 Z	ejd
d Z
dd Zejdd Zejdd Zdd Zejdd Zejdd Zejdd Zejdd Zdd Zdd Zd d! Zd"S )#ServicerContextz2A context object passed to method implementations.c                 C   s
   t  dS )zoAccesses the metadata sent by the client.

        Returns:
          The invocation :term:`metadata`.
        Nr   r   r   r   r   invocation_metadatag  s    z#ServicerContext.invocation_metadatac                 C   s
   t  dS )zIdentifies the peer that invoked the RPC being serviced.

        Returns:
          A string identifying the peer that invoked the RPC being serviced.
          The string format is determined by gRPC runtime.
        Nr   r   r   r   r   peerp  s    zServicerContext.peerc                 C   s
   t  dS )a2  Gets one or more peer identity(s).

        Equivalent to
        servicer_context.auth_context().get(servicer_context.peer_identity_key())

        Returns:
          An iterable of the identities, or None if the call is not
          authenticated. Each identity is returned as a raw bytes type.
        Nr   r   r   r   r   peer_identitiesz  s    zServicerContext.peer_identitiesc                 C   s
   t  dS )a8  The auth property used to identify the peer.

        For example, "x509_common_name" or "x509_subject_alternative_name" are
        used to identify an SSL peer.

        Returns:
          The auth property (string) that indicates the
          peer identity, or None if the call is not authenticated.
        Nr   r   r   r   r   peer_identity_key  s    z!ServicerContext.peer_identity_keyc                 C   s
   t  dS )zGets the auth context for the call.

        Returns:
          A map of strings to an iterable of bytes for each auth property.
        Nr   r   r   r   r   auth_context  s    zServicerContext.auth_contextc                 C   s
   t  dS )zSet the compression algorithm to be used for the entire call.

        Args:
          compression: An element of grpc.compression, e.g.
            grpc.compression.Gzip.
        Nr   )r   ri   r   r   r   set_compression  s    zServicerContext.set_compressionc                 C   s
   t  dS )a  Sends the initial metadata value to the client.

        This method need not be called by implementations if they have no
        metadata to add to what the gRPC runtime will transmit.

        Args:
          initial_metadata: The initial :term:`metadata`.
        Nr   )r   r?   r   r   r   send_initial_metadata  s    
z%ServicerContext.send_initial_metadatac                 C   s
   t  dS )a  Sets the trailing metadata for the RPC.

        Sets the trailing metadata to be sent upon completion of the RPC.

        If this method is invoked multiple times throughout the lifetime of an
        RPC, the value supplied in the final invocation will be the value sent
        over the wire.

        This method need not be called by implementations if they have no
        metadata to add to what the gRPC runtime will transmit.

        Args:
          trailing_metadata: The trailing :term:`metadata`.
        Nr   )r   r@   r   r   r   set_trailing_metadata  s    z%ServicerContext.set_trailing_metadatac                 C   s
   t  dS )zAccess value to be used as trailing metadata upon RPC completion.

        This is an EXPERIMENTAL API.

        Returns:
          The trailing :term:`metadata` for the RPC.
        Nr   r   r   r   r   r@     s    z!ServicerContext.trailing_metadatac                 C   s
   t  dS )a  Raises an exception to terminate the RPC with a non-OK status.

        The code and details passed as arguments will supersede any existing
        ones.

        Args:
          code: A StatusCode object to be sent to the client.
            It must not be StatusCode.OK.
          details: A UTF-8-encodable string to be sent to the client upon
            termination of the RPC.

        Raises:
          Exception: An exception is always raised to signal the abortion the
            RPC to the gRPC runtime.
        Nr   )r   rA   rB   r   r   r   abort  s    zServicerContext.abortc                 C   s
   t  dS )a  Raises an exception to terminate the RPC with a non-OK status.

        The status passed as argument will supersede any existing status code,
        status message and trailing metadata.

        This is an EXPERIMENTAL API.

        Args:
          status: A grpc.Status object. The status code in it must not be
            StatusCode.OK.

        Raises:
          Exception: An exception is always raised to signal the abortion the
            RPC to the gRPC runtime.
        Nr   )r   statusr   r   r   abort_with_status  s    z!ServicerContext.abort_with_statusc                 C   s
   t  dS )a$  Sets the value to be used as status code upon RPC completion.

        This method need not be called by method implementations if they wish
        the gRPC runtime to determine the status code of the RPC.

        Args:
          code: A StatusCode object to be sent to the client.
        Nr   )r   rA   r   r   r   set_code  s    
zServicerContext.set_codec                 C   s
   t  dS )a4  Sets the value to be used as detail string upon RPC completion.

        This method need not be called by method implementations if they have
        no details to transmit.

        Args:
          details: A UTF-8-encodable string to be sent to the client upon
            termination of the RPC.
        Nr   )r   rB   r   r   r   set_details   s    zServicerContext.set_detailsc                 C   s
   t  dS )zAccesses the value to be used as status code upon RPC completion.

        This is an EXPERIMENTAL API.

        Returns:
          The StatusCode value for the RPC.
        Nr   r   r   r   r   rA     s    zServicerContext.codec                 C   s
   t  dS )zAccesses the value to be used as detail string upon RPC completion.

        This is an EXPERIMENTAL API.

        Returns:
          The details string of the RPC.
        Nr   r   r   r   r   rB     s    zServicerContext.detailsc                 C   s
   t  dS )zDisables compression for the next response message.

        This method will override any compression configuration set during
        server creation or set on the call.
        Nr   r   r   r   r    disable_next_message_compression!  s    z0ServicerContext.disable_next_message_compressionN)r
   r   r   r   r!   r"   r   r   r   r   r   r   r   r   r@   r   r   r   r   rA   rB   r   r   r   r   r   r   d  s8   

	


	








r   c                   @   s   e Zd ZdZdS )RpcMethodHandlera  An implementation of a single RPC method.

    Attributes:
      request_streaming: Whether the RPC supports exactly one request message
        or any arbitrary number of request messages.
      response_streaming: Whether the RPC supports exactly one response message
        or any arbitrary number of response messages.
      request_deserializer: A callable :term:`deserializer` that accepts a byte string and
        returns an object suitable to be passed to this object's business
        logic, or None to indicate that this object's business logic should be
        passed the raw request bytes.
      response_serializer: A callable :term:`serializer` that accepts an object produced
        by this object's business logic and returns a byte string, or None to
        indicate that the byte strings produced by this object's business logic
        should be transmitted on the wire as they are.
      unary_unary: This object's application-specific business logic as a
        callable value that takes a request value and a ServicerContext object
        and returns a response value. Only non-None if both request_streaming
        and response_streaming are False.
      unary_stream: This object's application-specific business logic as a
        callable value that takes a request value and a ServicerContext object
        and returns an iterator of response values. Only non-None if
        request_streaming is False and response_streaming is True.
      stream_unary: This object's application-specific business logic as a
        callable value that takes an iterator of request values and a
        ServicerContext object and returns a response value. Only non-None if
        request_streaming is True and response_streaming is False.
      stream_stream: This object's application-specific business logic as a
        callable value that takes an iterator of request values and a
        ServicerContext object and returns an iterator of response values.
        Only non-None if request_streaming and response_streaming are both
        True.
    Nr	   r   r   r   r   r   -  s   r   c                   @   s   e Zd ZdZdS )HandlerCallDetailszDescribes an RPC that has just arrived for service.

    Attributes:
      method: The method name of the RPC.
      invocation_metadata: The :term:`metadata` sent by the client.
    Nr	   r   r   r   r   r   Q  s   r   c                   @   s   e Zd ZdZejdd ZdS )GenericRpcHandlerz2An implementation of arbitrarily many RPC methods.c                 C   s
   t  dS )a.  Returns the handler for servicing the RPC.

        Args:
          handler_call_details: A HandlerCallDetails describing the RPC.

        Returns:
          An RpcMethodHandler with which the RPC may be serviced if the
          implementation chooses to service this RPC, or None otherwise.
        Nr   )r   handler_call_detailsr   r   r   service]  s    zGenericRpcHandler.serviceN)r
   r   r   r   r!   r"   r   r   r   r   r   r   Z  s   r   c                   @   s   e Zd ZdZejdd ZdS )ServiceRpcHandlerad  An implementation of RPC methods belonging to a service.

    A service handles RPC methods with structured names of the form
    '/Service.Name/Service.Method', where 'Service.Name' is the value
    returned by service_name(), and 'Service.Method' is the method
    name.  A service can have multiple method names, but only a single
    service name.
    c                 C   s
   t  dS )zSReturns this service's name.

        Returns:
          The service name.
        Nr   r   r   r   r   service_nameu  s    zServiceRpcHandler.service_nameN)r
   r   r   r   r!   r"   r   r   r   r   r   r   k  s   	r   c                   @   s   e Zd ZdZejdd ZdS )ServerInterceptorz7Affords intercepting incoming RPCs on the service-side.c                 C   s
   t  dS )a)  Intercepts incoming RPCs before handing them over to a handler.

        State can be passed from an interceptor to downstream interceptors
        via contextvars. The first interceptor is called from an empty
        contextvars.Context, and the same Context is used for downstream
        interceptors and for the final handler call. Note that there are no
        guarantees that interceptors and handlers will be called from the
        same thread.

        Args:
          continuation: A function that takes a HandlerCallDetails and
            proceeds to invoke the next interceptor in the chain, if any,
            or the RPC handler lookup logic, with the call details passed
            as an argument, and returns an RpcMethodHandler instance if
            the RPC is considered serviced, or None otherwise.
          handler_call_details: A HandlerCallDetails describing the RPC.

        Returns:
          An RpcMethodHandler with which the RPC may be serviced if the
          interceptor chooses to service this RPC, or None otherwise.
        Nr   )r   rG   r   r   r   r   intercept_service  s    z#ServerInterceptor.intercept_serviceN)r
   r   r   r   r!   r"   r   r   r   r   r   r     s   r   c                   @   sh   e Zd ZdZejdd Zdd Zejdd Zejdd	 Z	ejd
d Z
ejdd ZdddZdS )ServerzServices RPCs.c                 C   s
   t  dS )zRegisters GenericRpcHandlers with this Server.

        This method is only safe to call before the server is started.

        Args:
          generic_rpc_handlers: An iterable of GenericRpcHandlers that will be
          used to service RPCs.
        Nr   )r   Zgeneric_rpc_handlersr   r   r   add_generic_rpc_handlers  s    
zServer.add_generic_rpc_handlersc                 C   s   dS )a  Registers GenericRpcHandlers with this Server.

        This method is only safe to call before the server is started.

        If the same method have both generic and registered handler,
        registered handler will take precedence.

        Args:
          service_name: The service name.
          method_handlers: A dictionary that maps method names to corresponding
            RpcMethodHandler.
        Nr   )r   r   method_handlersr   r   r   add_registered_method_handlers  s    z%Server.add_registered_method_handlersc                 C   s
   t  dS )az  Opens an insecure port for accepting RPCs.

        This method may only be called before starting the server.

        Args:
          address: The address for which to open a port. If the port is 0,
            or not specified in the address, then gRPC runtime will choose a port.

        Returns:
          An integer port on which server will accept RPC requests.
        Nr   )r   addressr   r   r   add_insecure_port  s    zServer.add_insecure_portc                 C   s
   t  dS )a  Opens a secure port for accepting RPCs.

        This method may only be called before starting the server.

        Args:
          address: The address for which to open a port.
            if the port is 0, or not specified in the address, then gRPC
            runtime will choose a port.
          server_credentials: A ServerCredentials object.

        Returns:
          An integer port on which server will accept RPC requests.
        Nr   )r   r   Zserver_credentialsr   r   r   add_secure_port  s    zServer.add_secure_portc                 C   s
   t  dS )zgStarts this Server.

        This method may only be called once. (i.e. it is not idempotent).
        Nr   r   r   r   r   start  s    zServer.startc                 C   s
   t  dS )a  Stops this Server.

        This method immediately stop service of new RPCs in all cases.

        If a grace period is specified, this method waits until all active
        RPCs are finished or until the grace period is reached. RPCs that haven't
        been terminated within the grace period are aborted.
        If a grace period is not specified (by passing None for `grace`),
        all existing RPCs are aborted immediately and this method
        blocks until the last RPC handler terminates.

        This method is idempotent and may be called at any time.
        Passing a smaller grace value in a subsequent call will have
        the effect of stopping the Server sooner (passing None will
        have the effect of stopping the server immediately). Passing
        a larger grace value in a subsequent call *will not* have the
        effect of stopping the server later (i.e. the most restrictive
        grace value is used).

        Args:
          grace: A duration of time in seconds or None.

        Returns:
          A threading.Event that will be set when this Server has completely
          stopped, i.e. when running RPCs either complete or are aborted and
          all handlers have terminated.
        Nr   )r   Zgracer   r   r   stop  s    zServer.stopNc                 C   s
   t  dS )a  Block current thread until the server stops.

        This is an EXPERIMENTAL API.

        The wait will not consume computational resources during blocking, and
        it will block until one of the two following conditions are met:

        1) The server is stopped or terminated;
        2) A timeout occurs if timeout is not `None`.

        The timeout argument works in the same way as `threading.Event.wait()`.
        https://docs.python.org/3/library/threading.html#threading.Event.wait

        Args:
          timeout: A floating point number specifying a timeout for the
            operation in seconds.

        Returns:
          A bool indicates if the operation times out.
        Nr   r   r   r   r   wait_for_termination  s    zServer.wait_for_termination)N)r
   r   r   r   r!   r"   r   r   r   r   r   r   r   r   r   r   r   r     s   




r   c              
   C   s$   ddl m} |dd||| dddS )a  Creates an RpcMethodHandler for a unary-unary RPC method.

    Args:
      behavior: The implementation of an RPC that accepts one request
        and returns one response.
      request_deserializer: An optional :term:`deserializer` for request deserialization.
      response_serializer: An optional :term:`serializer` for response serialization.

    Returns:
      An RpcMethodHandler object that is typically used by grpc.Server.
    r   
_utilitiesFNgrpcr   r   Zbehaviorrequest_deserializerZresponse_serializerr   r   r   r   unary_unary_rpc_method_handler!  s    r   c              
   C   s$   ddl m} |dd||d| ddS )a  Creates an RpcMethodHandler for a unary-stream RPC method.

    Args:
      behavior: The implementation of an RPC that accepts one request
        and returns an iterator of response values.
      request_deserializer: An optional :term:`deserializer` for request deserialization.
      response_serializer: An optional :term:`serializer` for response serialization.

    Returns:
      An RpcMethodHandler object that is typically used by grpc.Server.
    r   r   FTNr   r   r   r   r   unary_stream_rpc_method_handler=  s    r   c              
   C   s$   ddl m} |dd||dd| dS )a  Creates an RpcMethodHandler for a stream-unary RPC method.

    Args:
      behavior: The implementation of an RPC that accepts an iterator of
        request values and returns a single response value.
      request_deserializer: An optional :term:`deserializer` for request deserialization.
      response_serializer: An optional :term:`serializer` for response serialization.

    Returns:
      An RpcMethodHandler object that is typically used by grpc.Server.
    r   r   TFNr   r   r   r   r   stream_unary_rpc_method_handlerY  s    r   c              
   C   s$   ddl m} |dd||ddd| S )a  Creates an RpcMethodHandler for a stream-stream RPC method.

    Args:
      behavior: The implementation of an RPC that accepts an iterator of
        request values and returns an iterator of response values.
      request_deserializer: An optional :term:`deserializer` for request deserialization.
      response_serializer: An optional :term:`serializer` for response serialization.

    Returns:
      An RpcMethodHandler object that is typically used by grpc.Server.
    r   r   TNr   r   r   r   r    stream_stream_rpc_method_handleru  s    r   c                 C   s   ddl m} || |S )a  Creates a GenericRpcHandler from RpcMethodHandlers.

    Args:
      service: The name of the service that is implemented by the
        method_handlers.
      method_handlers: A dictionary that maps method names to corresponding
        RpcMethodHandler.

    Returns:
      A GenericRpcHandler. This is typically added to the grpc.Server object
      with add_generic_rpc_handlers() before starting the server.
    r   r   )r   r   ZDictionaryGenericHandler)r   r   r   r   r   r   method_handlers_generic_handler  s    r   c                 C   s   t t| ||S )aC  Creates a ChannelCredentials for use with an SSL-enabled Channel.

    Args:
      root_certificates: The PEM-encoded root certificates as a byte string,
        or None to retrieve them from a default location chosen by gRPC
        runtime.
      private_key: The PEM-encoded private key as a byte string, or None if no
        private key should be used.
      certificate_chain: The PEM-encoded certificate chain as a byte string
        to use or None if no certificate chain should be used.

    Returns:
      A ChannelCredentials for use with an SSL-enabled Channel.
    )rS   r(   ZSSLChannelCredentials)root_certificatesZprivate_keyZcertificate_chainr   r   r   ssl_channel_credentials  s      r   c                 C   s"   | dkrt  n| } tt| jS )a?  Creates a ChannelCredentials for use with xDS. This is an EXPERIMENTAL
      API.

    Args:
      fallback_credentials: Credentials to use in case it is not possible to
        establish a secure connection via xDS. If no fallback_credentials
        argument is supplied, a default SSLChannelCredentials is used.
    N)r   rS   r(   ZXDSChannelCredentialsrV   Zfallback_credentialsr   r   r   xds_channel_credentials  s    
r   c                 C   s   ddl m} || |S )zConstruct CallCredentials from an AuthMetadataPlugin.

    Args:
      metadata_plugin: An AuthMetadataPlugin to use for authentication.
      name: An optional name for the plugin.

    Returns:
      A CallCredentials.
    r   _plugin_wrapping)r   r    metadata_plugin_call_credentials)Zmetadata_pluginnamer   r   r   r   metadata_call_credentials  s
    
 r   c                 C   s*   ddl m} ddl m} ||| dS )a  Construct CallCredentials from an access token.

    Args:
      access_token: A string to place directly in the http request
        authorization header, for example
        "authorization: Bearer <access_token>".

    Returns:
      A CallCredentials.
    r   )_authr   N)r   r   r   r   ZAccessTokenAuthMetadataPlugin)Zaccess_tokenr   r   r   r   r   access_token_call_credentials  s     r   c                  G   s   t ttdd | D S )zCompose multiple CallCredentials to make a new CallCredentials.

    Args:
      *call_credentials: At least two CallCredentials objects.

    Returns:
      A CallCredentials object composed of the given CallCredentials objects.
    c                 s   s   | ]}|j V  qd S rT   rU   .0Zsingle_call_credentialsr   r   r   	<genexpr>  s   z-composite_call_credentials.<locals>.<genexpr>)r[   r(   ZCompositeCallCredentialstuplecall_credentialsr   r   r   composite_call_credentials  s    	r   c                 G   s    t ttdd |D | jS )aB  Compose a ChannelCredentials and one or more CallCredentials objects.

    Args:
      channel_credentials: A ChannelCredentials object.
      *call_credentials: One or more CallCredentials objects.

    Returns:
      A ChannelCredentials composed of the given ChannelCredentials and
        CallCredentials objects.
    c                 s   s   | ]}|j V  qd S rT   rU   r   r   r   r   r     s   z0composite_channel_credentials.<locals>.<genexpr>)rS   r(   ZCompositeChannelCredentialsr   rV   )Zchannel_credentialsr   r   r   r   composite_channel_credentials  s    r   Fc                 C   sD   | st dn2|r$|dkr$t dntt|dd | D |S dS )a  Creates a ServerCredentials for use with an SSL-enabled Server.

    Args:
      private_key_certificate_chain_pairs: A list of pairs of the form
        [PEM-encoded private key, PEM-encoded certificate chain].
      root_certificates: An optional byte string of PEM-encoded client root
        certificates that the server will use to verify client authentication.
        If omitted, require_client_auth must also be False.
      require_client_auth: A boolean indicating whether or not to require
        clients to be authenticated. May only be True if root_certificates
        is not None.

    Returns:
      A ServerCredentials for use with an SSL-enabled Server. Typically, this
      object is an argument to add_secure_port() method during server setup.
    <At least one private key-certificate chain pair is required!NzCIllegal to require client auth without providing root certificates!c                 S   s   g | ]\}}t ||qS r   r(   ZSslPemKeyCertPairr   keyZpemr   r   r   
<listcomp>=  s   z*ssl_server_credentials.<locals>.<listcomp>)
ValueErrorrd   r(   Zserver_credentials_ssl)#private_key_certificate_chain_pairsr   Zrequire_client_authr   r   r   ssl_server_credentials  s"    r   c                 C   s   t t| jS )zCreates a ServerCredentials for use with xDS. This is an EXPERIMENTAL
      API.

    Args:
      fallback_credentials: Credentials to use in case it is not possible to
        establish a secure connection via xDS. No default value is provided.
    )rd   r(   xds_server_credentialsrV   r   r   r   r   r   F  s    
r   c                   C   s   t t S )a&  Creates a credentials object directing the server to use no credentials.
      This is an EXPERIMENTAL API.

    This object cannot be used directly in a call to `add_secure_port`.
    Instead, it should be used to construct other credentials objects, e.g.
    with xds_server_credentials.
    )rd   r(   insecure_server_credentialsr   r   r   r   r   S  s    r   c                 C   s*   | rt t|dd | D S tddS )a  Creates a ServerCertificateConfiguration for use with a Server.

    Args:
      private_key_certificate_chain_pairs: A collection of pairs of
        the form [PEM-encoded private key, PEM-encoded certificate
        chain].
      root_certificates: An optional byte string of PEM-encoded client root
        certificates that the server will use to verify client authentication.

    Returns:
      A ServerCertificateConfiguration that can be returned in the certificate
        configuration fetching callback.
    c                 S   s   g | ]\}}t ||qS r   r   r   r   r   r   r   r  s   z8ssl_server_certificate_configuration.<locals>.<listcomp>r   N)re   r(   Zserver_certificate_config_sslr   )r   r   r   r   r   $ssl_server_certificate_configuration^  s    
r   c                 C   s   t t| ||S )a  Creates a ServerCredentials for use with an SSL-enabled Server.

    Args:
      initial_certificate_configuration (ServerCertificateConfiguration): The
        certificate configuration with which the server will be initialized.
      certificate_configuration_fetcher (callable): A callable that takes no
        arguments and should return a ServerCertificateConfiguration to
        replace the server's current certificate, or None for no change
        (i.e., the server will continue its current certificate
        config). The library will call this callback on *every* new
        client connection before starting the TLS handshake with the
        client, thus allowing the user application to optionally
        return a new ServerCertificateConfiguration that the server will then
        use for the handshake.
      require_client_authentication: A boolean indicating whether or not to
        require clients to be authenticated.

    Returns:
      A ServerCredentials.
    )rd   r(   Z*server_credentials_ssl_dynamic_cert_config)Z!initial_certificate_configurationZ!certificate_configuration_fetcherZrequire_client_authenticationr   r   r   dynamic_ssl_server_credentials~  s    r   c                   @   s    e Zd ZdZejjZejjZ	dS )LocalConnectionTypezTypes of local connection for local credential creation.

    Attributes:
      UDS: Unix domain socket connections
      LOCAL_TCP: Local TCP connections.
    N)
r
   r   r   r   r(   r   ZudsZUDSZ	local_tcp	LOCAL_TCPr   r   r   r   r     s   r   c                 C   s   t t| jS )a  Creates a local ChannelCredentials used for local connections.

    This is an EXPERIMENTAL API.

    Local credentials are used by local TCP endpoints (e.g. localhost:10000)
    also UDS connections.

    The connections created by local channel credentials are not
    encrypted, but will be checked if they are local or not.
    The UDS connections are considered secure by providing peer authentication
    and data confidentiality while TCP connections are considered insecure.

    It is allowed to transmit call credentials over connections created by
    local channel credentials.

    Local channel credentials are useful for 1) eliminating insecure_channel usage;
    2) enable unit testing for call credentials without setting up secrets.

    Args:
      local_connect_type: Local connection type (either
        grpc.LocalConnectionType.UDS or grpc.LocalConnectionType.LOCAL_TCP)

    Returns:
      A ChannelCredentials for use with a local Channel
    )rS   r(   Zchannel_credentials_localvalueZlocal_connect_typer   r   r   local_channel_credentials  s    
r   c                 C   s   t t| jS )a  Creates a local ServerCredentials used for local connections.

    This is an EXPERIMENTAL API.

    Local credentials are used by local TCP endpoints (e.g. localhost:10000)
    also UDS connections.

    The connections created by local server credentials are not
    encrypted, but will be checked if they are local or not.
    The UDS connections are considered secure by providing peer authentication
    and data confidentiality while TCP connections are considered insecure.

    It is allowed to transmit call credentials over connections created by local
    server credentials.

    Local server credentials are useful for 1) eliminating insecure_channel usage;
    2) enable unit testing for call credentials without setting up secrets.

    Args:
      local_connect_type: Local connection type (either
        grpc.LocalConnectionType.UDS or grpc.LocalConnectionType.LOCAL_TCP)

    Returns:
      A ServerCredentials for use with a local Server
    )rd   r(   Zserver_credentials_localr   r   r   r   r   local_server_credentials  s    
r   c                 C   s   t t| pg S )a  Creates a ChannelCredentials for use with an ALTS-enabled Channel.

    This is an EXPERIMENTAL API.
    ALTS credentials API can only be used in GCP environment as it relies on
    handshaker service being available. For more info about ALTS see
    https://cloud.google.com/security/encryption-in-transit/application-layer-transport-security

    Args:
      service_accounts: A list of server identities accepted by the client.
        If target service accounts are provided and none of them matches the
        peer identity of the server, handshake will fail. The arg can be empty
        if the client does not have any information about trusted server
        identity.
    Returns:
      A ChannelCredentials for use with an ALTS-enabled Channel
    )rS   r(   Zchannel_credentials_alts)Zservice_accountsr   r   r   alts_channel_credentials  s    r   c                   C   s   t t S )a  Creates a ServerCredentials for use with an ALTS-enabled connection.

    This is an EXPERIMENTAL API.
    ALTS credentials API can only be used in GCP environment as it relies on
    handshaker service being available. For more info about ALTS see
    https://cloud.google.com/security/encryption-in-transit/application-layer-transport-security

    Returns:
      A ServerCredentials for use with an ALTS-enabled Server
    )rd   r(   Zserver_credentials_altsr   r   r   r   alts_server_credentials  s    r   c                 C   s   t t| jS )aD  Creates a compute engine channel credential.

    This credential can only be used in a GCP environment as it relies on
    a handshaker service. For more info about ALTS, see
    https://cloud.google.com/security/encryption-in-transit/application-layer-transport-security

    This channel credential is expected to be used as part of a composite
    credential in conjunction with a call credentials that authenticates the
    VM's default service account. If used with any other sort of call
    credential, the connection may suddenly and unexpectedly begin failing RPCs.
    )rS   r(   Z"channel_credentials_compute_enginerV   r   r   r   r   "compute_engine_channel_credentials  s
    r   c                 C   s   ddl m} || S )a`  Creates a Future that tracks when a Channel is ready.

    Cancelling the Future does not affect the channel's state machine.
    It merely decouples the Future from channel state machine.

    Args:
      channel: A Channel object.

    Returns:
      A Future object that matures when the channel connectivity is
      ChannelConnectivity.READY.
    r   r   )r   r   channel_ready_future)channelr   r   r   r   r   "  s    r   c                 C   s(   ddl m} || |dkrdn|d|S )a  Creates an insecure Channel to a server.

    The returned Channel is thread-safe.

    Args:
      target: The server address
      options: An optional list of key-value pairs (:term:`channel_arguments`
        in gRPC Core runtime) to configure the channel.
      compression: An optional value indicating the compression method to be
        used over the lifetime of the channel.

    Returns:
      A Channel.
    r   _channelNr   )r   r   rr   )targetoptionsri   r   r   r   r   insecure_channel4  s       r   c                 C   sH   ddl m} ddlm} |j|kr*td|| |dkr<dn||j|S )a  Creates a secure Channel to a server.

    The returned Channel is thread-safe.

    Args:
      target: The server address.
      credentials: A ChannelCredentials instance.
      options: An optional list of key-value pairs (:term:`channel_arguments`
        in gRPC Core runtime) to configure the channel.
      compression: An optional value indicating the compression method to be
        used over the lifetime of the channel.

    Returns:
      A Channel.
    r   r   )_insecure_channel_credentialszYsecure_channel cannot be called with insecure credentials. Call insecure_channel instead.Nr   )r   r   Zgrpc.experimentalr   rV   r   rr   )r   rX   r   ri   r   r   r   r   r   secure_channelJ  s    
r   c                 G   s   ddl m} |j| f| S )a  Intercepts a channel through a set of interceptors.

    Args:
      channel: A Channel.
      interceptors: Zero or more objects of type
        UnaryUnaryClientInterceptor,
        UnaryStreamClientInterceptor,
        StreamUnaryClientInterceptor, or
        StreamStreamClientInterceptor.
        Interceptors are given control in the order they are listed.

    Returns:
      A Channel that intercepts each invocation via the provided interceptors.

    Raises:
      TypeError: If interceptor does not derive from any of
        UnaryUnaryClientInterceptor,
        UnaryStreamClientInterceptor,
        StreamUnaryClientInterceptor, or
        StreamStreamClientInterceptor.
    r   )_interceptor)r   r   intercept_channel)r   interceptorsr   r   r   r   r   j  s    r   c              	   C   sF   ddl m} || |dkrdn||dkr,dn||dkr:dn||||S )a  Creates a Server with which RPCs can be serviced.

    Args:
      thread_pool: A futures.ThreadPoolExecutor to be used by the Server
        to execute RPC handlers.
      handlers: An optional list of GenericRpcHandlers used for executing RPCs.
        More handlers may be added by calling add_generic_rpc_handlers any time
        before the server is started.
      interceptors: An optional list of ServerInterceptor objects that observe
        and optionally manipulate the incoming RPCs before handing them over to
        handlers. The interceptors are given control in the order they are
        specified. This is an EXPERIMENTAL API.
      options: An optional list of key-value pairs (:term:`channel_arguments` in gRPC runtime)
        to configure the channel.
      maximum_concurrent_rpcs: The maximum number of concurrent RPCs this server
        will service before returning RESOURCE_EXHAUSTED status, or None to
        indicate no limit.
      compression: An element of grpc.compression, e.g.
        grpc.compression.Gzip. This compression algorithm will be used for the
        lifetime of the server unless overridden.
      xds: If set to true, retrieves server configuration via xDS. This is an
        EXPERIMENTAL option.

    Returns:
      A Server object.
    r   _serverNr   )r   r   create_server)Zthread_poolhandlersr   r   Zmaximum_concurrent_rpcsri   Zxdsr   r   r   r   server  s    #r   c                 c   s,   ddl m} || ||}|V  |  d S )Nr   r   )r   r   Z_ContextZ_finalize_state)Z	rpc_eventstater   r   rc   r   r   r   _create_servicer_context  s    r   c                   @   s"   e Zd ZdZejZejZejZdS )CompressionzIndicates the compression method to be used for an RPC.

    Attributes:
     NoCompression: Do not use compression algorithm.
     Deflate: Use "Deflate" compression algorithm.
     Gzip: Use "Gzip" compression algorithm.
    N)r
   r   r   r   r   ZNoCompressionZDeflateZGzipr   r   r   r   r     s   r   )@r   r   r   r#   r)   r6   r7   r8   r>   rS   r[   r\   r]   rb   r   rD   re   rd   r   rf   rm   ro   rq   rE   rK   rM   rQ   rr   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   r   r   r   r   r   r   r   r   r   z
grpc.toolszgrpc.healthzgrpc.reflection)      r   )aiozgrpc.aio)NN)NN)NN)NN)NNN)N)N)NF)N)F)N)NN)NN)NNNNNF)er   r!   
contextlibenumloggingsysr   r   Zgrpc._cythonr   r(   Zgrpc._runtime_protosr   r   r   	getLoggerr
   
addHandlerNullHandlerZgrpc._grpcio_metadatar   ImportError	Exceptionr   r   ABCr   uniqueEnumr#   r)   r6   r7   r8   ABCMetar>   rD   rE   rK   rM   rQ   objectrS   r[   r\   r]   rb   rd   re   rf   rm   ro   rq   rr   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   r   r   r   r   r   r   r   r   contextmanagerr   IntEnumr   __all__Z
grpc_toolsmodulesupdateZgrpc_healthZgrpc_reflectionversion_infor   r   r   r   r   <module>   s   
 $?23"##&	i$k' " J$	     
   
   
   
     


  
+ 
# 
"


       
0
F