a
    v=ic/                     @   s   d Z ddlZddlmZmZmZmZm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 G d
d dejZG dd deeef ejZdS )z.Abstract base classes for server-side classes.    N)GenericIterableMappingOptionalSequence   )Metadata)DoneCallbackType)MetadataType)RequestType)ResponseTypec                   @   s   e Zd ZdZejeej ddddZ	eje
edddZeje
ejed	d
dZejddddZejee ddddZejdee edddZdS )ServerzServes RPCs.N)generic_rpc_handlersreturnc                 C   s   dS )zRegisters GenericRpcHandlers with this Server.

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

        Args:
          generic_rpc_handlers: A sequence of GenericRpcHandlers that will be
          used to service RPCs.
        N )selfr   r   r   f/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/grpc/aio/_base_server.pyadd_generic_rpc_handlers   s    zServer.add_generic_rpc_handlers)addressr   c                 C   s   dS )a	  Opens an insecure port for accepting RPCs.

        A port is a communication endpoint that used by networking protocols,
        like TCP and UDP. To date, we only support TCP.

        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 the gRPC runtime will choose a port.

        Returns:
          An integer port on which the server will accept RPC requests.
        Nr   )r   r   r   r   r   add_insecure_port,   s    zServer.add_insecure_port)r   server_credentialsr   c                 C   s   dS )aL  Opens a secure port for accepting RPCs.

        A port is a communication endpoint that used by networking protocols,
        like TCP and UDP. To date, we only support TCP.

        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 the gRPC
            runtime will choose a port.
          server_credentials: A ServerCredentials object.

        Returns:
          An integer port on which the server will accept RPC requests.
        Nr   )r   r   r   r   r   r   add_secure_port=   s    zServer.add_secure_portr   c                    s   dS )zgStarts this Server.

        This method may only be called once. (i.e. it is not idempotent).
        Nr   r   r   r   r   startQ   s    zServer.start)gracer   c                    s   dS )a  Stops this Server.

        This method immediately stops the server from servicing new RPCs in
        all cases.

        If a grace period is specified, this method returns immediately and all
        RPCs active at the end of 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.
        Nr   )r   r   r   r   r   stopX   s    zServer.stop)timeoutr   c                    s   dS )a  Continues current coroutine once 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   r   wait_for_terminationp   s    zServer.wait_for_termination)N)__name__
__module____qualname____doc__abcabstractmethodr   grpcZGenericRpcHandlerr   strintr   ZServerCredentialsr   r   r   floatr   boolr   r   r   r   r   r      s&   
 r   c                   @   s  e Zd ZdZejedddZejeddddZ	eje
dd	d
dZejde fejee
ddddZeje
ddddZejee dddZejejddddZejeddddZejejddddZejddddZejedd d!Zejeee  dd"d#Zejee dd$d%Zejeeee f dd&d'Z e!dd(d)Z"d*d+ Z#d,d- Z$d.d/ Z%e&dd0d1d2Z'e(dd3d4Z)e(dd5d6Z*dS )7ServicerContextz2A context object passed to method implementations.r   c                    s   dS )zReads one message from the RPC.

        Only one read operation is allowed simultaneously.

        Returns:
          A response message of the RPC.

        Raises:
          An RpcError exception if the read failed.
        Nr   r   r   r   r   read   s    zServicerContext.readN)messager   c                    s   dS )zWrites one message to the RPC.

        Only one write operation is allowed simultaneously.

        Raises:
          An RpcError exception if the write failed.
        Nr   )r   r,   r   r   r   write   s    zServicerContext.write)initial_metadatar   c                    s   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_metadata )codedetailstrailing_metadatar   c                    s   dS )as  Raises an exception to terminate the RPC with a non-OK status.

        The code and details passed as arguments will supercede 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.
          trailing_metadata: A sequence of tuple represents the trailing
            :term:`metadata`.

        Raises:
          Exception: An exception is always raised to signal the abortion the
            RPC to the gRPC runtime.
        Nr   )r   r1   r2   r3   r   r   r   abort   s    zServicerContext.abort)r3   r   c                 C   s   dS )a  Sends the trailing metadata for the RPC.

        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   r3   r   r   r   set_trailing_metadata   s    z%ServicerContext.set_trailing_metadatac                 C   s   dS )zoAccesses the metadata sent by the client.

        Returns:
          The invocation :term:`metadata`.
        Nr   r   r   r   r   invocation_metadata   s    z#ServicerContext.invocation_metadata)r1   r   c                 C   s   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   r1   r   r   r   set_code   s    zServicerContext.set_code)r2   r   c                 C   s   dS )a8  Sets the value to be used the 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   r2   r   r   r   set_details   s    zServicerContext.set_details)compressionr   c                 C   s   dS )zSet the compression algorithm to be used for the entire call.

        This is an EXPERIMENTAL method.

        Args:
          compression: An element of grpc.compression, e.g.
            grpc.compression.Gzip.
        Nr   )r   r9   r   r   r   set_compression   s    zServicerContext.set_compressionc                 C   s   dS )zDisables compression for the next response message.

        This is an EXPERIMENTAL method.

        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_compressionc                 C   s   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   peer  s    zServicerContext.peerc                 C   s   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_identities  s    zServicerContext.peer_identitiesc                 C   s   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   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   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_remaining0  s    zServicerContext.time_remainingc                 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.
        NNotImplementedErrorr   r   r   r   r3   9  s    z!ServicerContext.trailing_metadatac                 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.
        NrA   r   r   r   r   r1   C  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.
        NrA   r   r   r   r   r2   M  s    zServicerContext.details)callbackr   c                 C   s   dS )zRegisters a callback to be called on RPC termination.

        This is an EXPERIMENTAL API.

        Args:
          callback: A callable object will be called with the servicer context
            object as its only argument.
        Nr   )r   rC   r   r   r   add_done_callbackW  s    z!ServicerContext.add_done_callbackc                 C   s   dS )zReturn True if the RPC is cancelled.

        The RPC is cancelled when the cancellation was requested with cancel().

        This is an EXPERIMENTAL API.

        Returns:
          A bool indicates whether the RPC is cancelled or not.
        Nr   r   r   r   r   	cancelleda  s    zServicerContext.cancelledc                 C   s   dS )zReturn True if the RPC is done.

        An RPC is done if the RPC is completed, cancelled or aborted.

        This is an EXPERIMENTAL API.

        Returns:
          A bool indicates if the RPC is done.
        Nr   r   r   r   r   donel  s    zServicerContext.done)+r   r    r!   r"   r#   r$   r   r+   r   r-   r
   r/   tupler%   Z
StatusCoder&   r4   r5   r   r   r6   r7   r8   ZCompressionr:   r;   r<   r   bytesr=   r>   r   r?   r(   r@   r3   r1   r2   r	   rD   r)   rE   rF   r   r   r   r   r*      sV   	


		



r*   )r"   r#   typingr   r   r   r   r   r%   	_metadatar   Z_typingr	   r
   r   r   ABCr   r*   r   r   r   r   <module>   s   n