a
    v=ic..                     @   sF  d 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 ddl	m
Z
 dd	lmZ ejZejZejZd"d
dZdd ZejZejZejZG dd deZdd Zdd ZG dd deZeddddddZd#ddZd$ddZd%ddZejZejZG dd deZ e dddddddZ!d&ddZ"d'd d!Z#dS )(z.Entry points into the Beta API of gRPC Python.    N)_auth)_client_adaptations)	_metadata)_server_adaptations)
interfaces)cardinality)facec                    s    fdd}t j||dS )Nc                    s    fdd}| | d S )Nc                    s    t | | d S N)r   Zunbeta)Zbeta_metadataerrorcallback j/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/grpc/beta/implementations.pywrapped_callback*   s    zCmetadata_call_credentials.<locals>.plugin.<locals>.wrapped_callbackr   )contextr   r   metadata_pluginr   r   plugin(   s    z)metadata_call_credentials.<locals>.plugin)name)grpcmetadata_call_credentials)r   r   r   r   r   r   r   &   s    r   c                 C   s   t t| S )zConstruct CallCredentials from GoogleCredentials.

  Args:
    credentials: A GoogleCredentials object from the oauth2client library.

  Returns:
    A CallCredentials object for use in a GRPCCallOptions object.
  )r   r   ZGoogleCallCredentials)credentialsr   r   r   google_call_credentials2   s    	r   c                   @   s*   e Zd ZdZdd Zd	ddZdd ZdS )
ChannelzA channel to a remote host through which RPCs may be conducted.

  Only the "subscribe" and "unsubscribe" methods are supported for application
  use. This class' instance constructor and all other attributes are
  unsupported.
  c                 C   s
   || _ d S r	   )_channel)selfchannelr   r   r   __init__K   s    zChannel.__init__Nc                 C   s   | j j||d dS )a  Subscribes to this Channel's connectivity.

    Args:
      callback: A callable to be invoked and passed an
        interfaces.ChannelConnectivity identifying this Channel's connectivity.
        The callable will be invoked immediately upon subscription and again for
        every change to this Channel's connectivity thereafter until it is
        unsubscribed.
      try_to_connect: A boolean indicating whether or not this Channel should
        attempt to connect if it is not already connected and ready to conduct
        RPCs.
    )try_to_connectN)r   	subscribe)r   r   r   r   r   r   r   N   s    zChannel.subscribec                 C   s   | j | dS )zUnsubscribes a callback from this Channel's connectivity.

    Args:
      callback: A callable previously registered with this Channel from having
        been passed to its "subscribe" method.
    N)r   unsubscribe)r   r   r   r   r   r    ]   s    zChannel.unsubscribe)N)__name__
__module____qualname____doc__r   r   r    r   r   r   r   r   C   s   
r   c                 C   s&   t |du r| n
d| |f }t|S )a2  Creates an insecure Channel to a remote host.

  Args:
    host: The name of the remote host to which to connect.
    port: The port of the remote host to which to connect.
      If None only the 'host' part will be used.

  Returns:
    A Channel to the remote host through which RPCs may be conducted.
  N%s:%d)r   insecure_channelr   )hostportr   r   r   r   r&   g   s    r&   c                 C   s(   t |du r| n
d| |f |}t|S )ae  Creates a secure Channel to a remote host.

  Args:
    host: The name of the remote host to which to connect.
    port: The port of the remote host to which to connect.
      If None only the 'host' part will be used.
    channel_credentials: A ChannelCredentials.

  Returns:
    A secure Channel to the remote host through which RPCs may be conducted.
  Nr%   )r   secure_channelr   )r'   r(   Zchannel_credentialsr   r   r   r   r)   w   s    r)   c                   @   s   e Zd ZdZdd ZdS )StubOptionszA value encapsulating the various options for creation of a Stub.

  This class and its instances have 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 r	   r'   request_serializersresponse_deserializersmetadata_transformerthread_poolthread_pool_size)r   r'   r,   r-   r.   r/   r0   r   r   r   r      s    zStubOptions.__init__Nr!   r"   r#   r$   r   r   r   r   r   r*      s   r*   c                 C   s   t | |||||S )a;  Creates a StubOptions value to be passed at stub creation.

  All parameters are optional and should always be passed by keyword.

  Args:
    host: A host string to set on RPC calls.
    request_serializers: A dictionary from service name-method name pair to
      request serialization behavior.
    response_deserializers: A dictionary from service name-method name pair to
      response deserialization behavior.
    metadata_transformer: A callable that given a metadata object produces
      another metadata object to be used in the underlying communication on the
      wire.
    thread_pool: A thread pool to use in stubs.
    thread_pool_size: The size of thread pool to create for use in stubs;
      ignored if thread_pool has been passed.

  Returns:
    A StubOptions value created from the passed parameters.
  )r*   r+   r   r   r   stub_options   s    r2   c                 C   s,   |du rt n|}t| j|j|j|j|jS )zCreates a face.GenericStub on which RPCs can be made.

  Args:
    channel: A Channel for use by the created stub.
    options: A StubOptions customizing the created stub.

  Returns:
    A face.GenericStub on which RPCs can be made.
  N)_EMPTY_STUB_OPTIONSr   generic_stubr   r'   r.   r,   r-   )r   optionseffective_optionsr   r   r   r4      s    
