rmLbc@sddlZejjddddlmZddlmZddlZddlZddl Z ddl m Z ddl m Z ddl mZmZdd lmZdd lmZejeZd efd YZd efdYZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZeddgZedZ edZ!dS(iNis/usr/lib/fence-agents/bundled(tfutures(t namedtuple(tMAXINT(tsix(tCancelledErrortTransferNotDoneError(tFunctionContainer(t TaskSemaphoretTransferFuturecBsJeZdddZedZdZdZdZdZ RS(cCsL||_|dkr$t|_n||_|dkrHt|_ndS(sThe future associated to a submitted transfer request :type meta: TransferMeta :param meta: The metadata associated to the request. This object is visible to the requester. :type coordinator: TransferCoordinator :param coordinator: The coordinator associated to the request. This object is not visible to the requester. N(t_metatNonet TransferMetat _coordinatortTransferCoordinator(tselftmetat coordinator((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyt__init__ s    cCs|jS(s.The metadata associated tio the TransferFuture(R (R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR3scCs |jjS(smDetermines if a TransferFuture has completed :returns: True if completed. False, otherwise. (R tdone(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR8scCs;y|jjSWn#tk r6}|j|nXdS(sWaits until TransferFuture is done and returns the result If the TransferFuture succeeded, it will return the result. If the TransferFuture failed, it will raise the exception associated to the failure. N(R tresulttKeyboardInterrupttcancel(Rte((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR?s  cCs|jjdS(s6Cancels the request associated with the TransferFutureN(R R(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyROscCs5|jstdn|jj|dtdS(s!Sets the exception on the future.s?set_exception can only be called once the transfer is complete.toverrideN(RRR t set_exceptiontTrue(Rt exception((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRSs  N( t__name__t __module__R RtpropertyRRRRR(((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs    R cBsbeZdZdddZedZedZedZedZ dZ RS(s'Holds metadata about the TransferFuturecCs(||_||_d|_i|_dS(N(t _call_argst _transfer_idR t_sizet _user_context(Rt call_argst transfer_id((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR^s   cCs|jS(s*The call args used in the transfer request(R(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR"dscCs|jS(sThe unique id of the transfer(R(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR#iscCs|jS(s)The size of the transfer request if known(R (R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pytsizenscCs|jS(s.A dictionary that requesters can store data in(R!(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyt user_contextsscCs ||_dS(sA method to provide the size of a transfer request By providing this value, the TransferManager will not try to call HeadObject or use the use OS to determine the size of the transfer. N(R (RR$((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pytprovide_transfer_sizexsN( RRt__doc__R RRR"R#R$R%R&(((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR \sR cBs eZdZddZdZedZedZedZ edZ dZ e dZ d Zd ed Zd Zd ZdZddZdZdZdZdZdZdZdZdZdZdZRS(s*A helper class for managing TransferFuturecCs||_d|_d|_d|_t|_g|_g|_t j |_ t j |_ t j |_t j |_t j |_dS(Ns not-started(R#t_statusR t_resultt _exceptiontsett_associated_futurest_failure_cleanupst_done_callbackst threadingtEventt _done_eventtLockt_lockt_associated_futures_lockt_done_callbacks_lockt_failure_cleanups_lock(RR#((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs       cCsd|jj|jfS(Ns%s(transfer_id=%s)(t __class__RR#(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyt__repr__scCs|jS(N(R*(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRscCs$|jtj|jSWdQXdS(sThe list of futures associated to the inprogress TransferFuture Once the transfer finishes this list becomes empty as the transfer is considered done and there should be no running futures left. N(R4tcopyR,(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pytassociated_futuress cCs|jS(s;The list of callbacks to call when the TransferFuture fails(R-(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pytfailure_cleanupsscCs|jS(sThe status of the TransferFuture The currently supported states are: * not-started - Has yet to start. If in this state, a transfer can be canceled immediately and nothing will happen. * queued - SubmissionTask is about to submit tasks * running - Is inprogress. In-progress as of now means that the SubmissionTask that runs the transfer is being executed. So there is no guarantee any transfer requests had been made to S3 if this state is reached. * cancelled - Was cancelled * failed - An exception other than CancelledError was thrown * success - No exceptions were thrown and is done. (R((R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pytstatusscCs/|j d|_||_d|_WdQXdS(sSet a result for the TransferFuture Implies that the TransferFuture succeeded. This will always set a result because it is invoked on the final task where there is only ever one final task and it is ran at the very end of a transfer process. So if a result is being set for this final task, the transfer succeeded even if something came a long and canceled the transfer on the final task. tsuccessN(R3R R*R)R((RR((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyt set_results   cCs<|j-|j s|r2||_d|_nWdQXdS(sSet an exception for the TransferFuture Implies the TransferFuture failed. :param exception: The exception that cause the transfer to fail. :param override: If True, override any existing state. tfailedN(R3RR*R((RRR((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs  cCs,|jjt|jr%|jn|jS(sWaits until TransferFuture is done and returns the result If the TransferFuture succeeded, it will return the result. If the TransferFuture failed, it will raise the exception associated to the failure. (R1twaitRR*R)(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs   tcCs|jp|jsut}tjd|||||_|jdkrVt}nd|_|ru|jqunWdQXdS(sCancels the TransferFuture :param msg: The message to attach to the cancellation :param exc_type: The type of exception to set for the cancellation s%s cancel(%s) calleds not-startedt cancelledN( R3RtFalsetloggertdebugR*R(Rt announce_done(Rtmsgtexc_typetshould_announce_done((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs    cCs|jddS(s+Sets the TransferFutrue's status to runningtqueuedN(t_transition_to_non_done_state(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pytset_status_to_queuedscCs|jddS(s+Sets the TransferFuture's status to runningtrunningN(RK(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pytset_status_to_runningscCsE|j6|jr2td|j|fn||_WdQXdS(Ns=Unable to transition from done state %s to non-done state %s.(R3Rt RuntimeErrorR<R((Rt desired_state((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRKs   cCs\tjd|||jf|j|d|}|j||jt|j||S(sSubmits a task to a provided executor :type executor: s3transfer.futures.BoundedExecutor :param executor: The executor to submit the callable to :type task: s3transfer.tasks.Task :param task: The task to submit to the executor :type tag: s3transfer.futures.TaskTag :param tag: A tag to associate to the submitted task :rtype: concurrent.futures.Future :returns: A future representing the submitted task s;Submitting task %s to executor %s for transfer request: %s.ttag(RDRER#tsubmittadd_associated_futuretadd_done_callbackRtremove_associated_future(RtexecutorttaskRQtfuture((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRRs cCs |jdkS(sDetermines if a TransferFuture has completed :returns: False if status is equal to 'failed', 'cancelled', or 'success'. True, otherwise R?RBR=(sfaileds cancelledssuccess(R<(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR)scCs$|j|jj|WdQXdS(s6Adds a future to be associated with the TransferFutureN(R4R,tadd(RRX((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRS1s cCs$|j|jj|WdQXdS(s4Removes a future's association to the TransferFutureN(R4R,tremove(RRX((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRU6s c Os0|j!|jjt|||WdQXdS(s7Add a done callback to be invoked when transfer is doneN(R5R.tappendR(Rtfunctiontargstkwargs((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRT;s  c Os0|j!|jjt|||WdQXdS(s$Adds a callback to call upon failureN(R6R-R[R(RR\R]R^((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pytadd_failure_cleanupBs  cCs7|jdkr|jn|jj|jdS(sMAnnounce that future is done running and run associated callbacks This will run any failure cleanups if the transfer failed if not they have not been run, allows the result() to be unblocked, and will run any done callbacks associated to the TransferFuture if they have not already been ran. R=N(R<t_run_failure_cleanupsR1R+t_run_done_callbacks(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRFHs  cCs-|j|j|jg|_WdQXdS(N(R5t_run_callbacksR.(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRaUs cCs-|j|j|jg|_WdQXdS(N(R6RbR;R-(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR`]s cCs"x|D]}|j|qWdS(N(t _run_callback(Rt callbackstcallback((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRbes cCs:y |Wn(tk r5tjd|dtnXdS(NsException raised in %s.texc_info(t ExceptionRDRER(RRe((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRcis  N(RRR'R RR8RRR:R;R<R>RCRRRRRLRNRKRRRRSRURTR_RFRaR`RbRc(((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR s2                 tBoundedExecutorcBs;eZejZdddZdedZedZ RS(cCsR||_|dkr!|j}n|d|j|_t||_||_dS(sDAn executor implentation that has a maximum queued up tasks The executor will block if the number of tasks that have been submitted and is currently working on is past its maximum. :params max_size: The maximum number of inflight futures. An inflight future means that the task is either queued up or is currently being executed. A size of None or 0 means that the executor will have no bound in terms of the number of inflight futures. :params max_num_threads: The maximum number of threads the executor uses. :type tag_semaphores: dict :params tag_semaphores: A dictionary where the key is the name of the tag and the value is the semaphore to use when limiting the number of tasks the executor is processing at a time. :type executor_cls: BaseExecutor :param underlying_executor_cls: The executor class that get bounded by this executor. If None is provided, the concurrent.futures.ThreadPoolExecutor class is used. t max_workersN(t_max_num_threadsR t EXECUTOR_CLSt _executorRt _semaphoret_tag_semaphores(Rtmax_sizetmax_num_threadsttag_semaphorest executor_cls((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRus    cCsu|j}|r|j|}n|j|j|}t|j|j|}t|jj|}|j ||S(s1Submit a task to complete :type task: s3transfer.tasks.Task :param task: The task to run __call__ on :type tag: s3transfer.futures.TaskTag :param tag: An optional tag to associate to the task. This is used to override which semaphore to use. :type block: boolean :param block: True if to wait till it is possible to submit a task. False, if not to wait and raise an error if not able to submit a task. :returns: The future assocaited to the submitted task ( RmRntacquireR#RtreleasetExecutorFutureRlRRRT(RRWRQtblockt semaphoret acquire_tokentrelease_callbackRX((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRRs  cCs|jj|dS(N(Rltshutdown(RR@((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRzsN( RRRtThreadPoolExecutorRkR RRRRRz(((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRhrs   %RucBs,eZdZdZdZdZRS(cCs ||_dS(sA future returned from the executor Currently, it is just a wrapper around a concurrent.futures.Future. However, this can eventually grow to implement the needed functionality of concurrent.futures.Future if we move off of the library and not affect the rest of the codebase. :type future: concurrent.futures.Future :param future: The underlying future N(t_future(RRX((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs cCs |jjS(N(R|R(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRscs#fd}|jj|dS(sAdds a callback to be completed once future is done :parm fn: A callable that takes no arguments. Note that is different than concurrent.futures.Future.add_done_callback that requires a single argument for the future. csS(N((tfuture_passed_to_callback(tfn(s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyt done_callbacksN(R|RT(RR~R((R~s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRTs cCs |jjS(N(R|R(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs(RRRRRTR(((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRus  t BaseExecutorcBs/eZdZddZdZedZRS(sABase Executor class implementation needed to work with s3transfercCsdS(N((RRi((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRscOstddS(Nssubmit()(tNotImplementedError(RR~R]R^((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRRscCstddS(Ns shutdown()(R(RR@((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRzsN(RRR'R RRRRRz(((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs  tNonThreadedExecutorcBs#eZdZdZedZRS(s@A drop-in replacement non-threaded version of ThreadPoolExecutorcOs}t}y |||}|j|WnMtk rxtjd\}}tjd||||j||nX|S(Nis0Setting exception for %s to %s with traceback %s(tNonThreadedExecutorFutureR>RgtsysRfRDREtset_exception_info(RR~R]R^RXRRttb((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRRs   cCsdS(N((RR@((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRzs(RRR'RRRRz(((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs RcBsYeZdZdZdZdZd dZdZdZ dZ dZ RS( sThe Future returned from NonThreadedExecutor Note that this future is **not** thread-safe as it is being used from the context of a non-threaded environment. cCs1d|_d|_d|_t|_g|_dS(N(R R)R*t _tracebackRCt_doneR.(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs     cCs||_|jdS(N(R)t _set_done(RR((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR>s cCs ||_||_|jdS(N(R*RR(RRt traceback((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs  cCs5|jr.tjt|j|j|jn|jS(N(R*RtreraisettypeRR)(Rttimeout((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs cCs7t|_x|jD]}|j|qWg|_dS(N(RRR.t_invoke_done_callback(RR((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs cCs ||S(N((RR((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR#scCs|jS(N(R(R((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyR&scCs-|jr|j|n|jj|dS(N(RRR.R[(RR~((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRT)s N( RRR'RR>RR RRRRRT(((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyRs       tTaskTagtnametin_memory_uploadtin_memory_download("Rtpathtinsertt concurrentRt collectionsRR9tloggingR/ts3transfer.compatRRts3transfer.exceptionsRRts3transfer.utilsRRt getLoggerRRDtobjectRR R RhRuRRRRtIN_MEMORY_UPLOAD_TAGtIN_MEMORY_DOWNLOAD_TAG(((s6/usr/lib/python2.7/site-packages/s3transfer/futures.pyt s.    =&L# /