HEX
Server: LiteSpeed
System: Linux srv146.niagahoster.com 4.18.0-553.30.1.lve.el8.x86_64 #1 SMP Tue Dec 3 01:21:19 UTC 2024 x86_64
User: kodi1989 (1633)
PHP: 8.1.34
Disabled: symlink,shell_exec,exec,popen,system,dl,passthru,escapeshellarg,escapeshellcmd,show_source,pcntl_exec
Upload Files
File: //opt/alt/python37/lib64/python3.7/site-packages/grpc/__pycache__/_channel.cpython-37.pyc
B

��f�1�	@stdZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZm
Z
mZmZmZmZmZddlZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlm Z ddlm!Z!ddlm"Z"ddl#Ze�$e%�Z&d�'ej(�Z)dZ*e�+d�dk	Z,ej-j.ej-j/ej-j0ej-j1ej-j2ej-j3fZ4ej-j.ej-j/ej-j0ej-j1ej-j3fZ5ej-j.ej-j1ej-j2ej-j3fZ6ej-j.ej-j1ej-j3fZ7dZ8dZ9dZ:ee;ee;d�dd�Z<eej=ee>e>d�dd�Z?Gdd�de@�ZAeAej=e>dd�dd �ZBejCeAeee
ed!�d"d#�ZDeAeee"d$�d%d&�ZEeeAeejFejGfe!ee"dd'�d(d)�ZHe>eAe>d*�d+d,�ZIGd-d.�d.ejJejKejL�ZMGd/d0�d0ejJejN�ZOGd1d2�d2eOejKejL�ZPGd3d4�d4eOejKejL�ZQe
ee;e!eee;eeReejJfd5�d6d7�ZSeAejGeTee;ee ee ejKffd8�d9d:�ZUeeeVeeejWd;�d<d=�ZXeeeVeeeejWee"fd;�d>d?�ZYee;ee;d@�dAdB�ZZGdCdD�dDej[�Z\GdEdF�dFej]�Z^GdGdH�dHej]�Z_GdIdJ�dJej`�ZaGdKdL�dLejb�ZcGdMdN�dNeV�ZdGdOdP�dPe@�ZeeeddQ�dRdS�ZfeedT�dUdV�ZgGdWdX�dXe@�Zhehe
eejigdfdQ�dYdZ�Zjehejieeejigdfdd[�d\d]�Zkeheeejigdfdd^�d_d`�ZlehejmeTdda�dbdc�ZneheejigdfeTddd�dedf�Zoeheejigdfddg�dhdi�Zpeeeejqeedj�dkdl�Zreeeeeeefdm�dndo�ZsGdpdq�dqejm�ZmdS)rz.Invocation-side implementation of gRPC Python.�N)	�Any�Callable�Iterator�List�Optional�Sequence�Set�Tuple�Union)�_common)�_compression)�_grpcio_metadata)�_observability)�cygrpc)�ChannelArgumentType)�DeserializingFunction)�IntegratedCallFactory)�MetadataType)�NullaryCallbackType)�ResponseType)�SerializingFunction)�UserTagzgrpc-python/{}Z!GRPC_SINGLE_THREADED_UNARY_STREAMz0Exception calling channel subscription callback!z?<{} of RPC that terminated with:
	status = {}
	details = "{}"
>zZ<{} of RPC that terminated with:
	status = {}
	details = "{}"
	debug_error_string = "{}"
>)�timeout�returncCs|dkrdSt��|S)N)�time)r�r�@/opt/alt/python37/lib64/python3.7/site-packages/grpc/_channel.py�	_deadlinelsr)�unknown_cygrpc_code�detailsrcCsd�||�S)Nz,Server sent unknown code {} and details "{}")�format)rrrrr�_unknown_code_detailspsr!c@s�eZdZUejed<eejed<e	e
ed<eed<e	e
ed<e	ej
ed<e	eed<e	eed<eed	<eeed
<e	eed<e	eed<e	eed
<e	eed<e	eed<eeje	e
e	e
e	ej
e	ed�dd�Zdd�ZdS)�	_RPCState�	condition�due�initial_metadata�response�trailing_metadata�coder�debug_error_string�	cancelled�	callbacks�
fork_epoch�rpc_start_time�rpc_end_time�method�target)r$r%r'r(rcCsjt��|_t|�|_||_d|_||_||_||_	d|_
d|_d|_d|_
d|_d|_g|_t��|_dS)NF)�	threading�	Conditionr#�setr$r%r&r'r(rr)r-r.r/r0r*r+r�get_fork_epochr,)�selfr$r%r'r(rrrr�__init__�s


z_RPCState.__init__cCst��|_dS)N)r1r2r#)r5rrr�reset_postfork_child�sz_RPCState.reset_postfork_childN)�__name__�
__module__�__qualname__r1r2�__annotations__rr�
OperationTyperrr�grpc�
StatusCode�str�boolrr�int�floatrr6r7rrrrr"xs*

"r")�stater(rrcCs0|jdkr,||_||_|jdkr&d|_d|_dS)Nr)r(rr%r')rCr(rrrr�_abort�s

rD)�eventrC�response_deserializerrc
Cs*g}�x|jD�]}|��}|j�|�|tjjkr@|��|_q|tjjkr�|�	�}|dk	r�t
�||�}|dkr�d}t|t
jj|�n||_q|tjjkr|��|_|jdkr�t
j�|���}	|	dkr�t
jj|_t|	|���|_n|	|_|��|_|��|_t��|_t�|�|� |j!�d|_!qW|S)Nz!Exception deserializing response!)"Zbatch_operations�typer$�removerr<�receive_initial_metadatar%�receive_message�messagerZdeserializerDr=r>�INTERNALr&�receive_status_on_clientr'r(Z!CYGRPC_STATUS_CODE_TO_STATUS_CODE�get�UNKNOWNr!rZerror_stringr)r�perf_counterr.rZmaybe_record_rpc_latency�extendr+)
rErCrFr+Zbatch_operationZoperation_typeZserialized_responser&rr(rrr�
_handle_event�s@








rR)rCrFrcs��fdd�}|S)Ncs��j�$t|���}�j���j}WdQRXxR|D]J}y
|�Wq6tk
r~}zt�dt|j�t|��Wdd}~XYq6Xq6W|o��j	t
��kS)NzException in callback %s: %s)r#rR�
notify_allr$�	Exception�logging�error�repr�funcr,rr4)rEr+�done�callback�e)rFrCrr�handle_event�s


*z$_event_handler.<locals>.handle_eventr)rCrFr\r)rFrCr�_event_handler�sr])�request_iteratorrC�call�request_serializer�
event_handlerrcs6�����fdd�}tj|d�}|�d�|��dS)z'Consume a request supplied by the user.c	s��x�d}z�yt��t��}Wnhtk
r4PYnTtk
r�t��d}tjj}d}t	�
|���tj
||�t�||�dSXWd|s�t��Xt�|��}�j���jdk�rx�j�sx|dkr�tjj}d}��tj
||�t�||�dS�j�tjj�t�|t�f}��|��}|�s<�j�tjj�dS�fdd�}tj�jj|t�tj��d��jdk	�r|dSndSWdQRXqW�j�P�jdk�r܈j�tjj �t�!t�f}��|��}|�s܈j�tjj �WdQRXdS)NFTzException iterating requests!zException serializing request!cs�jdk	ptjj�jkS)N)r(rr<�send_messager$r)rCrr�_done<s
zJ_consume_request_iterator.<locals>.consume_request_iterator.<locals>._done)Zspin_cb)"rZenter_user_request_generator�next�
StopIterationrTZ"return_from_user_request_generatorr=r>rO�_LOGGER�	exception�cancelr�!STATUS_CODE_TO_CYGRPC_STATUS_CODErD�	serializer#r(r*rLr$�addr<rb�SendMessageOperation�_EMPTY_FLAGS�operaterH�wait�	functools�partial�block_if_fork_in_progress�send_close_from_client�SendCloseFromClientOperation)Z*return_from_user_request_generator_invoked�requestr(r�serialized_request�
operations�	operatingrc)r_rar^r`rCrr�consume_request_iteratorsl



