Files
old-parkingkoncept/parkingkonceptvenv/lib/python3.7/site-packages/s3transfer/__pycache__/download.cpython-37.pyc

255 lines
22 KiB
Plaintext
Raw Normal View History

2019-11-17 12:44:16 +01:00
B
<00>[<5B>]<5D>m<00>@s<>ddlZddlZddlZddlZddlZddlmZddlmZddl m
Z
ddl m Z ddl mZddl mZddl mZdd l mZdd
l mZdd l mZdd l mZdd l mZddl mZddlmZddlmZe<00>e<1B>ZGdd<12>de<1D>ZGdd<14>de<1E>ZGdd<16>de<1E>Z Gdd<18>de<1E>Z!Gdd<1A>de!<21>Z"Gdd<1C>de<19>Z#Gdd<1E>de<18>Z$Gdd <20>d e$<24>Z%Gd!d"<22>d"e<18>Z&Gd#d$<24>d$e<18>Z'Gd%d&<26>d&e<18>Z(Gd'd(<28>d(e<18>Z)Gd)d*<2A>d*e<18>Z*Gd+d,<2C>d,e<1D>Z+Gd-d.<2E>d.e<1D>Z,dS)/<2F>N)<01>six)<01>seekable)<01>RetriesExceededError)<01>IN_MEMORY_DOWNLOAD_TAG)<01>S3_RETRYABLE_DOWNLOAD_ERRORS)<01> get_callbacks)<01>invoke_progress_callbacks)<01>calculate_num_parts)<01>calculate_range_parameter)<01>FunctionContainer)<01>CountCallbackInvoker)<01>StreamReaderProgress)<01>DeferredOpenFile)<01>Task)<01>SubmissionTaskc@sTeZdZdZdd<03>Zedd<05><00>Zdd<07>Zdd <09>Zd
d <0B>Z d d <0A>Z
dd<0F>Z dd<11>Z dS)<13>DownloadOutputManagera<72>Base manager class for handling various types of files for downloads
This class is typically used for the DownloadSubmissionTask class to help
determine the following:
* Provides the fileobj to write to downloads to
* Get a task to complete once everything downloaded has been written
The answers/implementations differ for the various types of file outputs
that may be accepted. All implementations must subclass and override
public methods from this class.
cCs||_||_||_dS)N)<03>_osutil<69>_transfer_coordinator<6F> _io_executor)<04>self<6C>osutil<69>transfer_coordinator<6F> io_executor<6F>r<00>;/tmp/pip-install-u_6_z2pz/s3transfer/s3transfer/download.py<70>__init__6szDownloadOutputManager.__init__cCs td<01><01>dS)aeDetermines if the target for the download is compatible with manager
:param download_target: The target for which the upload will write
data to.
:param osutil: The os utility to be used for the transfer
:returns: True if the manager can handle the type of target specified
otherwise returns False.
zmust implement is_compatible()N)<01>NotImplementedError)<03>cls<6C>download_targetrrrr<00> is_compatible;s z#DownloadOutputManager.is_compatiblecCsdS)z<>Get the tag (if any) to associate all GetObjectTasks
:rtype: s3transfer.futures.TaskTag
:returns: The tag to associate all GetObjectTasks with
Nr)rrrr<00>get_download_task_tagIsz+DownloadOutputManager.get_download_task_tagcCs td<01><01>dS)aGet file-like object to use for io writes in the io executor
:type transfer_future: s3transfer.futures.TransferFuture
:param transfer_future: The future associated with upload request
returns: A file-like object to write to
z*must implement get_fileobj_for_io_writes()N)r)r<00>transfer_futurerrr<00>get_fileobj_for_io_writesQsz/DownloadOutputManager.get_fileobj_for_io_writescCs|j<00>|j|<00>|||<03><03>dS)aQueue IO write for submission to the IO executor.
This method accepts an IO executor and information about the
downloaded data, and handles submitting this to the IO executor.
This method may defer submission to the IO executor if necessary.
N)r<00>submitr<00>get_io_write_task)r<00>fileobj<62>data<74>offsetrrr<00>queue_file_io_task[s z(DownloadOutputManager.queue_file_io_taskcCst|j|||d<01>d<02>S)aGet an IO write task for the requested set of data
This task can be ran immediately or be submitted to the IO executor
for it to run.
:type fileobj: file-like object
:param fileobj: The file-like object to write to
:type data: bytes
:param data: The data to write out
:type offset: integer
:param offset: The offset to write the data to in the file-like object
:returns: An IO task to be used to write data to a file-like object
)r%r&r')<01> main_kwargs)<02> IOWriteTaskr)rr%r&r'rrrr$is
z'DownloadOutputManager.get_io_write_taskcCs td<01><01>dS)a<>Get the final io task to complete the download
This is needed because based on the architecture of the TransferManager
the final tasks will be sent to the IO executor, but the executor
needs a final task for it to signal that the transfer is done and
all done callbacks can be run.
:rtype: s3transfer.tasks.Task
:returns: A final task to completed in the io executor
z"must implement get_final_io_task()N)r)rrrr<00>get_final_io_task<73>s z'DownloadOutputManager.get_final_io_taskcCs$t|d|jjd<02>}|j<03>|j<05>|S)N<>wb)<02>modeZ open_function)rr<00>openr<00>add_failure_cleanup<75>close)r<00>filename<6D>frrr<00>_get_fileobj_from_filename<6D>sz0DownloadOutputManager._get_fileobj_from_filenameN) <0A>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__r<00> classmethodrr r"r(r$r+r3rrrrr)s  
rcs@eZdZ<02>fdd<02>Zedd<04><00>Zdd<06>Zdd<08>Zd d
<EFBFBD>Z<08>Z S) <0B>DownloadFilenameOutputManagercs*tt|<00><02>|||<03>d|_d|_d|_dS)N)<06>superr9r<00>_final_filename<6D>_temp_filename<6D> _temp_fileobj)rrrr)<01> __class__rrr<00>s


