3 \> @sddddddgZddlZddlZddlZddlZdd lmZdd lmZdd lm Z ej Z ej Z ej Z ej Z ejZejZejZejdZGd d d ZGdddZeZddZddZddZddZddddZy ddlZWnek rYn XejZZdS)CancelledError TimeoutErrorInvalidStateErrorFuture wrap_futureisfutureN) base_futures)compat)eventsc@s0eZdZdZddZddZd d Zd d Zd S)_TracebackLoggerloopsource_tracebackexctbcCs |j|_|j|_||_d|_dS)N)_loopr _source_tracebackrrr)selffuturerr'/usr/lib64/python3.6/asyncio/futures.py__init__Rsz_TracebackLogger.__init__cCs,|j}|dk r(d|_tj|j||j|_dS)N)r tracebackformat_exception __class__ __traceback__r)rrrrractivateXs  z_TracebackLogger.activatecCsd|_d|_dS)N)rr)rrrrclear_sz_TracebackLogger.clearcCsb|jr^d}|jr:djtj|j}|d7}|d|j7}|dj|jj7}|jjd|idS)Nz*Future/Task exception was never retrieved z0Future/Task created at (most recent call last): z%s message)rrjoinr format_listrstripr call_exception_handler)rmsgsrcrrr__del__csz_TracebackLogger.__del__N)r rrr)__name__ __module__ __qualname__ __slots__rrrr&rrrrr s 2r c@seZdZeZdZdZdZdZdZ dZ ddddZ e j ZddZejrNdd Zd d Zd d ZddZddZddZddZddZddZddZddZddZejreZdS) rNF)r cCs@|dkrtj|_n||_g|_|jjr )rr'r _repr_info)rrrr__repr__szFuture.__repr__cCsD|js dS|j}d|jj||d}|jr4|j|d<|jj|dS)Nz %s exception was never retrieved)r exceptionrr)_log_traceback _exceptionrr'rrr#)rrcontextrrrr&s zFuture.__del__cCs&d|_|jtkrdSt|_|jdS)NFT)r4_state_PENDING _CANCELLED_schedule_callbacks)rrrrcancels  z Future.cancelcCsD|jdd}|sdSg|jdd<x|D]}|jj||q*WdS)N)r,r call_soon)rZ callbackscallbackrrrr:s  zFuture._schedule_callbackscCs |jtkS)N)r7r9)rrrr cancelledszFuture.cancelledcCs |jtkS)N)r7r8)rrrrdonesz Future.donecCs<|jtkrt|jtkr tdd|_|jdk r6|j|jS)NzResult is not ready.F)r7r9r _FINISHEDrr4r5_result)rrrrresults   z Future.resultcCs,|jtkrt|jtkr tdd|_|jS)NzException is not set.F)r7r9rr@rr4r5)rrrrr3s   zFuture.exceptioncCs*|jtkr|jj||n |jj|dS)N)r7r8rr<r,append)rfnrrradd_done_callbacks zFuture.add_done_callbackcs<fdd|jD}t|jt|}|r8||jdd<|S)Ncsg|]}|kr|qSrr).0f)rDrr sz/Future.remove_done_callback..)r,len)rrDZfiltered_callbacksZ removed_countr)rDrremove_done_callbacks zFuture.remove_done_callbackcCs4|jtkrtdj|j|||_t|_|jdS)Nz{}: {!r})r7r8rformatrAr@r:)rrBrrr set_result s  zFuture.set_resultcCs|jtkrtdj|j|t|tr,|}t|tkr@td||_t |_|j t j rbd|_ nt|||_|jj|jjdS)Nz{}: {!r}zPStopIteration interacts badly with generators and cannot be raised into a FutureT)r7r8rrK isinstancetype StopIteration TypeErrorr5r@r:r PY34r4r Z _tb_loggerrr<r)rr3rrr set_exception,s    zFuture.set_exceptionccs|jsd|_|V|jS)NT)r?_asyncio_future_blockingrB)rrrr__iter__DszFuture.__iter__) r'r(r)r8r7rAr5rrrSr4rr Z_future_repr_infor1r2r rQr&r;r:r>r?rBr3rErJrLrRrTZPY35 __await__rrrrrns2   cCs|jr dS|j|dS)N)r>rL)ZfutrBrrr_set_result_unless_cancelledSsrVcCsN|jr|j|jsdS|j}|dk r8|j|n|j}|j|dS)N)r>r;Zset_running_or_notify_cancelr3rRrBrL) concurrentsourcer3rBrrr_set_concurrent_future_stateZs rYcCsP|jr dS|jr|jn.|j}|dk r:|j|n|j}|j|dS)N)r>r;r3rRrBrL)rXdestr3rBrrr_copy_future_stateis  r[cst r"ttjj r"tdt rDttjj rDtdtrRjndtrdjndddfdd}fdd}j|j|dS) Nz(A future is required for source argumentz-A future is required for destination argumentcSs"t|rt||n t||dS)N)rr[rY)rotherrrr _set_states z!_chain_future.._set_statecs2|jr.dkskr"jn jjdS)N)r>r;call_soon_threadsafe) destination) dest_looprX source_looprr_call_check_cancels z)_chain_future.._call_check_cancelcsJjrdk rjrdSdks,kr8|nj|dS)N)r>Z is_closedr^)rX)r]r`r_rarr_call_set_states  z&_chain_future.._call_set_state)rrMrWZfuturesrrPrrE)rXr_rbrcr)r]r`r_rXrar _chain_future}s   rd)r cCs2t|r |S|dkrtj}|j}t|||S)N)rr r+Z create_futurerd)rr Z new_futurerrrrs )__all__Zconcurrent.futuresrWZloggingr.rrr r r rrrrr8r9r@DEBUGZ STACK_DEBUGr rZ _PyFuturerVrYr[rdrZ_asyncio ImportErrorZ_CFuturerrrrs<     Pc*