r4   c              	   C   s0   |du rt n|}t| j|||j|j|j|jS )a  Creates a face.DynamicStub with which RPCs can be invoked.

  Args:
    channel: A Channel for the returned face.DynamicStub to use.
    service: The package-qualified full name of the service.
    cardinalities: A dictionary from RPC method name to cardinality.Cardinality
      value identifying the cardinality of the RPC method.
    options: An optional StubOptions value further customizing the functionality
      of the returned face.DynamicStub.

  Returns:
    A face.DynamicStub with which RPCs can be invoked.
  N)r3   r   dynamic_stubr   r'   r.   r,   r-   )r   ZserviceZcardinalitiesr5   r6   r   r   r   r7      s    r7   c                   @   s   e Zd ZdZdd ZdS )ServerOptionszA value encapsulating the various options for creation of a Server.

  This class and its instances have 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 r	   multi_method_implementationrequest_deserializersresponse_serializersr/   r0   default_timeoutmaximum_timeout)r   r:   r;   r<   r/   r0   r=   r>   r   r   r   r      s    zServerOptions.__init__Nr1   r   r   r   r   r8      s   r8   c                 C   s   t | ||||||S )a|  Creates a ServerOptions value to be passed at server creation.

  All parameters are optional and should always be passed by keyword.

  Args:
    multi_method_implementation: A face.MultiMethodImplementation to be called
      to service an RPC if the server has no specific method implementation for
      the name of the RPC for which service was requested.
    request_deserializers: A dictionary from service name-method name pair to
      request deserialization behavior.
    response_serializers: A dictionary from service name-method name pair to
      response serialization behavior.
    thread_pool: A thread pool to use in stubs.
    thread_pool_size: The size of thread pool to create for use in stubs;
      ignored if thread_pool has been passed.
    default_timeout: A duration in seconds to allow for RPC service when
      servicing RPCs that did not include a timeout value when invoked.
    maximum_timeout: A duration in seconds to allow for RPC service when
      servicing RPCs no matter what timeout value was passed when the RPC was
      invoked.

  Returns:
    A StubOptions value created from the passed parameters.
  )r8   r9   r   r   r   server_options  s    r?   c                 C   s.   |du rt n|}t| |j|j|j|j|jS )aq  Creates an interfaces.Server with which RPCs can be serviced.

  Args:
    service_implementations: A dictionary from service name-method name pair to
      face.MethodImplementation.
    options: An optional ServerOptions value further customizing the
      functionality of the returned Server.

  Returns:
    An interfaces.Server with which RPCs can be serviced.
  N)_EMPTY_SERVER_OPTIONSr   serverr:   r;   r<   r/   r0   )Zservice_implementationsr5   r6   r   r   r   rA   &  s    rA   )N)NNNNNN)N)N)NNNNNNN)N)$r$   	threadingr   r   Z	grpc.betar   r   r   r   Zgrpc.framework.commonr   Zgrpc.framework.interfaces.facer   ZChannelCredentialsZssl_channel_credentialsZCallCredentialsr   r   Zaccess_token_call_credentialsZcomposite_call_credentialsZcomposite_channel_credentialsobjectr   r&   r)   r*   r3   r2   r4   r7   ZServerCredentialsZssl_server_credentialsr8   r@   r?   rA   r   r   r   r   <module>   sX   
$      


       
$