z;_consume_request_iterator.<locals>.consume_request_iterator)r0TN)r�ForkManagedThread�	setDaemon�start)r^rCr_r`raryZconsumption_threadr)r_rar^r`rCr�_consume_request_iterators
	O
r})�
class_name�	rpc_staterc	Cs`|j�P|jdkrd�|�S|jtjjkr<t�||j|j�St�||j|j|j	�SWdQRXdS)z Calculates error string for RPC.Nz<{} object>)
r#r(r r=r>�OK�_OK_RENDEZVOUS_REPR_FORMATr�_NON_OK_RENDEZVOUS_REPR_FORMATr))r~rrrr�_rpc_state_stringas

r�c@sVeZdZUdZeed<ed�dd�Zeed�dd�Z	eed�d	d
�Z
eejd�dd�Z
eed�d
d�Zeed�dd�Zed�dd�Zed�dd�Zed�dd�Zed�dd�Zed�dd�Zed�dd�Zed�dd�Zd*eeed �d!d"�Zd+eeeed �d#d$�Zd,eeeejd �d%d&�Z d-e!ej"gdfeedd'�d(d)�Z#dS).�_InactiveRpcErrorz�An RPC error not tied to the execution of a particular RPC.

    The RPC represented by the state object must not be in-progress or
    cancelled.

    Attributes:
      _state: An instance of _RPCState.
    �_state)rCc	Csb|j�Rtdt�|j�t�|j�|jt�|j��|_t�|j	�|j_	t�|j
�|j_
WdQRXdS)Nr)r#r"�copy�deepcopyr%r'r(rr�r&r))r5rCrrrr6s

z_InactiveRpcError.__init__)rcCs|jjS)N)r�r%)r5rrrr%�sz"_InactiveRpcError.initial_metadatacCs|jjS)N)r�r')r5rrrr'�sz#_InactiveRpcError.trailing_metadatacCs|jjS)N)r�r()r5rrrr(�sz_InactiveRpcError.codecCst�|jj�S)N)r�decoder�r)r5rrrr�sz_InactiveRpcError.detailscCst�|jj�S)N)rr�r�r))r5rrrr)�sz$_InactiveRpcError.debug_error_stringcCst|jj|j�S)N)r��	__class__r8r�)r5rrr�_repr�sz_InactiveRpcError._reprcCs|��S)N)r�)r5rrr�__repr__�sz_InactiveRpcError.__repr__cCs|��S)N)r�)r5rrr�__str__�sz_InactiveRpcError.__str__cCsdS)zSee grpc.Future.cancel.Fr)r5rrrrh�sz_InactiveRpcError.cancelcCsdS)zSee grpc.Future.cancelled.Fr)r5rrrr*�sz_InactiveRpcError.cancelledcCsdS)zSee grpc.Future.running.Fr)r5rrr�running�sz_InactiveRpcError.runningcCsdS)zSee grpc.Future.done.Tr)r5rrrrY�sz_InactiveRpcError.doneN)rrcCs|�dS)zSee grpc.Future.result.Nr)r5rrrr�result�sz_InactiveRpcError.resultcCs|S)zSee grpc.Future.exception.r)r5rrrrrg�sz_InactiveRpcError.exceptioncCs,y|�Wntjk
r&t��dSXdS)zSee grpc.Future.traceback.�N)r=�RpcError�sys�exc_info)r5rrrr�	traceback�sz_InactiveRpcError.traceback)�fnrrcCs||�dS)z"See grpc.Future.add_done_callback.Nr)r5r�rrrr�add_done_callback�sz#_InactiveRpcError.add_done_callback)N)N)N)N)$r8r9r:�__doc__r"r;r6rrr%r'r=r>r(r?rr)r�r�r�r@rhr*r�rYrBrr�rTrg�types�
TracebackTyper�r�Futurer�rrrrr�ss.

r�cseZdZUdZeed<eejej	fed<e
eed<e
eed<eeejej	fe
ee
ed��fdd�Z
ed	�d
d�Ze
ed	�dd
�Zed	�dd�Zeed�dd�Zdd�Zdd�Zdd�Zdd�Ze
ed	�dd�Zed	�dd�Zed	�dd �Zed	�d!d"�Zd#d	�d$d%�Z�ZS)&�_Rendezvousa�An RPC iterator.

    Attributes:
      _state: An instance of _RPCState.
      _call: An instance of SegregatedCall or IntegratedCall.
        In either case, the _call object is expected to have operate, cancel,
        and next_event methods.
      _response_deserializer: A callable taking bytes and return a Python
        object.
      _deadline: A float representing the deadline of the RPC in seconds. Or
        possibly None, to represent an RPC with no deadline at all.
    r��_call�_response_deserializerr)rCr_rF�deadlinecs*tt|���||_||_||_||_dS)N)�superr�r6r�r�r�r)r5rCr_rFr�)r�rrr6�s
z_Rendezvous.__init__)rc	Cs |jj�|jjdkSQRXdS)zSee grpc.RpcContext.is_activeN)r�r#r()r5rrr�	is_active�s
z_Rendezvous.is_activec	Cs:|jj�(|jdkrdSt|jt��d�SWdQRXdS)z"See grpc.RpcContext.time_remainingNr)r�r#r�maxr)r5rrr�time_remaining�s

z_Rendezvous.time_remainingc	Csn|jj�\|jjdkr\tjj}d}|j�tj	||�d|j_
t|j||�|jj��dSdSWdQRXdS)zSee grpc.RpcContext.cancelNz!Locally cancelled by application!TF)
r�r#r(r=r>�	CANCELLEDr�rhrrir*rDrS)r5r(rrrrrh�s
z_Rendezvous.cancel)rZrc	Cs:|jj�(|jjdkrdS|jj�|�dSWdQRXdS)z See grpc.RpcContext.add_callbackNFT)r�r#r+�append)r5rZrrr�add_callbacks

z_Rendezvous.add_callbackcCs|S)Nr)r5rrr�__iter__sz_Rendezvous.__iter__cCs|��S)N)�_next)r5rrrrdsz_Rendezvous.nextcCs|��S)N)r�)r5rrr�__next__sz_Rendezvous.__next__cCs
t��dS)N)�NotImplementedError)r5rrrr� sz_Rendezvous._nextcCs
t��dS)N)r�)r5rrrr)#sz_Rendezvous.debug_error_stringcCst|jj|j�S)N)r�r�r8r�)r5rrrr�&sz_Rendezvous._reprcCs|��S)N)r�)r5rrrr�)sz_Rendezvous.__repr__cCs|��S)N)r�)r5rrrr�,sz_Rendezvous.__str__Nc	Csh|jj�V|jjdkrZtjj|j_d|j_d|j_|j�	t
j|jj|jj�|jj��WdQRXdS)Nz"Cancelled upon garbage collection!T)
r�r#r(r=r>r�rr*r�rhrrirS)r5rrr�__del__/s

z_Rendezvous.__del__)r8r9r:r�r"r;r
r�SegregatedCall�IntegratedCallrrrBr6r@r�r�rhrr�r�rdr�r�r?r)r�r�r�r��
__classcell__rr)r�rr��s,
	r�c@sFeZdZUdZeed<ed�dd�Zed�dd�Zed�dd	�Z	ed�d
d�Z
d'eee
d
�dd�Zd(eeeed
�dd�Zd)eeeejd
�dd�Zeejgdfdd�dd�Zeed�dd�Zeed�dd�Zeejd�dd�Zeed�dd�Zeej d�dd �Z!e
d�d!d"�Z"e
d�d#d$�Z#eed�d%d&�Z$dS)*�_SingleThreadedRendezvousaNAn RPC iterator operating entirely on a single thread.

    The __next__ method of _SingleThreadedRendezvous does not depend on the
    existence of any other thread, including the "channel spin thread".
    However, this means that its interface is entirely synchronous. So this
    class cannot completely fulfill the grpc.Future interface. The result,
    exception, and traceback methods will never block and will instead raise
    an exception if calling the method would result in blocking.

    This means that these methods are safe to call from add_done_callback
    handlers.
    r�)rcCs|jjdk	S)N)r�r()r5rrr�_is_completeNsz&_SingleThreadedRendezvous._is_completec	Cs|jj�
|jjSQRXdS)N)r�r#r*)r5rrrr*Qs
z#_SingleThreadedRendezvous.cancelledc	Cs |jj�|jjdkSQRXdS)N)r�r#r()r5rrrr�Us
z!_SingleThreadedRendezvous.runningc	Cs |jj�|jjdk	SQRXdS)N)r�r#r()r5rrrrYYs
z_SingleThreadedRendezvous.doneN)rrc	Cs\~|jj�H|��s tj�d��|jjtjjkr8|jj	S|jj
rJt���n|�WdQRXdS)a9Returns the result of the computation or raises its exception.

        This method will never block. Instead, it will raise an exception
        if calling this method would otherwise result in blocking.

        Since this method will never block, any `timeout` argument passed will
        be ignored.
        zJ_SingleThreadedRendezvous only supports result() when the RPC is complete.N)r�r#r�r=�experimental�
UsageErrorr(r>r�r&r*�FutureCancelledError)r5rrrrr�]s	

z _SingleThreadedRendezvous.resultc	CsX~|jj�D|��s tj�d��|jjtjjkr4dS|jj	rFt�
��n|SWdQRXdS)a*Return the exception raised by the computation.

        This method will never block. Instead, it will raise an exception
        if calling this method would otherwise result in blocking.

        Since this method will never block, any `timeout` argument passed will
        be ignored.
        zM_SingleThreadedRendezvous only supports exception() when the RPC is complete.N)r�r#r�r=r�r�r(r>r�r*r�)r5rrrrrgts	

z#_SingleThreadedRendezvous.exceptionc	Cs|~|jj�h|��s tj�d��|jjtjjkr4dS|jj	rFt�
��n(y|�Wntjk
rlt�
�dSXWdQRXdS)a;Access the traceback of the exception raised by the computation.

        This method will never block. Instead, it will raise an exception
        if calling this method would otherwise result in blocking.

        Since this method will never block, any `timeout` argument passed will
        be ignored.
        zM_SingleThreadedRendezvous only supports traceback() when the RPC is complete.Nr�)r�r#r�r=r�r�r(r>r�r*r�r�r�r�)r5rrrrr��s

z#_SingleThreadedRendezvous.traceback)r�rc	CsF|jj�,|jjdkr0|jj�t�||��dSWdQRX||�dS)N)r�r#r(r+r�rprq)r5r�rrrr��s

z+_SingleThreadedRendezvous.add_done_callbackc	Cs6|jj�$x|jjdkr"|��qW|jjSQRXdS)zSee grpc.Call.initial_metadataN)r�r#r%�_consume_next_event)r5rrrr%�s
z*_SingleThreadedRendezvous.initial_metadatac	Cs4|jj�"|jjdkr"tj�d��|jjSQRXdS)zSee grpc.Call.trailing_metadataNz4Cannot get trailing metadata until RPC is completed.)r�r#r'r=r�r�)r5rrrr'�s

z+_SingleThreadedRendezvous.trailing_metadatac	Cs4|jj�"|jjdkr"tj�d��|jjSQRXdS)zSee grpc.Call.codeNz'Cannot get code until RPC is completed.)r�r#r(r=r�r�)r5rrrr(�s

z_SingleThreadedRendezvous.codec	Cs:|jj�(|jjdkr"tj�d��t�|jj�SQRXdS)zSee grpc.Call.detailsNz*Cannot get details until RPC is completed.)r�r#rr=r�r�rr�)r5rrrr�s

z!_SingleThreadedRendezvous.detailsc	CsF|j��}|jj�*t||j|j�}x|D]
}|�q*WWdQRX|S)N)r��
next_eventr�r#rRr�)r5rEr+rZrrrr��s


z-_SingleThreadedRendezvous._consume_next_eventc	Cs~xx|��|jj�^|jjdk	r4|jj}d|j_|Stjj|jjkrl|jjt	j
jkr\t��n|jjdk	rl|�WdQRXqWdS)N)
r�r�r#r&rr<rJr$r(r=r>r�re)r5r&rrr�_next_response�s
z(_SingleThreadedRendezvous._next_responsec	Cs�|jj�n|jjdkrV|jj�tjj�|j�	t�
t�fd�}|sr|jj�tjj�n|jjt
jjkrnt��n|�WdQRX|��S)N)r�r#r(r$rkrr<rJr�rn�ReceiveMessageOperationrmrHr=r>r�rer�)r5rxrrrr��s
z_SingleThreadedRendezvous._nextc	Cs:|jj�(|jjdkr"tj�d��t�|jj�SQRXdS)Nz5Cannot get debug error string until RPC is completed.)r�r#r)r=r�r�rr�)r5rrrr)	s

z,_SingleThreadedRendezvous.debug_error_string)N)N)N)%r8r9r:r�r"r;r@r�r*r�rYrrBrr�rTrgr�r�r�rr=r�r�rr%r'r>r(r?rr�	BaseEventr�r�r�r)rrrrr�<s&
				r�c@s$eZdZUdZeed<eed�dd�Zeed�dd�Z	ee
jd�dd	�Zee
d�d
d�Zee
d�dd
�Zed�dd�Zed�dd�Zed�dd�Zed�dd�Zd#eeed�dd�Zd$eeeed�dd�Zd%eeeejd�dd�Zee
jgdfdd�dd �Zed�d!d"�Z dS)&�_MultiThreadedRendezvousa�An RPC iterator that depends on a channel spin thread.

    This iterator relies upon a per-channel thread running in the background,
    dequeueing events from the completion queue, and notifying threads waiting
    on the threading.Condition object in the _RPCState object.

    This extra thread allows _MultiThreadedRendezvous to fulfill the grpc.Future interface
    and to mediate a bidirection streaming RPC.
    r�)rc	s:�jj�(�fdd�}t��jjj|��jjSQRXdS)zSee grpc.Call.initial_metadatacs�jjdk	S)N)r�r%r)r5rrrc%sz8_MultiThreadedRendezvous.initial_metadata.<locals>._doneN)r�r#rror%)r5rcr)r5rr%!s
z)_MultiThreadedRendezvous.initial_metadatac	s:�jj�(�fdd�}t��jjj|��jjSQRXdS)zSee grpc.Call.trailing_metadatacs�jjdk	S)N)r�r'r)r5rrrc/sz9_MultiThreadedRendezvous.trailing_metadata.<locals>._doneN)r�r#rror')r5rcr)r5rr'+s
z*_MultiThreadedRendezvous.trailing_metadatac	s:�jj�(�fdd�}t��jjj|��jjSQRXdS)zSee grpc.Call.codecs�jjdk	S)N)r�r(r)r5rrrc9sz,_MultiThreadedRendezvous.code.<locals>._doneN)r�r#rror()r5rcr)r5rr(5s
z_MultiThreadedRendezvous.codec	s@�jj�.�fdd�}t��jjj|�t��jj�SQRXdS)zSee grpc.Call.detailscs�jjdk	S)N)r�rr)r5rrrcCsz/_MultiThreadedRendezvous.details.<locals>._doneN)r�r#rror�r)r5rcr)r5rr?s
z _MultiThreadedRendezvous.detailsc	s@�jj�.�fdd�}t��jjj|�t��jj�SQRXdS)Ncs�jjdk	S)N)r�r)r)r5rrrcLsz:_MultiThreadedRendezvous.debug_error_string.<locals>._done)r�r#rror�r))r5rcr)r5rr)Is
z+_MultiThreadedRendezvous.debug_error_stringc	Cs|jj�
|jjSQRXdS)N)r�r#r*)r5rrrr*Rs
z"_MultiThreadedRendezvous.cancelledc	Cs |jj�|jjdkSQRXdS)N)r�r#r()r5rrrr�Vs
z _MultiThreadedRendezvous.runningc	Cs |jj�|jjdk	SQRXdS)N)r�r#r()r5rrrrYZs
z_MultiThreadedRendezvous.donecCs|jjdk	S)N)r�r()r5rrrr�^sz%_MultiThreadedRendezvous._is_completeN)rrc	Csl|jj�Ztj|jjj|j|d�}|r0t���n.|jjtjj	krH|jj
S|jjrZt���n|�WdQRXdS)z�Returns the result of the computation or raises its exception.

        See grpc.Future.result for the full API contract.
        )rN)
r�r#rror�r=�FutureTimeoutErrorr(r>r�r&r*r�)r5r�	timed_outrrrr�as


z_MultiThreadedRendezvous.resultc	Csh|jj�Vtj|jjj|j|d�}|r0t���n*|jjtjj	krDdS|jj
rVt���n|SWdQRXdS)zvReturn the exception raised by the computation.

        See grpc.Future.exception for the full API contract.
        )rN)r�r#rror�r=r�r(r>r�r*r�)r5rr�rrrrgts


z"_MultiThreadedRendezvous.exceptionc	Cs�|jj�ztj|jjj|j|d�}|r0t���nN|jjtjj	krDdS|jj
rVt���n(y|�Wntjk
r|t
��dSXWdQRXdS)z�Access the traceback of the exception raised by the computation.

        See grpc.future.traceback for the full API contract.
        )rNr�)r�r#rror�r=r�r(r>r�r*r�r�r�r�)r5rr�rrrr��s


z"_MultiThreadedRendezvous.traceback)r�rc	CsF|jj�,|jjdkr0|jj�t�||��dSWdQRX||�dS)N)r�r#r(r+r�rprq)r5r�rrrr��s

z*_MultiThreadedRendezvous.add_done_callbackc	s�jj���jjdkrdt�j�j�}�jj�tjj	��j
�t�t
�f|�}|s��jj�tjj	�n�jjtjjkr|t��n���fdd�}t��jjj|��jjdk	r��jj}d�j_|Stjj	�jjkr��jjtjjkr�t��n�jjdk	r���WdQRXdS)Ncs(�jjdk	p&tjj�jjko&�jjdk	S)N)r�r&rr<rJr$r(r)r5rr�_response_ready�sz7_MultiThreadedRendezvous._next.<locals>._response_ready)r�r#r(r]r�r$rkrr<rJr�rnr�rmrHr=r>r�rerror&)r5rarxr�r&r)r5rr��s0

z_MultiThreadedRendezvous._next)N)N)N)!r8r9r:r�r"r;rrr%r'r=r>r(r?rr)r@r*r�rYr�rBrr�rTrgr�r�r�rr�r�r�rrrrr�s"




	r�)rurr`rcCsPt|�}t�||�}|dkrBtdddtjjd�}t|�}|d|fS||dfSdS)NrzException serializing request!)rrrjr"r=r>rLr�)rurr`r�rvrCrVrrr�_start_unary_request�s