z&DownloadFilenameOutputManager.__init__cCs t|tj<02>S)N)<03>
isinstancer<00> string_types)rrrrrrr<00>sz+DownloadFilenameOutputManager.is_compatiblecCs.|jjj}||_|j<04>|<02>|_|<00><07>|_|jS)N) <09>meta<74> call_argsr%r;rZget_temp_filenamer<<00>_get_temp_fileobjr=)rr!r%rrrr"<00>s


z7DownloadFilenameOutputManager.get_fileobj_for_io_writescCst|j|j|j|jd<01>dd<03>S)N)r%<00>final_filenamerT)rr)<00>is_final)<05>IORenameFileTaskrr=r;r)rrrrr+<00>s z/DownloadFilenameOutputManager.get_final_io_taskcCs$|<00>|j<01>}|j<02>|jj|j<01>|S)N)r3r<rr/rZ remove_file)rr2rrrrC<00>s z/DownloadFilenameOutputManager._get_temp_fileobj)
r4r5r6rr8rr"r+rC<00> __classcell__rr)r>rr9<00>s
  r9c@s(eZdZedd<02><00>Zdd<04>Zdd<06>ZdS)<08>DownloadSeekableOutputManagercCst|<01>S)N)r)rrrrrrr<00>sz+DownloadSeekableOutputManager.is_compatiblecCs
|jjjS)N)rArBr%)rr!rrrr"<00>sz7DownloadSeekableOutputManager.get_fileobj_for_io_writescCs t|jd<01>S)N)r)<02>CompleteDownloadNOOPTaskr)rrrrr+<00>sz/DownloadSeekableOutputManager.get_final_io_taskN)r4r5r6r8rr"r+rrrrrH<00>s rHcsVeZdZd<10>fdd<03> Zedd<05><00>Zdd<07>Zdd <09>Zd
d <0B>Z<08>fd d <0A>Z dd<0F>Z
<EFBFBD>Z S)<11> DownloadNonSeekableOutputManagerNcs6tt|<00><02>|||<03>|dkr"t<03>}||_t<05><06>|_dS)N)r:rJr<00>
DeferQueue<EFBFBD> _defer_queue<75> threading<6E>Lock<63>_io_submit_lock)rrrr<00> defer_queue)r>rrr<00>s 

z)DownloadNonSeekableOutputManager.__init__cCs
t|d<01>S)N<>write)<01>hasattr)rrrrrrr<00>sz.DownloadNonSeekableOutputManager.is_compatiblecCstS)N)r)rrrrr <00>sz6DownloadNonSeekableOutputManager.get_download_task_tagcCs
|jjjS)N)rArBr%)rr!rrrr"<00>sz:DownloadNonSeekableOutputManager.get_fileobj_for_io_writescCs t|jd<01>S)N)r)rIr)rrrrr+<00>sz2DownloadNonSeekableOutputManager.get_final_io_taskc s`|j<00>P|j<01>||<02>}x:|D]2}|d}t<03>d|d|<01>tt|<00><02>|||<03>qWWdQRXdS)Nr&z%Queueing IO offset %s for fileobj: %sr')rOrL<00>request_writes<65>logger<65>debugr:rJr()rr%r&r'<00>writesrQ)r>rrr(<00>s
 z3DownloadNonSeekableOutputManager.queue_file_io_taskcCst|j||d<01>d<02>S)N)r%r&)r))<02>IOStreamingWriteTaskr)rr%r&r'rrrr$<00>sz2DownloadNonSeekableOutputManager.get_io_write_task)N) r4r5r6rr8rr r"r+r(r$rGrr)r>rrJ<00>s  rJcs:eZdZd
