o
    Pž<an  ã                   @   sz  d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z
ddlmZ ddlmZ ddlmZ ddlZddlmZmZ dZdZG d	d
„ d
ejƒZe e¡Ze eƒ ¡ ejjZdZ e!ƒ Z"d%dd„Z#dd„ Z$dd„ Z%G dd„ de&ƒZ'G dd„ de!ƒZ(G dd„ de!ƒZ)G dd„ de!ƒZ*G dd„ de!ƒZ+G dd„ dej,ƒZ-G dd „ d e!ƒZ.G d!d"„ d"e!ƒZ/G d#d$„ d$e!ƒZ0dS )&a­  Abstractions over S3's upload/download operations.

This module provides high level abstractions for efficient
uploads/downloads.  It handles several things for the user:

* Automatically switching to multipart transfers when
  a file is over a specific size threshold
* Uploading/downloading a file in parallel
* Throttling based on max bandwidth
* Progress callbacks to monitor transfers
* Retries.  While botocore handles retries for streaming uploads,
  it is not possible for it to handle retries for streaming
  downloads.  This module handles retries for both cases so
  you don't need to implement any retry logic yourself.

This module has a reasonable set of defaults.  It also allows you
to configure many aspects of the transfer process including:

* Multipart threshold size
* Max parallel downloads
* Max bandwidth
* Socket timeouts
* Retry amounts

There is no support for s3->s3 multipart copies at this
time.


.. _ref_s3transfer_usage:

Usage
=====

The simplest way to use this module is:

.. code-block:: python

    client = boto3.client('s3', 'us-west-2')
    transfer = S3Transfer(client)
    # Upload /tmp/myfile to s3://bucket/key
    transfer.upload_file('/tmp/myfile', 'bucket', 'key')

    # Download s3://bucket/key to /tmp/myfile
    transfer.download_file('bucket', 'key', '/tmp/myfile')

The ``upload_file`` and ``download_file`` methods also accept
``**kwargs``, which will be forwarded through to the corresponding
client operation.  Here are a few examples using ``upload_file``::

    # Making the object public
    transfer.upload_file('/tmp/myfile', 'bucket', 'key',
                         extra_args={'ACL': 'public-read'})

    # Setting metadata
    transfer.upload_file('/tmp/myfile', 'bucket', 'key',
                         extra_args={'Metadata': {'a': 'b', 'c': 'd'}})

    # Setting content type
    transfer.upload_file('/tmp/myfile.json', 'bucket', 'key',
                         extra_args={'ContentType': "application/json"})


The ``S3Transfer`` clas also supports progress callbacks so you can
provide transfer progress to users.  Both the ``upload_file`` and
``download_file`` methods take an optional ``callback`` parameter.
Here's an example of how to print a simple progress percentage
to the user:

.. code-block:: python

    class ProgressPercentage(object):
        def __init__(self, filename):
            self._filename = filename
            self._size = float(os.path.getsize(filename))
            self._seen_so_far = 0
            self._lock = threading.Lock()

        def __call__(self, bytes_amount):
            # To simplify we'll assume this is hooked up
            # to a single filename.
            with self._lock:
                self._seen_so_far += bytes_amount
                percentage = (self._seen_so_far / self._size) * 100
                sys.stdout.write(
                    "%s  %s / %s  (%.2f%%)" % (self._filename, self._seen_so_far,
                                                 self._size, percentage))
                sys.stdout.flush()


    transfer = S3Transfer(boto3.client('s3', 'us-west-2'))
    # Upload /tmp/myfile to s3://bucket/key and print upload progress.
    transfer.upload_file('/tmp/myfile', 'bucket', 'key',
                         callback=ProgressPercentage('/tmp/myfile'))



You can also provide a TransferConfig object to the S3Transfer
object that gives you more fine grained control over the
transfer.  For example:

.. code-block:: python

    client = boto3.client('s3', 'us-west-2')
    config = TransferConfig(
        multipart_threshold=8 * 1024 * 1024,
        max_concurrency=10,
        num_download_attempts=10,
    )
    transfer = S3Transfer(client, config)
    transfer.upload_file('/tmp/foo', 'bucket', 'key')