r�)rCr_�	with_callr�rcCs>|jtjjkr2|r*t||d|�}|j|fS|jSnt|��dS)N)r(r=r>r�r�r&r�)rCr_r�r��
rendezvousrrr�_end_unary_response_blocking�s
r�)�metadata�initial_metadata_flagsrcCs*t�||�t�t�t�t�ft�t�ffS)N)r�SendInitialMetadataOperationr�rm�ReceiveStatusOnClientOperation�ReceiveInitialMetadataOperation)r�r�rrr�#_stream_unary_invocation_operations�s

r�cCstdd�t||�D��S)Ncss|]}|dfVqdS)Nr)�.0rwrrr�	<genexpr>sz?_stream_unary_invocation_operations_and_tags.<locals>.<genexpr>)�tupler�)r�r�rrr�,_stream_unary_invocation_operations_and_tags�sr�)�
user_deadlinercCsRt��}|dkr|dkrdS|dk	r0|dkr0|S|dk	rD|dkrD|St||�SdS)N)rZget_deadline_from_context�min)r�Zparent_deadlinerrr�_determine_deadline
sr�c@s�eZdZUejed<eed<eed<eed<ee	ed<ee
ed<eed<dddddddgZejeeeee	ee
d�d	d
�Z
eeeeeeeeejeeeeeejeeeejfd�dd
�Zdeeeeeeejeeeejeeejfd�dd�Zdeeeeeeejeeeejed�dd�Zdeeeeeeejeeeejeeejfd�dd�Zdeeeeeeejeeeejed�dd�Z dS)�_UnaryUnaryMultiCallable�_channel�
_managed_call�_method�_target�_request_serializerr��_context)�channel�managed_callr/r0r`rFcCs2||_||_||_||_||_||_t��|_dS)N)	r�r�r�r�r�r�r�build_census_contextr�)r5r�r�r/r0r`rFrrrr6-s	z!_UnaryUnaryMultiCallable.__init__)rurr��wait_for_ready�compressionrc
Cs�t|||j�\}}}t��|�}	t�||�}
|dkr@ddd|fSttdddd�}t�	|
|	�t�
|t�t�t�t�
t�t�t�t�t�f}|||dfSdS)N)r�r��_InitialMetadataFlags�with_wait_for_readyr�augment_metadatar"�_UNARY_UNARY_INITIAL_DUErr�rlrmrtr�r�r�)
r5rurr�r�r�r�rvr�r��augmented_metadatarCrwrrr�_prepare>s"

