U vi,@sddlmZddlZddlZddlmZmZmZmZm Z m Z m Z m Z ddl mZddlmZddlmZddlmZdd lmZe d Ze d Ze d Ze d Ze dZe dZe dZe dddZGdddejeZ dgZ!dS)) annotationsN)AnyCallable GeneratorOptionalTypeVarUnioncastoverload)abc) Disposable)CurrentThreadScheduler)AsyncIOScheduler)AutoDetachObserver_A_B_C_D_E_F_G_T_outT) covariantc sneZdZdZdGdddfdd ZdHdd d d d d ZdIdddddd d dddZedddddZeddddddZeddddd d!dZedddd"d#d$d%dZedddd"d&d'd(d)dZedddd"d&d*d+d,d-dZedddd"d&d*d.d/d0d1dZd2d3d4d5dZd3d6d7d8Z d9d6d:d;Z dd?Z d` into :mod:`operators `.Nz"Optional[abc.Subscription[_T_out]]None) subscribereturncstt|_||_dS)zCreates an observable sequence object from the specified subscription function. Args: subscribe: [Optional] Subscription function N)super__init__ threadingRLocklock _subscribe)selfr __class__P/opt/alt/python38/lib/python3.8/site-packages/reactivex/observable/observable.pyr s  zObservable.__init__zabc.ObserverBase[_T_out]Optional[abc.SchedulerBase]abc.DisposableBase)observer schedulerrcCs|jr|||StSN)r#r )r$r+r,r'r'r(_subscribe_core,szObservable._subscribe_corer,zCOptional[Union[abc.ObserverBase[_T_out], abc.OnNext[_T_out], None]]zOptional[abc.OnError]zOptional[abc.OnCompleted])on_nexton_error on_completedr,rcst|tjs$t|drFtt|drFttjt|}|j}|j }|j }t |||dddddddd d d fd d }t }|r||n|tjS)aSubscribe an observer to the observable sequence. You may subscribe using an observer or callbacks, not both; if the first argument is an instance of :class:`Observer <..abc.ObserverBase>` or if it has a (callable) attribute named :code:`on_next`, then any callback arguments will be ignored. Examples: >>> source.subscribe() >>> source.subscribe(observer) >>> source.subscribe(observer, scheduler=scheduler) >>> source.subscribe(on_next) >>> source.subscribe(on_next, on_error) >>> source.subscribe(on_next, on_error, on_completed) >>> source.subscribe(on_next, on_error, on_completed, scheduler=scheduler) Args: observer: [Optional] The object that is to receive notifications. on_error: [Optional] Action to invoke upon exceptional termination of the observable sequence. on_completed: [Optional] Action to invoke upon graceful termination of the observable sequence. on_next: [Optional] Action to invoke for each element in the observable sequence. scheduler: [Optional] The default scheduler to use for this subscription. Returns: Disposable object representing an observer's subscription to the observable sequence. r0z-Union[abc.DisposableBase, Callable[[], None]]r*) subscriberrcSs*t|tjst|dr"ttj|St|S)zgFixes subscriber to make sure it returns a Disposable instead of None or a dispose functiondispose) isinstancer ZDisposableBasehasattrr r )r3r'r'r(fix_subscriberks  z,Observable.subscribe..fix_subscriberNr)rr)___rc sNz}Wn.tk r>}z|s.W5d}~XYn X|_dSr-)r. ExceptionZfailZ subscription)r8r9r3exZauto_detach_observerr7r,r$r'r(set_disposableys  z,Observable.subscribe..set_disposable)NN)r5r Z ObserverBaser6callablegetattrr rr0r1r2rr Z singletonZschedule_requiredZscheduler r4)r$r0r1r2r,Zobvr=Zcurrent_thread_schedulerr'r<r(r3s0+   zObservable.subscribez"Callable[[Observable[_T_out]], _A]r)_Observable__op1rcCsdSr-r')r$r@r'r'r(pipeszObservable.pipezCallable[[_A], _B]r)r@_Observable__op2rcCsdSr-r')r$r@rBr'r'r(rAszCallable[[_B], _C]r)r@rB_Observable__op3rcCsdSr-r')r$r@rBrCr'r'r(rAszCallable[[_C], _D]r)r@rBrC_Observable__op4rcCsdSr-r')r$r@rBrCrDr'r'r(rAszCallable[[_D], _E]r)r@rBrCrD_Observable__op5rcCsdSr-r')r$r@rBrCrDrEr'r'r(rAszCallable[[_E], _F]r)r@rBrCrDrE_Observable__op6rcCsdSr-r')r$r@rBrCrDrErFr'r'r(rAs zCallable[[_F], _G]r)r@rBrCrDrErF_Observable__op7rcCsdSr-r')r$r@rBrCrDrErFrGr'r'r(rAs zCallable[[Any], Any]r) operatorsrcGsddlm}||f|S)a?Compose multiple operators left to right. Composes zero or more operators into a functional composition. The operators are composed from left to right. A composition of zero operators gives back the original source. Examples: >>> source.pipe() == source >>> source.pipe(f) == f(source) >>> source.pipe(g, f) == f(g(source)) >>> source.pipe(h, g, f) == f(g(h(source))) Args: operators: Sequence of operators. Returns: The composed observable. rrArI)r$rHZpipe_r'r'r(rAs )rcCsddlm}||S)a]Run source synchronously. Subscribes to the observable source. Then blocks and waits for the observable source to either complete or error. Returns the last value emitted, or throws exception if any error occurred. Examples: >>> result = run(source) Raises: SequenceContainsNoElementsError: if observable completes (on_completed) without any values being emitted. Exception: raises exception if any error (on_error) occurred. Returns: The last element emitted from the observable. rrunrJ)r$rKr'r'r(rKs zObservable.runzGenerator[Any, None, _T_out]cCs2ddlm}t}||t|dd}|S)zmAwaits the given observable. Returns: The last item of the observable sequence. r) to_future_)loopr/)Zoperators._tofuturerLasyncioget_event_looprAr __await__)r$rLrMfuturer'r'r(rPs  zObservable.__await__zObservable[_T_out])otherrcCsddlm}|||S)aPythonic version of :func:`concat `. Example: >>> zs = xs + ys Args: other: The second observable sequence in the concatenation. Returns: Concatenated observable sequence. rconcat reactivexrTr$rRrTr'r'r(__add__ s zObservable.__add__z'Observable[_T_out]'cCsddlm}|||S)zPythonic use of :func:`concat `. Example: >>> xs += ys Args: other: The second observable sequence in the concatenation. Returns: Concatenated observable sequence. rrSrUrWr'r'r(__iadd__s zObservable.__iadd__zUnion[slice, int])keyrcCsRt|tr"|j|j|j}}}n||dd}}}ddlm}|||||S)a$ Pythonic version of :func:`slice `. Slices the given observable using Python slice notation. The arguments to slice are `start`, `stop` and `step` given within brackets `[]` and separated by the colons `:`. It is basically a wrapper around the operators :func:`skip `, :func:`skip_last `, :func:`take `, :func:`take_last ` and :func:`filter `. The following diagram helps you remember how slices works with streams. Positive numbers are relative to the start of the events, while negative numbers are relative to the end (close) of the stream. .. code:: r---e---a---c---t---i---v---e---! 0 1 2 3 4 5 6 7 8 -8 -7 -6 -5 -4 -3 -2 -1 0 Examples: >>> result = source[1:10] >>> result = source[1:-2] >>> result = source[1:-1:2] Args: key: Slice object Returns: Sliced observable sequence. Raises: TypeError: If key is not of type :code:`int` or :code:`slice` r)slice_)r5slicestartstopstepZoperators._slicer\)r$rZr^r_r`r\r'r'r( __getitem__,s (  zObservable.__getitem__)N)N)NNN)__name__ __module__ __qualname____doc__rr.rr rArKrPrXrYra __classcell__r'r'r%r(rs< b   r)" __future__rrNr typingrrrrrrr r rVr Zreactivex.disposabler Zreactivex.schedulerr Zreactivex.scheduler.eventlooprr+rrrrrrrrrZObservableBaser__all__r'r'r'r(s( (      F