é    N)Úsix)ÚReadTimeoutError)ÚIncompleteReadError)ÚRetriesExceededErrorÚS3UploadFailedErrorzAmazon Web Servicesz0.5.0c                   @   s   e Zd Zdd„ ZdS )ÚNullHandlerc                 C   s   d S ©N© )ÚselfÚrecordr	   r	   ú5/usr/lib/python3/dist-packages/s3transfer/__init__.pyÚemit–   ó   zNullHandler.emitN)Ú__name__Ú
__module__Ú__qualname__r   r	   r	   r	   r   r   •   s    r   i   é   c                 C   s   d  dd„ t| ƒD ƒ¡S )NÚ c                 s   s   � | ]	}t  tj¡V  qd S r   )ÚrandomÚchoiceÚstringÚ	hexdigits)Ú.0Ú_r	   r	   r   Ú	<genexpr>¤   s   € z(random_file_extension.<locals>.<genexpr>)ÚjoinÚrange)Ú
num_digitsr	   r	   r   Úrandom_file_extension£   s   r   c                 K   ó*   |dv rt | jdƒr| j ¡  d S d S d S )N©Ú	PutObjectÚ
UploadPartÚdisable_callback)ÚhasattrÚbodyr#   ©ÚrequestÚoperation_nameÚkwargsr	   r	   r   Údisable_upload_callbacks§   ó
   
ÿþr*   c                 K   r   )Nr    Úenable_callback)r$   r%   r,   r&   r	   r	   r   Úenable_upload_callbacks­   r+   r-   c                   @   s   e Zd ZdS )ÚQueueShutdownErrorN)r   r   r   r	   r	   r	   r   r.   ³   s    r.   c                   @   s„   e Zd Z	ddd„Ze		ddd„ƒZdd„ Zdd	d
„Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚReadFileChunkNTc                 C   sF   || _ || _| j| j |||d�| _| j  | j¡ d| _|| _|| _dS )a‚  

        Given a file object shown below:

            |___________________________________________________|
            0          |                 |                 full_file_size
                       |----chunk_size---|
                 start_byte

        :type fileobj: file
        :param fileobj: File like object

        :type start_byte: int
        :param start_byte: The first byte from which to start reading.

        :type chunk_size: int
        :param chunk_size: The max chunk size to read.  Trying to read
            pass the end of the chunk size will behave like you've
            reached the end of the file.

        :type full_file_size: int
        :param full_file_size: The entire content length associated
            with ``fileobj``.

        :type callback: function(amount_read)
        :param callback: Called whenever data is read from this object.

        )Úrequested_sizeÚ
start_byteÚactual_file_sizer   N)Ú_fileobjÚ_start_byteÚ_calculate_file_sizeÚ_sizeÚseekÚ_amount_readÚ	_callbackÚ_callback_enabled)r
   Úfileobjr1   Ú
chunk_sizeÚfull_file_sizeÚcallbackr,   r	   r	   r   Ú__init__¸   s   þ
zReadFileChunk.__init__c                 C   s,   t |dƒ}t | ¡ ¡j}| ||||||ƒS )aW  Convenience factory function to create from a filename.

        :type start_byte: int
        :param start_byte: The first byte from which to start reading.

        :type chunk_size: int
        :param chunk_size: The max chunk size to read.  Trying to read
            pass the end of the chunk size will behave like you've
            reached the end of the file.

        :type full_file_size: int
        :param full_file_size: The entire content length associated
            with ``fileobj``.

        :type callback: function(amount_read)
        :param callback: Called whenever data is read from this object.

        :type enable_callback: bool
        :param enable_callback: Indicate whether to invoke callback
            during read() calls.

        :rtype: ``ReadFileChunk``
        :return: A new instance of ``ReadFileChunk``

        Úrb)ÚopenÚosÚfstatÚfilenoÚst_size)ÚclsÚfilenamer1   r<   r>   r,   ÚfÚ	file_sizer	   r	   r   Úfrom_filenameà   s
   