z!_UnaryUnaryMultiCallable._prepareN)rurr��credentialsr�r�rc

Cs�|�|||||�\}}}	}
|dkr(|
�n~t��|_t�|j�|_t�|j�|_	|j
�tj
j|jdt|	�||dkrtdn|j|dff|j�}|��}t|||j�||fSdS)N)r�rrPr-rr�r�r/r�r0r��segregated_callr�PropagationConstants�GRPC_PROPAGATE_DEFAULTSr��_credentialsr�r�rRr�)
r5rurr�r�r�r�rCrwr�r�r_rErrr�	_blockingds(	
z"_UnaryUnaryMultiCallable._blockingc	Cs&|�||||||�\}}t||dd�S)NF)r�r�)	r5rurr�r�r�r�rCr_rrr�__call__�sz!_UnaryUnaryMultiCallable.__call__c	Cs&|�||||||�\}}t||dd�S)NT)r�r�)	r5rurr�r�r�r�rCr_rrrr��sz"_UnaryUnaryMultiCallable.with_callc
Cs�|�|||||�\}}}	}
|dkr(|
�ntt||j�}t��|_t�|j�|_	t�|j
�|_|�t
jj|jd|	||dkrzdn|j|f||j�	}t|||j|	�SdS)N)r�r]r�rrPr-rr�r�r/r�r0r�rr�r�r�r�r�)
r5rurr�r�r�r�rCrwr�r�rar_rrr�future�s(	
z_UnaryUnaryMultiCallable.future)NNNNN)NNNNN)NNNNN)NNNNN)!r8r9r:r�Channelr;r�bytesrrrr�	__slots__r6rBrr@r=�Compressionr	r"r�	Operationr�r��CallCredentialsr�r�r��Callr�r�r�rrrrr�sl

