
                             S SK JrJrJrJrJrJrJr  S SKrS SK	J
r
Jr  S SKJrJrJrJr  S SKJr  S SKJr  \" S5      r " S S	\\\4   \\   \5      r " S
 S\\\4   5      rg)    )castAsyncIteratorTypeVarOptionalCallableAsyncIterable	AwaitableN)GoogleAPICallErrorFailedPrecondition)
ConnectionRequestResponseConnectionFactory)WorkItem)PermanentFailableTc                      ^  \ rS rSr% SrS\S'   \\\      \S'   U 4S jr	S\\   4S jr
S	\S
S4S jrS
\4S jrS rSS jrS
\4S jrS
\\   4S jrSrU =r$ )GapicConnection(   zCA Connection wrapping a gapic AsyncIterator[Request/Response] pair.z&asyncio.Queue[WorkItem[Request, None]]_write_queue_response_itc                 T   > [         TU ]  5         [        R                  " SS9U l        g )N   )maxsize)super__init__asyncioQueuer   )self	__class__s    Ilib/third_party/google/cloud/pubsublite/internal/wire/gapic_connection.pyr   GapicConnection.__init__0   s    #MM!4    response_itc                     Xl         g N)r   )r   r$   s     r!   set_response_itGapicConnection.set_response_it4   s    'r#   requestreturnNc                    #    [        U5      nU R                  U R                  R                  U5      5      I S h  vN   U R                  UR                  5      I S h  vN   g  N( N7fr&   )r   await_unless_failedr   putresponse_future)r   r)   items      r!   writeGapicConnection.write7   sW      &&t'8'8'<'<T'BCCC&&t';';<<< 	D<s!   9A(A$"A(A&A(&A(c                   #    U R                   c*  U R                  [        S5      5        U R                  5       e [	        [
        [           U R                   5      nU R                  UR                  5       5      I S h  vN $  N! [         a,    U R                  [        S5      5         U R                  5       e[         a*  nU R                  U5         S nAU R                  5       eS nAff = f7f)Nz GapicConnection not initialized.z"Server sent unprompted half close.)r   failr   errorr   r   r   r,   	__anext__StopAsyncIterationr
   )r   r$   es      r!   readGapicConnection.read<   s     $II()KLM**,	}X68I8IJK11+2G2G2IJJJJ! 	PII()MNO jjl " 	IIaLLjjl	sM   8C0AB >B?B C0B $C-)C0:	C-C(C0(C--C0c                    #    U $ 7fr&    r   s    r!   
__aenter__GapicConnection.__aenter__I   s
     s   c                    #    g 7fr&   r;   )r   exc_type	exc_value	tracebacks       r!   	__aexit__GapicConnection.__aexit__L   s     s   c                    #    U R                  U R                  R                  5       5      I S h  vN nUR                  R	                  S 5        UR
                  $  N+7fr&   )r,   r   getr.   
set_resultr)   )r   r/   s     r!   r5   GapicConnection.__anext__O   sQ     .2.F.F!!#/
 )
 	''-||	)
s   -AA,Ac                     U $ r&   r;   r<   s    r!   	__aiter__GapicConnection.__aiter__V   s    r#   )r   r   )r*   N)__name__
__module____qualname____firstlineno____doc____annotations__r   r   r   r   r'   r   r0   r8   r=   rC   r5   rJ   __static_attributes____classcell__)r    s   @r!   r   r   (   s     N::=2335(=+B (=7 =t =
H  =2  r#   r   c                   ~    \ rS rSrSr\\\   /\\	\
      4   rS\\\   /\\	\
      4   4S jrS\\\
4   4S jrSrg)	GapicConnectionFactoryZ   z3A ConnectionFactory that produces GapicConnections.producerc                     Xl         g r&   	_producer)r   rW   s     r!   r   GapicConnectionFactory.__init___   s	     "r#   r*   c                    #    [         [        [        4   " 5       nU R                  U5      nUI S h  vN nUR	                  UR                  5       5        U$  N%7fr&   )r   r   r   rZ   r'   rJ   )r   connresponse_futresponse_iterables       r!   newGapicConnectionFactory.newg   sP     w013~~d+"...88:; /s   /AA&ArY   N)rL   rM   rN   rO   rP   r   r   r   r	   r   r   rZ   r   r   r`   rR   r;   r#   r!   rU   rU   Z   sh    =-019]8=T3UUVI"7#$ih0G&HH
":gx&78 r#   rU   )typingr   r   r   r   r   r   r	   r   google.api_core.exceptionsr
   r   0google.cloud.pubsublite.internal.wire.connectionr   r   r   r   /google.cloud.pubsublite.internal.wire.work_itemr   8google.cloud.pubsublite.internal.wire.permanent_failabler   r   r   rU   r;   r#   r!   <module>rg      sq       M  E VCL/w !=#9;L/d.w/@A r#   