<EFBFBD>fdd<03> Zedd<05><00>Zdd<07>Zdd <09>Z<07>ZS) <0B>$DownloadSpecialFilenameOutputManagerNcs tt|<00><02>||||<04>d|_dS)N)r:rXr<00>_fileobj)rrrrrP)r>rrrs
 z-DownloadSpecialFilenameOutputManager.__init__cCst|tj<02>o|<02>|<01>S)N)r?rr@Zis_special_file)rrrrrrrs z2DownloadSpecialFilenameOutputManager.is_compatiblecCs|jjj}|<00>|<02>|_|jS)N)rArBr%r3rY)rr!r1rrrr" s
 z>DownloadSpecialFilenameOutputManager.get_fileobj_for_io_writescCst|jdd|jid<03>S)NTr%)rrEr))<03> IOCloseTaskrrY)rrrrr+sz6DownloadSpecialFilenameOutputManager.get_final_io_task)N) r4r5r6rr8rr"r+rGrr)r>rrX<00>s rXc@sBeZdZdZdd<03>Zddd<06>Zdd<08>Zd d
<EFBFBD>Zd d <0C>Zd d<0E>Z dS)<10>DownloadSubmissionTaskz/Task for submitting tasks to execute a downloadcCsLttttg}|jjj}x|D]}|<05>||<02>r|SqWtd|t |<04>f<00><01>dS)a<>Retrieves a class for managing output for a download
:type transfer_future: s3transfer.futures.TransferFuture
:param transfer_future: The transfer future for the request
:type osutil: s3transfer.utils.OSUtils
:param osutil: The os utility associated to the transfer
:rtype: class of DownloadOutputManager
:returns: The appropriate class to use for managing a specific type of
input for downloads.
z'Output %s of type: %s is not supported.N)
rXr9rHrJrArBr%r<00> RuntimeError<6F>type)rr!rZdownload_manager_resolver_chainr%Zdownload_manager_clsrrr<00> _get_download_output_manager_clss

 z7DownloadSubmissionTask._get_download_output_manager_clsNc
Cs<>|jjdkrD|jf|jjj|jjjd<02>|jjj<06><02>}|j<00>|d<00>|<00>||<03>||j |<05>} |jj|j
kr<>|<00> |||||| ||<07>n|<00> |||||| ||<07>dS)a
:param client: The client associated with the transfer manager
:type config: s3transfer.manager.TransferConfig
:param config: The transfer config associated with the transfer
manager
:type osutil: s3transfer.utils.OSUtil
:param osutil: The os utility associated to the transfer manager
:type request_executor: s3transfer.futures.BoundedExecutor
:param request_executor: The request executor associated with the
transfer manager
:type io_executor: s3transfer.futures.BoundedExecutor
:param io_executor: The io executor associated with the
transfer manager
:type transfer_future: s3transfer.futures.TransferFuture
:param transfer_future: The transfer future associated with the
transfer request that tasks are being submitted for
:type bandwidth_limiter: s3transfer.bandwidth.BandwidthLimiter
:param bandwidth_limiter: The bandwidth limiter to use when
downloading streams
N)<02>Bucket<65>KeyZ ContentLength) rA<00>sizeZ head_objectrB<00>bucket<65>key<65>
extra_argsZprovide_transfer_sizer^rZmultipart_threshold<6C>_submit_download_request<73>_submit_ranged_download_request)
r<00>client<6E>configr<00>request_executorrr!<00>bandwidth_limiter<65>response<73>download_output_managerrrr<00>_submit7s"  
 
 
zDownloadSubmissionTask._submitc Csp|jj} |<06>|<07>}
t|d<01>} |<06><04>} |<06><05>} |jj|t|j|| j | j
|
| j | |j ||j |d<02>
| gd<03>| d<04>dS)N<>progress)
rgrbrcr%rd<00> callbacks<6B> max_attemptsrl<00> io_chunksizerj)rr)<00>done_callbacks)<01>tag)rArBr"rr r+rr#<00>ImmediatelyWriteIOGetObjectTaskrbrcrd<00>num_download_attemptsrq)rrgrhrrirrlr!rjrBr%<00>progress_callbacks<6B>get_object_tag<61>
final_taskrrrrems,
z/DownloadSubmissionTask._submit_download_requestc Cs<>|jj} t|d<01>}
|<06>|<07>} |j} t|jj| <0C>} |<06><07>}t|<00> ||<05><02>}x~t
| <0A>D]r}t | || <0A>}d|i}|<12> | j <0A>|<0F><0E>|jj|t|j|| j| j| ||
|j|| ||j|d<03> |jgd<04>|d<05>qRW|<0F><17>dS)NrnZRange) rgrbrcr%rdrorp<00> start_indexrlrqrj)rr)rr)rs)rArBrr"Zmultipart_chunksizer rar r <00>&_get_final_io_task_submission_callback<63>ranger
<00>updaterd<00> incrementrr#<00> GetObjectTaskrbrcrurqZ decrement<6E>finalize)rrgrhrrirrlr!rjrBrvr%<00> part_size<7A> num_partsrwZfinalize_download_invoker<65>iZrange_parameterrdrrrrf<00>sD


 
 z6DownloadSubmissionTask._submit_ranged_download_requestcCs|<01><00>}t|jj||<03>S)N)r+r rr#)rZdownload_managerrrxrrrrz<00>sz=DownloadSubmissionTask._get_final_io_task_submission_callbackcCs6||}||dkrd}n ||d}d||f}|S)N<><00>z bytes=%s-%sr)rr<>Z
