�
i��Xc@s�ddlZddlZddlZddlZddlZddlZdZdZdZdZ dZ
dZdZd Z
d
ZdZeee
eegZide6d
e6de
6de6de6Zejd�Zdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd��YZdefd ��YZd!�Zed"�Z ej!d#d$�Z"ee d%�Z#d&efd'��YZ$d(efd)��YZ%dS(*i����Ns"Brian Quinlan (brian@sweetapp.com)tFIRST_COMPLETEDtFIRST_EXCEPTIONt
ALL_COMPLETEDt
_AS_COMPLETEDtPENDINGtRUNNINGt CANCELLEDtCANCELLED_AND_NOTIFIEDtFINISHEDtpendingtrunningt cancelledtfinishedsconcurrent.futurestErrorcBseZdZRS(s-Base class for all future-related exceptions.(t__name__t
__module__t__doc__(((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR
.stCancelledErrorcBseZdZRS(sThe Future was cancelled.(RRR(((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR2stTimeoutErrorcBseZdZRS(s*The operation exceeded the given deadline.(RRR(((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR6st_WaitercBs2eZdZd�Zd�Zd�Zd�ZRS(s;Provides the event that wait() and as_completed() block on.cCstj�|_g|_dS(N(t threadingtEventteventtfinished_futures(tself((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt__init__<scCs|jj|�dS(N(Rtappend(Rtfuture((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt
add_result@scCs|jj|�dS(N(RR(RR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt
add_exceptionCscCs|jj|�dS(N(RR(RR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt
add_cancelledFs(RRRRRRR(((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR:s
t_AsCompletedWaitercBs2eZdZd�Zd�Zd�Zd�ZRS(sUsed by as_completed().cCs&tt|�j�tj�|_dS(N(tsuperRRRtLocktlock(R((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRLscCs7|j�(tt|�j|�|jj�WdQXdS(N(R"R RRRtset(RR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRPs
cCs7|j�(tt|�j|�|jj�WdQXdS(N(R"R RRRR#(RR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRUs
cCs7|j�(tt|�j|�|jj�WdQXdS(N(R"R RRRR#(RR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRZs
(RRRRRRR(((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRIs
t_FirstCompletedWaitercBs)eZdZd�Zd�Zd�ZRS(s*Used by wait(return_when=FIRST_COMPLETED).cCs'tt|�j|�|jj�dS(N(R R$RRR#(RR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRbscCs'tt|�j|�|jj�dS(N(R R$RRR#(RR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRfscCs'tt|�j|�|jj�dS(N(R R$RRR#(RR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRjs(RRRRRR(((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR$_s t_AllCompletedWaitercBs;eZdZd�Zd�Zd�Zd�Zd�ZRS(s<Used by wait(return_when=FIRST_EXCEPTION and ALL_COMPLETED).cCs8||_||_tj�|_tt|�j�dS(N(tnum_pending_callststop_on_exceptionRR!R"R R%R(RR&R'((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRqs cCs<|j�-|jd8_|js2|jj�nWdQXdS(Ni(R"R&RR#(R((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt_decrement_pending_callsws
cCs$tt|�j|�|j�dS(N(R R%RR((RR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR}scCs=tt|�j|�|jr/|jj�n
|j�dS(N(R R%RR'RR#R((RR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR�s cCs$tt|�j|�|j�dS(N(R R%RR((RR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR�s(RRRRR(RRR(((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR%ns t_AcquireFuturescBs)eZdZd�Zd�Zd�ZRS(sDA context manager that does an ordered acquire of Future conditions.cCst|dt�|_dS(Ntkey(tsortedtidtfutures(RR-((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR�scCs%x|jD]}|jj�q
WdS(N(R-t
_conditiontacquire(RR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt __enter__�scGs%x|jD]}|jj�q
WdS(N(R-R.trelease(RtargsR((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt__exit__�s(RRRRR0R3(((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR)�s cCs�|tkrt�}n�|tkr0t�}nhtd�|D��}|tkrgt|dt�}n1|tkr�t|dt �}nt
d|��x|D]}|jj|�q�W|S(Ncss$|]}|jttgkVqdS(N(t_stateRR(t.0tf((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pys <genexpr>�sR'sInvalid return condition: %r(
RRRR$tsumRR%tTrueRtFalset
ValueErrort_waitersR(tfstreturn_whentwaitert
pending_countR6((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt_create_and_install_waiters�s
c cs�|dk r|tj�}nt|�}t|��4td�|D��}||}t|t�}WdQXz�x|D]}|VqwWx�|rJ|dkr�d}nA|tj�}|dkr�tdt|�t|�f��n|jj |�|j
�$|j}g|_|jj�WdQXx |D]}|V|j
|�q+Wq�WWdx.|D]&}|j�|jj
|�WdQXqVWXdS(snAn iterator over the given futures that yields each as it completes.
Args:
fs: The sequence of Futures (possibly created by different Executors) to
iterate over.
timeout: The maximum number of seconds to wait. If None, then there
is no limit on the wait time.
Returns:
An iterator that yields the given Futures as they complete (finished or
cancelled). If any given Futures are duplicated, they will be returned
once.
Raises:
TimeoutError: If the entire result iterator could not be generated
before the given timeout.
css*|] }|jttgkr|VqdS(N(R4RR(R5R6((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pys <genexpr>�sNis%d (of %d) futures unfinished(tNonettimeR#R)R@RRtlenRtwaitR"RtcleartremoveR.R;( R<ttimeouttend_timeRR R>Rtwait_timeoutR6((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pytas_completed�s<
tDoneAndNotDoneFuturess
done not_donec
Cs,t|���td�|D��}t|�|}|tkrR|rRt||�S|tkr�|r�td�|D��r�t||�Snt|�t|�kr�t||�St||�}WdQX|jj |�x.|D]&}|j
�|jj|�WdQXq�W|j
|j�t|t|�|�S(sWait for the futures in the given sequence to complete.
Args:
fs: The sequence of Futures (possibly created by different Executors) to
wait upon.
timeout: The maximum number of seconds to wait. If None, then there
is no limit on the wait time.
return_when: Indicates when this function should return. The options
are:
FIRST_COMPLETED - Return when any future finishes or is
cancelled.
FIRST_EXCEPTION - Return when any future finishes by raising an
exception. If no future raises an exception
then it is equivalent to ALL_COMPLETED.
ALL_COMPLETED - Return when all futures finish or are cancelled.
Returns:
A named 2-tuple of sets. The first set, named 'done', contains the
futures that completed (is finished or cancelled) before the wait
completed. The second set, named 'not_done', contains uncompleted
futures.
css*|] }|jttgkr|VqdS(N(R4RR(R5R6((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pys <genexpr>scss4|]*}|j�r|j�dk r|VqdS(N(Rt exceptionRA(R5R6((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pys <genexpr>sN(R)R#RRKRtanyRCR@RRDR.R;RFtupdateR(R<RGR=tdonetnot_doneR>R6((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRD�s"
tFuturecBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d �Zdd
�Z
dd�Zdd�Zd
�Zd�Zd�Zd�ZRS(s5Represents the result of an asynchronous computation.cCsItj�|_t|_d|_d|_d|_g|_ g|_
dS(s8Initializes the future. Should not be called by clients.N(Rt ConditionR.RR4RAt_resultt
_exceptiont
_tracebackR;t_done_callbacks(R((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR s cCssxl|jD]a}y||�Wq
tk
rAtjd|�q
tk
rT�q
tjd|�q
Xq
WdS(Ns!exception calling callback for %r(RVt ExceptiontLOGGERRLt
BaseException(Rtcallback((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt_invoke_callbacks*s
cCs�|j��|jtkr|jrOdtt|��t|j|jjjfSdtt|��t|j|j jjfSndtt|��t|jfSWdQXdS(Ns!<Future at %s state=%s raised %s>s#<Future at %s state=%s returned %s>s<Future at %s state=%s>(
R.R4RRTthexR,t_STATE_TO_DESCRIPTION_MAPt __class__RRS(R((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt__repr__As
cCsf|j�M|jttgkr#tS|jttgkr<tSt|_|jj�WdQX|j �tS(s�Cancel the future if possible.
Returns True if the future was cancelled, False otherwise. A future
cannot be cancelled if it is running or has already completed.
N(
R.R4RRR9RRR8t
notify_allR[(R((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pytcancelRs
cCs'|j�|jttgkSWdQXdS(s(Return True if the future has cancelled.N(R.R4RR(R((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRes
cCs!|j�|jtkSWdQXdS(s1Return True if the future is currently executing.N(R.R4R(R((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR
js
cCs*|j�|jtttgkSWdQXdS(s>Return True of the future was cancelled or finished executing.N(R.R4RRR(R((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyROos
cCs\|jrQt|jtj�r-|jj}nt|j�}||j|j�n|jSdS(N(RTt
isinstancettypestInstanceTypeR^ttypeRURS(Rtexception_type((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt__get_resultts cCsJ|j�1|jtttgkr6|jj|�dSWdQX||�dS(s%Attaches a callable that will be called when the future finishes.
Args:
fn: A callable that will be called with this future as its only
argument when the future completes or is cancelled. The callable
will always be called by a thread in the same process in which
it was added. If the future has already completed or been
cancelled then the callable will be called immediately. These
callables are called in the order that they were added.
N(R.R4RRRRVR(Rtfn((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pytadd_done_callback�s
cCs�|j��|jttgkr+t��n|jtkrD|j�S|jj|�|jttgkrut��n"|jtkr�|j�St��WdQXdS(sBReturn the result of the call that the future represents.
Args:
timeout: The number of seconds to wait for the result if the future
isn't done. If None, then there is no limit on the wait time.
Returns:
The result of the call that the future represents.
Raises:
CancelledError: If the future was cancelled.
TimeoutError: If the future didn't finish executing before the given
timeout.
Exception: If the call raised then that exception will be raised.
N( R.R4RRRRt_Future__get_resultRDR(RRG((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pytresult�s
cCs�|j��|jttgkr+t��n|jtkrJ|j|jfS|jj|�|jttgkr{t��n(|jtkr�|j|jfSt ��WdQXdS(sqReturn a tuple of (exception, traceback) raised by the call that the
future represents.
Args:
timeout: The number of seconds to wait for the exception if the
future isn't done. If None, then there is no limit on the wait
time.
Returns:
The exception raised by the call that the future represents or None
if the call completed without raising.
Raises:
CancelledError: If the future was cancelled.
TimeoutError: If the future didn't finish executing before the given
timeout.
N(
R.R4RRRRRTRURDR(RRG((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pytexception_info�s
cCs|j|�dS(sUReturn the exception raised by the call that the future represents.
Args:
timeout: The number of seconds to wait for the exception if the
future isn't done. If None, then there is no limit on the wait
time.
Returns:
The exception raised by the call that the future represents or None
if the call completed without raising.
Raises:
CancelledError: If the future was cancelled.
TimeoutError: If the future didn't finish executing before the given
timeout.
i(Rl(RRG((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRL�scCs�|j��|jtkrGt|_x|jD]}|j|�q,WtS|jtkrct|_t St
jdt|�|j�t
d��WdQXdS(s�Mark the future as running or process any cancel notifications.
Should only be used by Executor implementations and unit tests.
If the future has been cancelled (cancel() was called and returned
True) then any threads waiting on the future completing (though calls
to as_completed() or wait()) are notified and False is returned.
If the future was not cancelled then it is put in the running state
(future calls to running() will return True) and True is returned.
This method should be called by Executor implementations before
executing the work associated with this future. If this method returns
False then the work should not be executed.
Returns:
False if the Future was cancelled, True otherwise.
Raises:
RuntimeError: if this method was already called or if set_result()
or set_exception() was called.
s!Future %s in unexpected state: %ssFuture in unexpected stateN(R.R4RRR;RR9RRR8RXtcriticalR,tRuntimeError(RR>((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pytset_running_or_notify_cancel�s
cCs^|j�E||_t|_x|jD]}|j|�q&W|jj�WdQX|j�dS(s�Sets the return value of work associated with the future.
Should only be used by Executor implementations and unit tests.
N(R.RSRR4R;RR`R[(RRkR>((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt
set_results
cCsg|j�N||_||_t|_x|jD]}|j|�q/W|jj�WdQX|j�dS(s�Sets the result of the future as being the given exception
and traceback.
Should only be used by Executor implementations and unit tests.
N( R.RTRURR4R;RR`R[(RRLt tracebackR>((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pytset_exception_infos
cCs|j|d�dS(s�Sets the result of the future as being the given exception.
Should only be used by Executor implementations and unit tests.
N(RrRA(RRL((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt
set_exception*sN(RRRRR[R_RaRR
RORjRiRARkRlRLRoRpRrRs(((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRQs"
! (
tExecutorcBs>eZdZd�Zd�Zed�Zd�Zd�ZRS(sCThis is an abstract base class for concrete asynchronous executors.cOs
t��dS(s Submits a callable to be executed with the given arguments.
Schedules the callable to be executed as fn(*args, **kwargs) and returns
a Future instance representing the execution of the callable.
Returns:
A Future representing the given call.
N(tNotImplementedError(RRhR2tkwargs((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pytsubmit4s csx|jd���dk r.�tj��ngtj|�D]}|j||�^q>����fd�}|�S(s}Returns a iterator equivalent to map(fn, iter).
Args:
fn: A callable that will take as many arguments as there are
passed iterables.
timeout: The maximum number of seconds to wait. If None, then there
is no limit on the wait time.
Returns:
An iterator equivalent to: map(func, *iterables) but the calls may
be evaluated out-of-order.
Raises:
TimeoutError: If the entire result iterator could not be generated
before the given timeout.
Exception: If fn(*args) raises for any values.
RGc3sjzGx@�D]8}�dkr*|j�Vq
|j�tj��Vq
WWdx�D]}|j�qQWXdS(N(RARkRBRa(R(RHR<RG(s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pytresult_iteratorYs
N(tgetRARBt itertoolstizipRw(RRht iterablesRvR2Rx((RHR<RGs</usr/lib/python2.7/site-packages/concurrent/futures/_base.pytmap?s.
cCsdS(s�Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other
methods can be called after this one.
Args:
wait: If True then shutdown will not return until all running
futures have finished executing and the resources used by the
executor have been reclaimed.
N((RRD((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pytshutdownescCs|S(N((R((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR0rscCs|jdt�tS(NRD(R~R8R9(Rtexc_typetexc_valtexc_tb((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyR3us( RRRRwR}R8R~R0R3(((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyRt1s &
(&tcollectionstloggingRRzRBRct
__author__RRRRRRRRRt_FUTURE_STATESR]t getLoggerRXRWR
RRtobjectRRR$R%R)R@RARJt
namedtupleRKRDRQRt(((s</usr/lib/python2.7/site-packages/concurrent/futures/_base.pyt<module>sV
;1� |