ÿzReadFileChunk.from_filenamec                 C   s   || }t ||ƒS r   )Úmin)r
   r;   r0   r1   r2   Úmax_chunk_sizer	   r	   r   r5     s   
z"ReadFileChunk._calculate_file_sizec                 C   sh   |d u r| j | j }n	t| j | j |ƒ}| j |¡}|  jt|ƒ7  _| jd ur2| jr2|  t|ƒ¡ |S r   )r6   r8   rK   r3   ÚreadÚlenr9   r:   )r
   ÚamountÚamount_to_readÚdatar	   r	   r   rM     s   zReadFileChunk.readc                 C   ó
   d| _ d S ©NT©r:   ©r
   r	   r	   r   r,     ó   
zReadFileChunk.enable_callbackc                 C   rR   ©NFrT   rU   r	   r	   r   r#     rV   zReadFileChunk.disable_callbackc                 C   s<   | j  | j| ¡ | jd ur| jr|  || j ¡ || _d S r   )r3   r7   r4   r9   r:   r8   )r
   Úwherer	   r	   r   r7     s   
zReadFileChunk.seekc                 C   s   | j  ¡  d S r   )r3   ÚcloserU   r	   r	   r   rY     s   zReadFileChunk.closec                 C   ó   | j S r   )r8   rU   r	   r	   r   Útell!  s   zReadFileChunk.tellc                 C   rZ   r   )r6   rU   r	   r	   r   Ú__len__$  s   zReadFileChunk.__len__c                 C   s   | S r   r	   rU   r	   r	   r   Ú	__enter__,  r   zReadFileChunk.__enter__c                 O   s   |   ¡  d S r   )rY   )r
   Úargsr)   r	   r	   r   Ú__exit__/  ó   zReadFileChunk.__exit__c                 C   s   t g ƒS r   )ÚiterrU   r	   r	   r   Ú__iter__2  s   zReadFileChunk.__iter__rS   r   )r   r   r   r?   ÚclassmethodrJ   r5   rM   r,   r#   r7   rY   r[   r\   r]   r_   rb   r	   r	   r	   r   r/   ·   s$    
ÿ(ÿ 
r/   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )ÚStreamReaderProgressz<Wrapper for a read only stream that adds progress callbacks.Nc                 C   s   || _ || _d S r   )Ú_streamr9   )r
   Ústreamr>   r	   r	   r   r?   =  s   
zStreamReaderProgress.__init__c                 O   s.   | j j|i |¤Ž}| jd ur|  t|ƒ¡ |S r   )re   rM   r9   rN   )r
   r^   r)   Úvaluer	   r	   r   rM   A  s   