& &&&r�c	@s�eZdZUejed<eed<eed<eeed<ee	ed<e
ed<ddddddgZejeeee	d�dd	�Zde
ee
eeeejeeeejed�dd
�Zd
S)�'_SingleThreadedUnaryStreamMultiCallabler�r�r�r�r�r�)r�r/r0r`rFcCs,||_||_||_||_||_t��|_dS)N)r�r�r�r�r�rr�r�)r5r�r/r0r`rFrrrr6�sz0_SingleThreadedUnaryStreamMultiCallable.__init__N)rurr�r�r�r�rc
Cst|�}t�||j�}|dkr:tdddtjjd�}	t|	��tt	dddd�}	|dkrVdn|j
}
t��|�}t
�||�}t�||�t�|t�t�t�ft�t�ft�t�ff}
tdd�|
D��}t��|	_t�|j�|	_t�|j�|	_|j� tj!j"|jdt#|�||
||j$�}t%|	||j&|�S)NrzException serializing request!css|]}|dfVqdS)Nr)r��opsrrrr�szC_SingleThreadedUnaryStreamMultiCallable.__call__.<locals>.<genexpr>)'rrrjr�r"r=r>rLr��_UNARY_STREAM_INITIAL_DUEr�r�r�rr�rr�rlrmrtr�r�r�rrPr-r�r�r/r�r0r�r�r�r�r�r�r�r�)r5rurr�r�r�r�r�rvrCZcall_credentialsr�r�rw�operations_and_tagsr_rrrr��sL	




