o
    |j6h/                     @   s`  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   unbeta)beta_metadataerrorcallback h/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/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   GoogleCallCredentials)credentialsr   r   r   google_call_credentials/   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__H   s   
zChannel.__init__Nc                 C   s   | j j||d dS )aF  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"   K   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#   Z   s   zChannel.unsubscriber	   )__name__
__module____qualname____doc__r    r"   r#   r   r   r   r   r   @   s
    
r   c                 C   s&   t |du r| nd| |f }t|S )a@  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)   d   s   r)   c                 C   s(   t |du r| nd| |f |}t|S )au  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+   channel_credentialsr   r   r   r   r,   u   s   r,   c                   @      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*   r1   r2   r3   r4   r5   r   r   r   r       s   	
zStubOptions.__init__Nr$   r%   r&   r'   r    r   r   r   r   r/          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/   r0   r   r   r   stub_options   s   r8   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*   r3   r1   r2   )r   optionseffective_optionsr   r   r   r:      s   
r:   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)r9   r   dynamic_stubr   r*   r3   r1   r2   )r   servicecardinalitiesr;   r<   r   r   r   r=      s   r=   c                   @   r.   )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_serializersr4   r5   default_timeoutmaximum_timeout)r   rB   rC   rD   r4   r5   rE   rF   r   r   r   r      s   

zServerOptions.__init__Nr6   r   r   r   r   r@      r7   r@   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.
    )r@   rA   r   r   r   server_options  s   !rG   c                 C   s.   |du rt n|}t| |j|j|j|j|jS )a  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   serverrB   rC   rD   r4   r5   )service_implementationsr;   r<   r   r   r   rI   E  s   rI   r	   )NNNNNN)NNNNNNN)$r'   	threadingr   r   	grpc.betar   r   r   r   grpc.framework.commonr   grpc.framework.interfaces.facer   ChannelCredentialsssl_channel_credentialsCallCredentialsr   r   access_token_call_credentialscomposite_call_credentialscomposite_channel_credentialsobjectr   r)   r,   r/   r9   r8   r:   r=   ServerCredentialsssl_server_credentialsr@   rH   rG   rI   r   r   r   r   <module>   sZ   

$

&

,