zStreamReaderProgress.readr   )r   r   r   Ú__doc__r?   rM   r	   r	   r	   r   rd   ;  s    
rd   c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚOSUtilsc                 C   s   t j |¡S r   )rB   ÚpathÚgetsize©r
   rG   r	   r	   r   Úget_file_sizeI  r`   zOSUtils.get_file_sizec                 C   s   t j||||dd�S )NF)r,   )r/   rJ   )r
   rG   r1   Úsizer>   r	   r	   r   Úopen_file_chunk_readerL  s   þzOSUtils.open_file_chunk_readerc                 C   s
   t ||ƒS r   )rA   )r
   rG   Úmoder	   r	   r   rA   Q  rV   zOSUtils.openc                 C   s&   zt  |¡ W dS  ty   Y dS w )z+Remove a file, noop if file does not exist.N)rB   ÚremoveÚOSErrorrl   r	   r	   r   Úremove_fileT  s
   ÿzOSUtils.remove_filec                 C   s   t j ||¡ d S r   )Ú
s3transferÚcompatÚrename_file)r
   Úcurrent_filenameÚnew_filenamer	   r	   r   rv   ]  s   zOSUtils.rename_fileN)r   r   r   rm   ro   rA   rs   rv   r	   r	   r	   r   ri   H  s    	ri   c                   @   sD   e Zd Zg d¢Zejjfdd„Zdd„ Zdd„ Z	dd	„ Z
d
d„ ZdS )ÚMultipartUploader)ÚSSECustomerKeyÚSSECustomerAlgorithmÚSSECustomerKeyMD5ÚRequestPayerc                 C   s   || _ || _|| _|| _d S r   )Ú_clientÚ_configÚ_osÚ_executor_cls©r
   ÚclientÚconfigÚosutilÚexecutor_clsr	   r	   r   r?   k  s   
zMultipartUploader.__init__c                 C   s,   i }|  ¡ D ]\}}|| jv r|||< q|S r   )ÚitemsÚUPLOAD_PART_ARGS)r
   Ú
extra_argsÚupload_parts_argsÚkeyrg   r	   r	   r   Ú_extra_upload_part_argsr  s   
€z)MultipartUploader._extra_upload_part_argsc           
   
   C   sª   | j jd||dœ|¤Ž}|d }z|  ||||||¡}W n* tyF }	 ztjddd� | j j|||d� td|d ||g¡|	f ƒ‚d }	~	ww | j j	|||d	|id
� d S )N©ÚBucketÚKeyÚUploadIdzBException raised while uploading parts, aborting multipart upload.T©Úexc_info)rŽ   r�   r�   zFailed to upload %s to %s: %sú/ÚParts)rŽ   r�   r�   ÚMultipartUploadr	   )
r~   Úcreate_multipart_uploadÚ_upload_partsÚ	ExceptionÚloggerÚdebugÚabort_multipart_uploadr   r   Úcomplete_multipart_upload)
r
   rG   Úbucketr‹   r>   r‰   ÚresponseÚ	upload_idÚpartsÚer	   r	   r   Úupload_file{  s8   
ÿÿÿÿÿÿÿ€û
þzMultipartUploader.upload_filec                 C   s®   |   |¡}g }| jj}	tt | j |¡t|	ƒ ¡ƒ}
| jj	}| j
|d��)}t | j|||||	||¡}| |td|
d ƒ¡D ]}| |¡ q=W d   ƒ |S 1 sPw   Y  |S )N©Úmax_workersé   )rŒ   r   Úmultipart_chunksizeÚintÚmathÚceilr€   rm   ÚfloatÚmax_concurrencyr�   Ú	functoolsÚpartialÚ_upload_one_partÚmapr   Úappend)r
   rŸ   rG   r�   r‹   r>   r‰   Úupload_parts_extra_argsr    Ú	part_sizeÚ	num_partsr¤   ÚexecutorÚupload_partialÚpartr	   r	   r   r—   Ž  s&   
ÿþÿ
üúzMultipartUploader._upload_partsc	              	   C   sr   | j j}	|	|||d  ||ƒ� }
| jjd|||||
dœ|¤Ž}|d }||dœW  d   ƒ S 1 s2w   Y  d S )Nr¥   )rŽ   r�   r�   Ú
PartNumberÚBodyÚETag)r¹   r·   r	   )r€   ro   r~   Úupload_part)r
   rG   r�   r‹   rŸ   r²   r‰   r>   Úpart_numberÚopen_chunk_readerr%   rž   Úetagr	   r	   r   r®   ž  s   ÿþý$ùz"MultipartUploader._upload_one_partN)r   r   r   rˆ   Ú
concurrentÚfuturesÚThreadPoolExecutorr?   rŒ   r¢   r—   r®   r	   r	   r	   r   ry   a  s    
ÿ	ry   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚShutdownQueueaY  A queue implementation that can be shutdown.

    Shutting down a queue means that this class adds a
    trigger_shutdown method that will trigger all subsequent
    calls to put() to fail with a ``QueueShutdownError``.

    It purposefully deviates from queue.Queue, and is *not* meant
    to be a drop in replacement for ``queue.Queue``.

    c                 C   s   d| _ t ¡ | _tj | |¡S rW   )Ú	_shutdownÚ	threadingÚLockÚ_shutdown_lockÚqueueÚQueueÚ_init)r
   Úmaxsizer	   r	   r   rÈ   ·  s   
zShutdownQueue._initc                 C   s<   | j � d| _t d¡ W d   ƒ d S 1 sw   Y  d S )NTzThe IO queue is now shutdown.)rÅ   rÂ   r™   rš   rU   r	   r	   r   Útrigger_shutdown½  s   "þzShutdownQueue.trigger_shutdownc                 C   sB   | j � | jrtdƒ‚W d   ƒ n1 sw   Y  tj | |¡S )Nz6Cannot put item to queue when queue has been shutdown.)rÅ   rÂ   r.   rÆ   rÇ   Úput)r
   Úitemr	   r	   r   rË   Â  s   ÿÿzShutdownQueue.putN)r   r   r   rh   rÈ   rÊ   rË   r	   r	   r	   r   rÁ   ¬  s
    
rÁ   c                   @   sP   e Zd Zejjfdd„Z	ddd„Zdd„ Zdd	„ Z	d
d„ Z
dd„ Zdd„ ZdS )ÚMultipartDownloaderc                 C   s*   || _ || _|| _|| _t| jjƒ| _d S r   )r~   r   r€   r�   rÁ   Úmax_io_queueÚ_ioqueuer‚   r	   r	   r   r?   Í  s
   zMultipartDownloader.__init__Nc              	   C   sŒ   | j dd��6}t | j|||||¡}| |¡}	t | j|¡}
| |
¡}tjj|	|gtjj	d�}|  
|¡ W d   ƒ d S 1 s?w   Y  d S )Né   r£   )Úreturn_when)r�   r¬   r­   Ú_download_file_as_futureÚsubmitÚ_perform_io_writesr¾   r¿   ÚwaitÚFIRST_EXCEPTIONÚ_process_future_results)r
   r�   r‹   rG   Úobject_sizer‰   r>   Ú
controllerÚdownload_parts_handlerÚparts_futureÚio_writes_handlerÚ	io_futureÚresultsr	   r	   r   Údownload_fileÕ  s    
þ
ÿ
þ"òz!MultipartDownloader.download_filec                 C   s   |\}}|D ]}|  ¡  qd S r   )Úresult)r
   r¿   ÚfinishedÚ
unfinishedÚfuturer	   r	   r   r×   ç  s   
ÿz+MultipartDownloader._process_future_resultsc              	   C   s²   | j j}tt |t|ƒ ¡ƒ}| j j}t | j	||||||¡}	z2| j
|d��}
t|
 |	t|ƒ¡ƒ W d   ƒ n1 s;w   Y  W | j t¡ d S W | j t¡ d S | j t¡ w )Nr£   )r   r¦   r§   r¨   r©   rª   r«   r¬   r­   Ú_download_ranger�   Úlistr¯   r   rÏ   rË   ÚSHUTDOWN_SENTINEL)r
   r�   r‹   rG   rØ   r>   r²   r³   r¤   Údownload_partialr´   r	   r	   r   rÒ   ì  s   
þÿýz,MultipartDownloader._download_file_as_futurec                 C   s6   || }||d krd}n|| d }d||f }|S )Nr¥   r   zbytes=%s-%sr	   )r
   r²   Ú
part_indexr³   Ústart_rangeÚ	end_rangeÚrange_paramr	   r	   r   Ú_calculate_range_paramú  s   z*MultipartDownloader._calculate_range_paramc                    s
  z}|   |||¡}| jj}	d }
t|	ƒD ]g}zAt d¡ | jj|||d�}t|d |ƒ‰d‰ || }t	‡ ‡fdd„dƒD ]}| j
 ||f¡ |t|ƒ7 }q:W  W t d|¡ d S  tjtjttfyy } ztjd	|||	d
d� |}
W Y d }~qd }~ww t|
ƒ‚t d|¡ w )NzMaking get_object call.)rŽ   r�   ÚRanger¸   i @  c                      s
   ˆ  ˆ ¡S r   ©rM   r	   ©Úbuffer_sizeÚstreaming_bodyr	   r   Ú<lambda>  ó   
 z5MultipartDownloader._download_range.<locals>.<lambda>ó    z$EXITING _download_range for part: %súCRetrying exception caught (%s), retrying request, (attempt %s / %s)Tr‘   )rì   r   Únum_download_attemptsr   r™   rš   r~   Ú
get_objectrd   ra   rÏ   rË   rN   ÚsocketÚtimeoutÚerrorr   r   r   )r
   r�   r‹   rG   r²   r³   r>   rè   rë   Úmax_attemptsÚlast_exceptionÚirž   Úcurrent_indexÚchunkr¡   r	   rï   r   rä     sJ   ÿ
ÿÿÿ

÷ÿþ€úz#MultipartDownloader._download_rangec                 C   s¬   | j  |d¡�E}	 | j ¡ }|tu r t d¡ 	 W d   ƒ d S z|\}}| |¡ | |¡ W n t	yJ } ztjd|dd� | j 
¡  ‚ d }~ww q	1 sOw   Y  d S )NÚwbTzCShutdown sentinel received in IO handler, shutting down IO handler.z!Caught exception in IO thread: %sr‘   )r€   rA   rÏ   Úgetræ   r™   rš   r7   Úwriter˜   rÊ   )r
   rG   rH   ÚtaskÚoffsetrQ   r¡   r	   r	   r   rÔ   $  s*   

ú
ÿ
€üõÿz&MultipartDownloader._perform_io_writesr   )r   r   r   r¾   r¿   rÀ   r?   rß   r×   rÒ   rì   rä   rÔ   r	   r	   r	   r   rÍ   Ì  s    
ÿ	
ÿ	!rÍ   c                   @   s(   e Zd Zde dde ddfdd„ZdS )ÚTransferConfigr   é
   é   éd   c                 C   s"   || _ || _|| _|| _|| _d S r   )Úmultipart_thresholdr«   r¦   rö   rÎ   )r
   r	  r«   r¦   rö   rÎ   r	   r	   r   r?   9  s
   
zTransferConfig.__init__N)r   r   r   ÚMBr?   r	   r	   r	   r   r  8  s    ûr  c                   @   s€   e Zd Zg d¢Zg d¢Zddd„Z	ddd„Zdd	„ Z		dd
d„Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )Ú
S3Transfer)Ú	VersionIdr{   rz   r|   r}   )ÚACLÚCacheControlÚContentDispositionÚContentEncodingÚContentLanguageÚContentTypeÚExpiresÚGrantFullControlÚ	GrantReadÚGrantReadACPÚGrantWriteACLÚMetadatar}   ÚServerSideEncryptionÚStorageClassr{   rz   r|   ÚSSEKMSKeyIdÚSSEKMSEncryptionContextÚTaggingNc                 C   s2   || _ |d u r
tƒ }|| _|d u rtƒ }|| _d S r   )r~   r  r   ri   Ú_osutil)r
   rƒ   r„   r…   r	   r	   r   r?   h  s   
zS3Transfer.__init__c                 C   s„   |du ri }|   || j¡ | jjj}|jdtdd� |jdtdd� | j	 
|¡| jjkr7|  |||||¡ dS |  |||||¡ dS )zµUpload a file to an S3 object.

        Variants have also been injected into S3 client, Bucket and Object.
        You don't have to use S3Transfer.upload_file() directly.
        Nzrequest-created.s3zs3upload-callback-disable)Ú	unique_idzs3upload-callback-enable)Ú_validate_all_known_argsÚALLOWED_UPLOAD_ARGSr~   ÚmetaÚeventsÚregister_firstr*   Úregister_lastr-   r  rm   r   r	  Ú_multipart_uploadÚ_put_object)r
   rG   r�   r‹   r>   r‰   r#  r	   r	   r   r¢   q  s"   
þþ
ÿzS3Transfer.upload_filec                 C   s`   | j j}||d| j  |¡|d��}| jjd|||dœ|¤Ž W d   ƒ d S 1 s)w   Y  d S )Nr   )r>   )rŽ   r�   r¸   r	   )r  ro   rm   r~   Ú
put_object)r
   rG   r�   r‹   r>   r‰   r¼   r%   r	   r	   r   r'  ˆ  s   