z0_SingleThreadedUnaryStreamMultiCallable.__call__)NNNNN)r8r9r:rr�r;r�rrrrr�r6rBrr=r�r@r�r�r�rrrrr��s.

&r�c	@s�eZdZUejed<eed<eed<eed<ee	ed<ee
ed<eed<dddddddgZejeeee	e
d�d	d
�Z
deeeeeeejeeeejed�d
d�ZdS)�_UnaryStreamMultiCallabler�r�r�r�r�r�r�)r�r�r/r0r`rFcCs2||_||_||_||_||_||_t��|_dS)N)	r�r�r�r�r�r�rr�r�)r5r�r�r/r0r`rFrrrr6Bs	z"_UnaryStreamMultiCallable.__init__N)rurr�r�r�r�rcCs�t|||j�\}}}	t��|�}
|dkr.|	�n�t�||�}ttdddd�}t�	||
�t�
|t�t�t�t�
t�ft�t�ff}
t��|_t�|j�|_t�|j�|_|�tjj|jdt|�||dkr�dn|j|
t||j�|j�	}t |||j|�SdS)N)!r�r�r�r�rr�r"r�rr�rlrmrtr�r�rrPr-rr�r�r/r�r0r�r�r�r�r�r]r�r�r�)r5rurr�r�r�r�r�rvr�r�r�rCrwr_rrrr�Ss>	


z"_UnaryStreamMultiCallable.__call__)NNNNN)r8r9r:rr�r;rr�rrrrr�r6rBrr=r�r@r�r�r�rrrrr�.s4


&r�c
@sfeZdZUejed<eed<eed<eed<ee	ed<ee
ed<eed<dddddddgZejeeeee	ee
d�d	d
�Z
eeeeeeejeeeejeeejfd�dd
�Zdeeeeeeejeeeejed�dd�Zdeeeeeeejeeeejeeejfd�dd�Zdeeeeeeejeeeejed�dd�ZdS)�_StreamUnaryMultiCallabler�r�r�r�r�r�r�)r�r�r/r0r`rFcCs2||_||_||_||_||_||_t��|_dS)N)	r�r�r�r�r�r�rr�r�)r5r�r�r/r0r`rFrrrr6�s	z"_StreamUnaryMultiCallable.__init__)r^rr�r�r�r�rc
Cs�t|�}ttdddd�}t��|�}	t�||�}
t��|_	t
�|j�|_
t
�|j�|_|j�tjj|jdt|�|
|dkr|dn|jt|
|	�|j�}t||||jd�x>|��}|j�&t|||j�|j��|j s�PWdQRXq�W||fS)N)!rr"�_STREAM_UNARY_INITIAL_DUEr�r�rr�rrPr-rr�r�r/r�r0r�r�rr�r�r�r�r�r�r}r�r�r#rRr�rSr$)
r5r^rr�r�r�r�r�rCr�r�r_rErrrr��s:	

z#_StreamUnaryMultiCallable._blockingNc	Cs&|�||||||�\}}t||dd�S)NF)r�r�)	r5r^rr�r�r�r�rCr_rrrr��s
z"_StreamUnaryMultiCallable.__call__c	Cs&|�||||||�\}}t||dd�S)NT)r�r�)	r5r^rr�r�r�r�rCr_rrrr��s
z#_StreamUnaryMultiCallable.with_callc
Cs�t|�}ttdddd�}t||j�}	t��|�}
t�||�}t	�
�|_t�
|j�|_t�
|j�|_|�tjj|jd|||dkr�dn|jt||
�|	|j�	}t||||j|	�t|||j|�S)N)rr"r�r]r�r�r�rr�rrPr-rr�r�r/r�r0r�rr�r�r�r�r�r}r�r�)
r5r^rr�r�r�r�r�rCrar�r�r_rrrr�s:	
z _StreamUnaryMultiCallable.future)NNNNN)NNNNN)NNNNN)r8r9r:rr�r;rr�rrrrr�r6rrBrr=r�r@r�r	r"r�r�r�r�r�r�r�rrrrr��sZ

'&&&r�c	@s�eZdZUejed<eed<eed<eed<ee	ed<ee
ed<eed<dddddddgZdejeeeee	ee
d	�d
d�Z
deeeeeeejeeeejed�d
d�ZdS)�_StreamStreamMultiCallabler�r�r�r�r�r�r�N)r�r�r/r0r`rFcCs2||_||_||_||_||_||_t��|_dS)N)	r�r�r�r�r�r�rr�r�)r5r�r�r/r0r`rFrrrr6Hs	z#_StreamStreamMultiCallable.__init__)r^rr�r�r�r�rcCs�t|�}ttdddd�}t��|�}	t�||�}
t�|
|	�t�	t
�ft�t
�ff}t||j
�}t��|_t�|j�|_t�|j�|_|�tjj|jdt|�|
|dkr�dn|j|||j�	}
t|||
|j|�t||
|j
|�S)N) rr"�_STREAM_STREAM_INITIAL_DUEr�r�rr�rr�r�rmr�r]r�rrPr-rr�r�r/r�r0r�r�r�r�r�r�r}r�r�)r5r^rr�r�r�r�r�rCr�r�rwrar_rrrr�Ys@	

