
    s                         S SK r S SKJrJrJrJr  S SKJrJr  S SK	J
r
  \" S5      rS\S\4S jr " S	 S
5      r " S S5      rg)    N)	AwaitableTypeVarOptionalCallable)GoogleAPICallErrorUnknown)wait_ignore_errorsTereturnc                 F    [        U [        5      (       a  U $ [        SU /S9$ )NzHad an unknown error)errors)
isinstancer   r   )r   s    Klib/third_party/google/cloud/pubsublite/internal/wire/permanent_failable.pyadapt_errorr      s%    !'(()1#66    c                   .    \ rS rSrS\4S jrS rS rSrg)_TaskWithCleanup   ac                 :    [         R                  " U5      U l        g N)asyncioensure_future_task)selfr   s     r   __init___TaskWithCleanup.__init__    s    **1-
r   c                 "   #    U R                   $ 7fr   r   r   s    r   
__aenter___TaskWithCleanup.__aenter__#   s     zzs   c                    #    U R                   R                  5       (       d8  U R                   R                  5         [        U R                   5      I S h  vN   g g  N7fr   )r   donecancelr	   )r   exc_typeexc_valexc_tbs       r   	__aexit___TaskWithCleanup.__aexit__&   s@     zz  JJ$TZZ000 !0s   AAAAr    N)	__name__
__module____qualname____firstlineno__r   r   r"   r*   __static_attributes__ r   r   r   r      s    .) .1r   r   c                       \ rS rSr% Sr\\R                     \S'   S r	\
S\R                  4S j5       rS\\   S\4S jrS	\/ \S
   4   4S jrS\4S jrS\\   4S jrSrg
)PermanentFailable,   zdA class that can experience permanent failures, with helpers for forwarding these to client actions._maybe_failure_taskc                     S U l         g r   r5   r!   s    r   r   PermanentFailable.__init__1   s
    #' r   r   c                 h    U R                   c  [        R                  " 5       U l         U R                   $ )zaGet the failure task, initializing it lazily, since it needs to be initialized in the event loop.)r5   r   Futurer!   s    r   _failure_taskPermanentFailable._failure_task4   s+     ##+'.~~'7D$'''r   	awaitablec                   #    [        U5       ISh  vN nU R                  R                  5       (       a  U R                  R                  5       e[        R
                  " X R                  /[        R                  S9I Sh  vN u  p4X#;   a  UI Sh  vN sSSS5      ISh  vN   $ U R                  R                  5       e N NB N3 N%! , ISh  vN  (       d  f       g= f7f)z
Await the awaitable, unless fail() is called first.
Args:
  awaitable: An awaitable

Returns: The result of the awaitable
Raises: The permanent error if fail() is called or the awaitable raises one.
N)return_when)r   r;   r%   	exceptionr   waitFIRST_COMPLETED)r   r=   taskr%   _s        r   await_unless_failed%PermanentFailable.await_unless_failed;   s      $I..$!!&&((((2244#LL))*8O8O GD |!z /.. $$..00 / " /...su   C$CC$A+C
CC
CC
C$"C#C$(C
C$C
C
C$
C!CC!C$poll_actionNc                    #      U R                  U" 5       5      I Sh  vN   M    N! [        R                   a     g[         a$  nU R	                  [        U5      5         SnAgSnAff = f7f)z
Run a polling loop, which runs poll_action forever unless this is failed.
Args:
  poll_action: A callable returning an awaitable to run in a loop. Note that async functions which return once
  satisfy this.
N)rE   r   CancelledError	Exceptionfailr   )r   rG   r   s      r   
run_pollerPermanentFailable.run_pollerN   s^     	&..{}=== =%% 	 	&IIk!n%%	&s8   A-' %' A*A-	A*A% A-%A**A-errc                     U R                   R                  5       (       d6  U R                   R                  U5        U R                   R                  5         g g r   )r;   r%   set_exceptionr@   )r   rN   s     r   rK   PermanentFailable.fail]   sD    !!&&((,,S1 ((*	 )r   c                 v    U R                   R                  5       (       d  g U R                   R                  5       $ r   )r;   r%   r@   r!   s    r   errorPermanentFailable.errord   s/    !!&&((!!++--r   r7   )r,   r-   r.   r/   __doc__r   r   r:   __annotations__r   propertyr;   r   r
   rE   r   rL   r   rK   rS   r0   r1   r   r   r3   r3   ,   s    n!'..11( (w~~ ( (19Q< 1A 1&&HR45H,I &+* +.x 23 .r   r3   )r   typingr   r   r   r   google.api_core.exceptionsr   r   6google.cloud.pubsublite.internal.wait_ignore_cancelledr	   r
   rJ   r   r   r3   r1   r   r   <module>r[      sG     9 9 B UCL79 7!3 7
1 
1;. ;.r   