þÿ"ýzS3Transfer._put_objectc                 C   s�   |du ri }|   || j¡ |  |||¡}|tj tƒ  }z|  ||||||¡ W n ty>   tj	d|dd� | j
 |¡ ‚ w | j
 ||¡ dS )z¹Download an S3 object to a file.

        Variants have also been injected into S3 client, Bucket and Object.
        You don't have to use S3Transfer.download_file() directly.
        Nz<Exception caught in download_file, removing partial file: %sTr‘   )r   ÚALLOWED_DOWNLOAD_ARGSÚ_object_sizerB   Úextsepr   Ú_download_filer˜   r™   rš   r  rs   rv   )r
   r�   r‹   rG   r‰   r>   rØ   Útemp_filenamer	   r	   r   rß   ’  s"   
ÿÿüzS3Transfer.download_filec                 C   s:   || j jkr|  ||||||¡ d S |  |||||¡ d S r   )r   r	  Ú_ranged_downloadÚ_get_object)r
   r�   r‹   rG   rØ   r‰   r>   r	   r	   r   r,  ¬  s
   ÿzS3Transfer._download_filec                 C   s,   |D ]}||vrt d|d |¡f ƒ‚qd S )Nz/Invalid extra_args key '%s', must be one of: %sz, )Ú
ValueErrorr   )r
   ÚactualÚallowedÚkwargr	   r	   r   r   ´  s   