z#_StreamStreamMultiCallable.__call__)NN)NNNNN)r8r9r:rr�r;rr�rrrrr�r6rrBrr=r�r@r�r�r�rrrrr�4s,


$
&r�cs>eZdZdZefed��fdd�
Zeeed�dd�Z	�Z
S)r�z'Stores immutable initial metadata flags)�valuecs|tjjM}tt|��||�S)N)r�InitialMetadataFlagsZ	used_maskr�r��__new__)�clsr�)r�rrr��sz_InitialMetadataFlags.__new__)r�rcCsJ|dk	rF|r&|�|tjjBtjjB�S|sF|�|tjj@tjjB�S|S)N)r�rr�r�Zwait_for_ready_explicitly_set)r5r�rrrr��sz)_InitialMetadataFlags.with_wait_for_ready)r8r9r:r�rmrAr�rr@r�r�rr)r�rr��sr�c@sNeZdZUejed<eed<eed<ejd�dd�Zdd�d	d
�Z	dd�Z
dS)
�_ChannelCallStater��
managed_callsr1)r�cCs t��|_||_d|_d|_dS)NrF)r1�Lock�lockr�r�)r5r�rrrr6�s
z_ChannelCallState.__init__N)rcCs
d|_dS)Nr)r�)r5rrrr7�sz&_ChannelCallState.reset_postfork_childc	Cs4y|j�tjjd�Wnttfk
r.YnXdS)NzChannel deallocated!)r��closerr>r*�	TypeError�AttributeError)r5rrrr��s
z_ChannelCallState.__del__)r8r9r:rr�r;rAr@r6r7r�rrrrr��s

r�)rCrcs.�fdd�}tj|d�}|�d�|��dS)Nc	sjxdt����j��}|jtjjkr&q|�|�}|r�j�"�j	d8_	�j	dkrXdSWdQRXqWdS)N�r)
rrrr�Znext_call_event�completion_typeZCompletionTypeZ
queue_timeout�tagr�r�)rEZcall_completed)rCrr�channel_spin�s



z._run_channel_spin_thread.<locals>.channel_spin)r0T)rrzr{r|)rCrZchannel_spin_threadr)rCr�_run_channel_spin_thread�s

r)rCc
sDttttttttttjtttj	t
tjd�	�fdd�}|S)N)	�flagsr/�hostr�r�r�rwrarc	snt�fdd�|D��}	�j�H�j�|||||||	|�}
�jdkrRd�_t��n�jd7_|
SQRXdS)a$Creates a cygrpc.IntegratedCall.

        Args:
          flags: An integer bitfield of call flags.
          method: The RPC method.
          host: A host string for the created call.
          deadline: A float to be the deadline of the created call or None if
            the call is to have an infinite deadline.
          metadata: The metadata for the call or None.
          credentials: A cygrpc.CallCredentials or None.
          operations: A sequence of sequences of cygrpc.Operations to be
            started on the call.
          event_handler: A behavior to call to handle the events resultant from
            the operations on the call.
          context: Context object for distributed tracing.
        Returns:
          A cygrpc.IntegratedCall with which to conduct an RPC.
        c3s|]}|�fVqdS)Nr)r�Z	operation)rarrr��szC_channel_managed_call_management.<locals>.create.<locals>.<genexpr>rrN)r�r�r�Zintegrated_callr�r)rr/rr�r�r�rwra�contextr�r_)rC)rar�create�s$



z0_channel_managed_call_management.<locals>.create)rAr�rr?rBrrr�rr�rr�)rCr	r)rCr� _channel_managed_call_management�s,r
c@s�eZdZUejed<ejed<eed<ej	ed<eed<e
eee
ej	gdfeej	fed<eed<ejd	�d
d�Zdd�d
d�ZdS)�_ChannelConnectivityStater�r��polling�connectivity�try_to_connectN�callbacks_and_connectivities�
delivering)r�cCs2t��|_||_d|_d|_d|_g|_d|_dS)NF)	r1�RLockr�r�rr
rrr)r5r�rrrr6s
z"_ChannelConnectivityState.__init__)rcCs"d|_d|_d|_g|_d|_dS)NF)rr
rrr)r5rrrr7$s
z._ChannelConnectivityState.reset_postfork_child)r8r9r:r1rr;r=r�r@�ChannelConnectivityrrr
rrr6r7rrrrr
s



	rcCs>g}x4|jD]*}|\}}||jk	r|�|�|j|d<qW|S)Nr)rr
r�)rCZcallbacks_needing_update�callback_and_connectivityrZZcallback_connectivityrrr�_deliveries,s

r)rC�initial_connectivity�initial_callbacksrc	Cs�|}|}xxxB|D]:}t�|�y||�Wqtk
rHt�t�YqXqW|j�$t|�}|rj|j}n
d|_	dSWdQRXq
WdS)NF)
rrrrTrfrg�0_CHANNEL_SUBSCRIPTION_CALLBACK_ERROR_LOG_MESSAGEr�rr
r)rCrrr
r+rZrrr�_deliver;s 

r)rCr+rcCs2tjt||j|fd�}|�d�|��d|_dS)N)r0�argsT)rrzrr
r{r|r)rCr+Zdelivering_threadrrr�_spawn_deliveryTs

r)rCr��initial_try_to_connectrc	Cs|}|�|�}|j�Ntj||_tdd�|jD��}x|jD]}|j|d<q>W|r^t||�WdQRXx�|�|t	�	�d�}t
�|�|j�,|js�|js�d|_
d|_P|j}d|_WdQRX|js�|rj|�|�}|j�2tj||_|j�st|�}|�rt||�WdQRXqjWdS)Ncss|]\}}|VqdS)Nr)r�rZ�_rrrr�tsz%_poll_connectivity.<locals>.<genexpr>rg�������?F)Zcheck_connectivity_stater�rZ1CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITYr
r�rrZwatch_connectivity_staterrrrrr�successrr)rCr�rrr
r+rrErrr�_poll_connectivityfs@