part_indexr<EFBFBD>Z start_rangeZ end_rangeZ range_paramrrr<00>_calculate_range_param<61>s    z-DownloadSubmissionTask._calculate_range_param)N)
r4r5r6r7r^rmrerfrzr<>rrrrr[s
5*?r[c@seZdZddd<04>Zdd<06>ZdS)r~rNc  Cs<>d} x<>t|<07>D]<5D>} y<>|jf||d<02>|<05><02>}t|d|<06>}| rJ| <0B>||j<04>}|
}t|| <09>}x8|D]0}|j<04><06>s<>|<00>||||<10>|t|<12>7}q^dSq^WdSt k
r<EFBFBD>}z,t
j d|| |dd<06>|} t ||
|<00>wWdd}~XYqXqWt | <0C><01>dS)a<>Downloads an object and places content into io queue
:param client: The client to use when calling GetObject
:param bucket: The bucket to download from
:param key: The key to download from
:param fileobj: The file handle to write content to
:param exta_args: Any extra arguements to include in GetObject request
:param callbacks: List of progress callbacks to invoke on download
:param max_attempts: The number of retries to do when downloading
:param download_output_manager: The download output manager associated
with the current download.
:param io_chunksize: The size of each io chunk to read from the
download stream and queue in the io queue.
:param start_index: The location in the file to start writing the
content of the key to.
:param bandwidth_limiter: The bandwidth limiter to use when throttling
the downloading of data in streams.
N)r_r`ZBodyzCRetrying exception caught (%s), retrying request, (attempt %s / %s)T)<01>exc_info)r{Z
get_objectr Zget_bandwith_limited_streamr<00>DownloadChunkIterator<6F>done<6E>
_handle_io<EFBFBD>lenrrTrUrr)rrgrbrcr%rdrorprlrqryrjZlast_exceptionr<6E>rkZstreaming_bodyZ current_index<65>chunks<6B>chunk<6E>errr<00>_main<69>s: 




 zGetObjectTask._maincCs|<01>|||<04>dS)N)r()rrlr%r<><00>indexrrrr<>%szGetObjectTask._handle_io)rN)r4r5r6r<>r<>rrrrr~<00>s
;r~c@seZdZdZdd<03>ZdS)rtaGetObjectTask that immediately writes to the provided file object
This is useful for downloads where it is known only one thread is
downloading the object so there is no reason to go through the
overhead of using an IO queue and executor.
cCs|<01>|||<04>}|<05>dS)N)r$)rrlr%r<>r<>Ztaskrrrr<>0sz*ImmediatelyWriteIOGetObjectTask._handle_ioN)r4r5r6r7r<>rrrrrt)srtc@seZdZdd<02>ZdS)r*cCs|<01>|<03>|<01>|<02>dS)z<>Pulls off an io queue to write contents to a file
:param fileobj: The file handle to write content to
:param data: The data to write
:param offset: The offset to write the data to.
N)<02>seekrQ)rr%r&r'rrrr<>6s
zIOWriteTask._mainN)r4r5r6r<>rrrrr*5sr*c@seZdZdZdd<03>ZdS)rWz/Task for writing data to a non-seekable stream.cCs|<01>|<02>dS)z<>Write data to a fileobj.
Data will be written directly to the fileboj without
any prior seeking.
:param fileobj: The fileobj to write content to
:param data: The data to write
N)rQ)rr%r&rrrr<>Ds
zIOStreamingWriteTask._mainN)r4r5r6r7r<>rrrrrWAsrWc@seZdZdZdd<03>ZdS)rFaA task to rename a temporary file to its final filename
:param fileobj: The file handle that content was written to.
:param final_filename: The final name of the file to rename to
upon completion of writing the contents.
:param osutil: OS utility
cCs|<01><00>|<03>|j|<02>dS)N)r0Z rename_file<6C>name)rr%rDrrrrr<>YszIORenameFileTask._mainN)r4r5r6r7r<>rrrrrFQsrFc@seZdZdZdd<03>ZdS)rZziA task to close out a file once the download is complete.
:param fileobj: The fileobj to close.
cCs |<01><00>dS)N)r0)rr%rrrr<>cszIOCloseTask._mainN)r4r5r6r7r<>rrrrrZ^srZcs*eZdZdZd<08>fdd<05> Zdd<07>Z<05>ZS) rIz<>A NOOP task to serve as an indicator that the download is complete
Note that the default for is_final is set to True because this should
always be the last task.
NTcstt|<00>j|||||d<01>dS)N)rr)<00>pending_main_kwargsrrrE)r:rIr)rrr)r<>rrrE)r>rrrms 
z!CompleteDownloadNOOPTask.__init__cCsdS)Nr)rrrrr<>xszCompleteDownloadNOOPTask._main)NNNT)r4r5r6r7rr<>rGrr)r>rrIgs
 rIc@s(eZdZdd<02>Zdd<04>Zdd<06>ZeZdS)r<>cCs||_||_d|_dS)z<>Iterator to chunk out a downloaded S3 stream
:param body: A readable file-like object
:param chunksize: The amount to read each time
rN)<03>_body<64>
_chunksize<EFBFBD>
_num_reads)r<00>body<64> chunksizerrrr}szDownloadChunkIterator.__init__cCs|S)Nr)rrrr<00>__iter__<5F>szDownloadChunkIterator.__iter__cCs<|j<00>|j<02>}|jd7_|r$|S|jdkr2|St<04><00>dS)Nr<4E>)r<><00>readr<64>r<><00> StopIteration)rr<>rrr<00>__next__<5F>s
zDownloadChunkIterator.__next__N)r4r5r6rr<>r<><00>nextrrrrr<>|s
 r<>c@s eZdZdZdd<03>Zdd<05>ZdS)rKa"IO queue that defers write requests until they are queued sequentially.
This class is used to track IO data for a *single* fileobj.
You can send data to this queue, and it will defer any IO write requests
until it has the next contiguous block available (starting at 0).
cCsg|_t<01>|_d|_dS)Nr)<04>_writes<65>set<65>_pending_offsets<74> _next_offset)rrrrr<00>szDeferQueue.__init__cCs<>||jkrgSg}||jkr gSt<02>|j||f<02>|j<01>|<01>xh|jr<>|jdd|jkr<>t<02>|j<04>}|<03>|d|dd<03><02>|j<01>|d<00>|jt |d<00>7_q@W|S)a<>Request any available writes given new incoming data.
You call this method by providing new data along with the
offset associated with the data. If that new data unlocks
any contiguous writes that can now be submitted, this
method will return all applicable writes.
This is done with 1 method call so you don't have to
make two method calls (put(), get()) which acquires a lock
each method call.
rr<>)r'r&)
r<EFBFBD>r<><00>heapq<70>heappushr<68><00>add<64>heappop<6F>append<6E>remover<65>)rr'r&rVZ
next_writerrrrS<00>s

  zDeferQueue.request_writesN)r4r5r6r7rrSrrrrrK<00>srK)-<2D>logging<6E>os<6F>socketrMr<>Zbotocore.compatrZs3transfer.compatrZs3transfer.exceptionsrZs3transfer.futuresrZs3transfer.utilsrrrr r
r r r rZs3transfer.tasksrr<00> getLoggerr4rT<00>objectrr9rHrJrXr[r~rtr*rWrFrZrIr<>rKrrrr<00><module> sH               
q(-PB