asda?‰PNG  IHDR ? f ??C1 sRGB ??é gAMA ±? üa pHYs ? ??o¨d GIDATx^íüL”÷e÷Y?a?("Bh?_ò???¢§?q5k?*:t0A-o??¥]VkJ¢M??f?±8\k2íll£1]q?ù???T a d6@sdZdZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl m Z dd l m Z e jZe jZe jZe jZejdZGd d d ZeZd d ZddZddZddZddZddZddddZz ddlZWneyYn 0ejZZdS)z.A Future class similar to the one in PEP 3148.)Future wrap_futureisfutureN) GenericAlias) base_futures)events) exceptions)format_helpersc@seZdZdZeZdZdZdZdZ dZ dZ dZ dZ ddddZejZddZd d ZeeZed d Zejd d ZddZddZd)ddZddZddZddZddZ ddZ!dddd Z"d!d"Z#d#d$Z$d%d&Z%d'd(Z&e&Z'dS)*ra,This class is *almost* compatible with concurrent.futures.Future. Differences: - This class is not thread-safe. - result() and exception() do not take a timeout argument and raise an exception when the future isn't done yet. - Callbacks registered with add_done_callback() are always called via the event loop's call_soon(). - This class is not compatible with the wait() and as_completed() methods in the concurrent.futures package. (In Python 3.4 or later we may be able to unify the implementations.) NFloopcCs@|durt|_n||_g|_|jr )format __class____name__join _repr_inforrrr__repr__Zs  zFuture.__repr__cCsF|js dS|j}|jjd||d}|jr6|j|d<|j|dS)Nz exception was never retrieved)message exceptionfuturesource_traceback)_Future__log_traceback _exceptionrrrrcall_exception_handler)rexccontextrrr__del__^s  zFuture.__del__cCs|jSN)r&r rrr_log_tracebackpszFuture._log_tracebackcCst|rtdd|_dS)Nz'_log_traceback can only be set to FalseF)bool ValueErrorr&)rvalrrrr-tscCs|j}|durtd|S)z-Return the event loop the Future is bound to.Nz!Future object is not initialized.)r RuntimeErrorrrrrget_loopzszFuture.get_loopcCs2|jdurt}n t|j}|j|_d|_|S)zCreate the CancelledError to raise if the Future is cancelled. This should only be called once when handling a cancellation since it erases the saved context exception value. N)_cancel_messager CancelledError_cancelled_exc __context__rr)rrr_make_cancelled_errors    zFuture._make_cancelled_errorcCs,d|_|jtkrdSt|_||_|dS)zCancel the future and schedule callbacks. If the future is already done or cancelled, return False. Otherwise, change the future's state to cancelled, schedule the callbacks and return True. FT)r&_state_PENDING _CANCELLEDr3_Future__schedule_callbacks)rmsgrrrcancels z Future.cancelcCsH|jdd}|sdSg|jdd<|D]\}}|jj|||dq(dS)zInternal: Ask the event loop to call all callbacks. The callbacks are scheduled to be called as soon as possible. Also clears the callback list. Nr*)rr call_soon)rZ callbackscallbackctxrrrZ__schedule_callbackss  zFuture.__schedule_callbackscCs |jtkS)z(Return True if the future was cancelled.)r9r;r rrr cancelledszFuture.cancelledcCs |jtkS)zReturn True if the future is done. Done means either that a result / exception are available, or that the future was cancelled. )r9r:r rrrdonesz Future.donecCsF|jtkr|}||jtkr*tdd|_|jdur@|j|jS)aReturn the result this future represents. If the future has been cancelled, raises CancelledError. If the future's result isn't yet available, raises InvalidStateError. If the future is done and has an exception set, this exception is raised. zResult is not ready.FN) r9r;r8 _FINISHEDr InvalidStateErrorr&r'_resultr7rrrresults    z Future.resultcCs6|jtkr|}||jtkr*tdd|_|jS)a&Return the exception that was set on this future. The exception (or None if no exception was set) is returned only if the future is done. If the future has been cancelled, raises CancelledError. If the future isn't done yet, raises InvalidStateError. zException is not set.F)r9r;r8rEr rFr&r'r7rrrr#s   zFuture.exceptionr?cCsB|jtkr|jj|||dn |dur.t}|j||fdS)zAdd a callback to be run when the future becomes done. The callback is called with a single argument - the future object. If the future is already done when this is called, the callback is scheduled with call_soon. r?N)r9r:rr@ contextvars copy_contextrappend)rfnr*rrradd_done_callbacks  zFuture.add_done_callbackcs<fdd|jD}t|jt|}|r8||jdd<|S)z}Remove all instances of a callback from the "call when done" list. Returns the number of callbacks removed. cs g|]\}}|kr||fqSrr).0frBrLrr sz/Future.remove_done_callback..N)rlen)rrLZfiltered_callbacksZ removed_countrrPrremove_done_callbacks zFuture.remove_done_callbackcCs8|jtkr t|jd|||_t|_|dS)zMark the future done and set its result. If the future is already done when this method is called, raises InvalidStateError. : N)r9r:r rFrGrEr<)rrHrrr set_results  zFuture.set_resultcCsb|jtkr t|jd|t|tr0|}t|turDtd||_t |_| d|_ dS)zMark the future done and set an exception. If the future is already done when this method is called, raises InvalidStateError. rTzPStopIteration interacts badly with generators and cannot be raised into a FutureTN) r9r:r rF isinstancetype StopIteration TypeErrorr'rEr<r&)rr#rrr set_exceptions   zFuture.set_exceptionccs,|sd|_|V|s$td|S)NTzawait wasn't used with future)rD_asyncio_future_blockingr1rHr rrr __await__s zFuture.__await__)N)(r __module__ __qualname____doc__r:r9rGr'rrr3r5r[r&rr_future_repr_inforr!r+ classmethodr__class_getitem__propertyr-setterr2r8r>r<rCrDrHr#rMrSrUrZr\__iter__rrrrrsB     rcCs*z |j}WntyYn0|S|jSr,)r2AttributeErrorr)futr2rrr _get_loop(s   rhcCs|r dS||dS)z?Helper setting the result only if the future was not cancelled.N)rCrU)rgrHrrr_set_result_unless_cancelled4sricCsXt|}|tjjur tj|jS|tjjur8tj|jS|tjjurPtj|jS|SdSr,)rW concurrentfuturesr4r args TimeoutErrorrF)r)Z exc_classrrr_convert_future_exc;s      rncCs^|s J|r||s(dS|}|durH|t|n|}||dS)z8Copy state from a future to a concurrent.futures.Future.N) rDrCr>set_running_or_notify_cancelr#rZrnrHrU)rjsourcer#rHrrr_set_concurrent_future_stateGs rqcCsl|s J|rdS|r$J|r6|n2|}|durV|t|n|}||dS)zqInternal helper to copy state from another Future. The other Future may be a concurrent.futures.Future. N)rDrCr>r#rZrnrHrU)rpdestr#rHrrr_copy_future_stateVs   rscststtjjstdts._set_statecs2|r.dusur"n jdSr,)rCr>call_soon_threadsafe) destination) dest_looprp source_looprr_call_check_cancels z)_chain_future.._call_check_cancelcsJrdurrdSdus,ur8|n|dSr,)rC is_closedrv)rp)rurxrwryrr_call_set_states z&_chain_future.._call_set_state)rrVrjrkrrYrhrM)rprwrzr|r)rurxrwrpryr _chain_futurejs   r}r cCsNt|r |St|tjjs(Jd||dur8t}|}t|||S)z&Wrap concurrent.futures.Future object.z+concurrent.futures.Future is expected, got N) rrVrjrkrrr create_futurer})r$r Z new_futurerrrrs r) r___all__concurrent.futuresrjrIloggingrtypesrrrr r rr:r;rEDEBUGZ STACK_DEBUGrZ _PyFuturerhrirnrqrsr}r_asyncio ImportErrorZ_CFuturerrrrs>         *