ÿÿÿÿÿz#S3Transfer._validate_all_known_argsc                 C   s*   t | j| j| jƒ}| ||||||¡ d S r   )rÍ   r~   r   r  rß   )r
   r�   r‹   rG   rØ   r‰   r>   Ú
downloaderr	   r	   r   r.  ¼  s   
ÿÿzS3Transfer._ranged_downloadc           
      C   s‚   | j j}d }t|ƒD ]2}z|  |||||¡W   S  tjtjttfy< }	 zt	j
d|	||dd� |	}W Y d }	~	q
d }	~	ww t|ƒ‚)Nrõ   Tr‘   )r   rö   r   Ú_do_get_objectrø   rù   rú   r   r   r™   rš   r   )
r
   r�   r‹   rG   r‰   r>   rû   rü   rý   r¡   r	   r	   r   r/  Ã  s&   

ÿ
ÿþ€ø	zS3Transfer._get_objectc           	         s|   | j jd||dœ|¤Ž}t|d |ƒ‰ | j |d¡�}t‡ fdd„dƒD ]}| |¡ q$W d   ƒ d S 1 s7w   Y  d S )Nr�   r¸   r   c                      s
   ˆ   d¡S )Ni    rî   r	   ©rñ   r	   r   rò   Ü  ró   z+S3Transfer._do_get_object.<locals>.<lambda>rô   r	   )r~   r÷   rd   r  rA   ra   r  )	r
   r�   r‹   rG   r‰   r>   rž   rH   rÿ   r	   r6  r   r5  Ö  s   ÿÿÿ"ÿzS3Transfer._do_get_objectc                 C   s   | j jd||dœ|¤Žd S )Nr�   ÚContentLengthr	   )r~   Úhead_object)r
   r�   r‹   r‰   r	   r	   r   r*  ß  s   ÿÿÿzS3Transfer._object_sizec                 C   s(   t | j| j| jƒ}| |||||¡ d S r   )ry   r~   r   r  r¢   )r
   rG   r�   r‹   r>   r‰   Úuploaderr	   r	   r   r&  ã  s   zS3Transfer._multipart_upload)NN)r   r   r   r)  r!  r?   r¢   r'  rß   r,  r   r.  r/  r5  r*  r&  r	   r	   r	   r   r  F  s"    


ÿ

ÿ	r  )r   )1rh   rB   r¨   r¬   Úloggingrø   rÃ   r   r   Úconcurrent.futuresr¾   Úbotocore.compatr   Úurllib3.exceptionsr   Úbotocore.exceptionsr   Ús3transfer.compatrt   Ús3transfer.exceptionsr   r   Ú
__author__Ú__version__ÚHandlerr   Ú	getLoggerr   r™   Ú
addHandlerÚmovesrÆ   r
  Úobjectræ   r   r*   r-   r˜   r.   r/   rd   ri   ry   rÇ   rÁ   rÍ   r  r  r	   r	   r	   r   Ú<module>   sH   q

 K l