r)rCrZrrc	Cs�|j��|jsX|jsXtjt||jt|�fd�}|�d�|�	�d|_|j�
|dg�nd|js�|jdk	r�t
||f�|jt|�O_|j�
||jg�n"|jt|�O_|j�
|dg�WdQRXdS)N)r0rT)r�rrrrzrr�r@r{r|r�rr
rr)rCrZrZpolling_threadrrr�
_subscribe�s 
r)rCrZrc	CsH|j�8x0t|j�D]"\}\}}||kr|j�|�PqWWdQRXdS)N)r��	enumerater�pop)rCrZ�indexZsubscribed_callbackZunused_connectivityrrr�_unsubscribe�sr#)�base_optionsr�rcCs$t�|�}t|�|tjjtffS)N)rZcreate_channel_optionr�rZ
ChannelArgKeyZprimary_user_agent_string�_USER_AGENT)r$r�Zcompression_optionrrr�_augment_options�s

r&)�optionsrcCsFg}g}x4|D],}|dtjjjkr0|�|�q|�|�qW||fS)z;Separates core channel options from Python channel options.r)r=r��ChannelOptions�SingleThreadedUnaryStreamr�)r'�core_options�python_options�pairrrr�_separate_channel_options�s
r-c@s�eZdZUdZeed<ejed<eed<e	ed<e
ed<e
eee
eje
ejd�dd	�Zeed
d�dd
�Zd,eejgd
fe
ed
d�dd�Zeejgd
fd
d�dd�Zd-e
e
ee
eejd�dd�Zd.e
e
ee
eejd�dd�Zd/e
e
ee
eejd�dd�Zd0e
e
ee
eejd�dd�Z d
d�dd�Z!d
d�d d!�Z"d
d�d"d#�Z#d$d%�Z$d&d'�Z%d
d�d(d)�Z&d*d+�Z'd
S)1r�z7A cygrpc.Channel-backed implementation of grpc.Channel.�_single_threaded_unary_streamr��_call_state�_connectivity_stater�)r0r'r�r�cCsrt|�\}}t|_|�|�t�t�|�t||�|�|_	||_
t|j	�|_t
|j	�|_t�|�tjrnt��dS)aPConstructor.

        Args:
          target: The target to which to connect.
          options: Configuration options for the channel.
          credentials: A cygrpc.ChannelCredentials or None.
          compression: An optional value indicating the compression method to be
            used over the lifetime of the channel.
        N)r-�%_DEFAULT_SINGLE_THREADED_UNARY_STREAMr.�_process_python_optionsrr�r�encoder&r�r�r�r/rr0Zfork_register_channel�g_gevent_activatedZgevent_increment_channel_count)r5r0r'r�r�r+r*rrrr6�s

zChannel.__init__N)r+rcCs*x$|D]}|dtjjjkrd|_qWdS)zASets channel attributes according to python-only channel options.rTN)r=r�r(r)r.)r5r+r,rrrr2
s
zChannel._process_python_options)rZrrcCst|j||�dS)N)rr0)r5rZrrrr�	subscribeszChannel.subscribe)rZrcCst|j|�dS)N)r#r0)r5rZrrr�unsubscribeszChannel.unsubscribe)r/r`rFrcCs(t|jt|j�t�|�t�|j�||�S)N)r�r�r
r/rr3r�)r5r/r`rFrrr�unary_unary!s
zChannel.unary_unarycCsR|jr&t|jt�|�t�|j�||�St|jt|j�t�|�t�|j�||�SdS)N)	r.r�r�rr3r�r�r
r/)r5r/r`rFrrr�unary_stream0s


zChannel.unary_streamcCs(t|jt|j�t�|�t�|j�||�S)N)r�r�r
r/rr3r�)r5r/r`rFrrr�stream_unaryLs
zChannel.stream_unarycCs(t|jt|j�t�|�t�|j�||�S)N)r�r�r
r/rr3r�)r5r/r`rFrrr�
stream_stream[s
zChannel.stream_stream)rc	Cs,|j}|r(|j�|jdd�=WdQRXdS)N)r0r�r)r5rCrrr�_unsubscribe_alljszChannel._unsubscribe_allcCs6|��|j�tjjd�t�|�tjr2t��dS)NzChannel closed!)	r;r�r�rr>r*Zfork_unregister_channelr4Zgevent_decrement_channel_count)r5rrr�_closeps

zChannel._closecCs|��|j�tjjd�dS)NzChannel closed due to fork)r;r�Z
close_on_forkrr>r*)r5rrr�_close_on_forkwszChannel._close_on_forkcCs|S)Nr)r5rrr�	__enter__}szChannel.__enter__cCs|��dS)NF)r<)r5�exc_type�exc_val�exc_tbrrr�__exit__�szChannel.__exit__cCs|��dS)N)r<)r5rrrr��sz
Channel.closecCsy|��WnYnXdS)N)r;)r5rrrr��s
zChannel.__del__)N)NN)NN)NN)NN)(r8r9r:r�r@r;rr�r�rr?rrrr=ZChannelCredentialsr�r6r2rrr5r6rr�UnaryUnaryMultiCallabler7�UnaryStreamMultiCallabler8�StreamUnaryMultiCallabler9�StreamStreamMultiCallabler:r;r<r=r>rBr�r�rrrrr��sF




r�)tr�r�rprU�osr�r1rr��typingrrrrrrrr	r
r=rrr
rZgrpc._cythonrZgrpc._typingrrrrrrrrZgrpc.experimental�	getLoggerr8rfr �__version__r%rm�getenvr1r<Zsend_initial_metadatarbrsrIrJrMr�r�r�r�rr�r�rBrr>r?r!�objectr"rDr�rRr]r�r�r}r�r�r�r�r�Z
RpcContextr�r�r�r�r�r@r�rAr�r�r�r�rCr�rDr�r�rEr�rFr�r�r�rr
rrrrrr�rrr#r�r&r-rrrr�<module>s�,




=
)Y^k
V
:& $6`[,Z;#.