U
    ´.¬b�m  ã                   @   sú   d dl mZ d dlmZ d dlmZmZmZmZ dd„ Z	dd„ Z
dd	„ Zd
d„ Zdd„ Zdd„ Zd/dd„Zd0dd„Zd1dd„Zd2dd„Zd3dd„Zd4dd„Zd5dd„Zd6dd „Zd7d!d"„Zd8d#d$„Zd9d%d&„Zd:d'd(„Zd;d)d*„Zd<d+d,„Zd=d-d.„ZdS )>é    )ÚClientError)Úutils)ÚProgressCallbackInvokerÚ
S3TransferÚTransferConfigÚcreate_transfer_managerc                 K   sJ   t  | dt¡ t  | dt¡ t  | dt¡ t  | dt¡ t  | dt¡ d S ©NÚupload_fileÚdownload_fileÚcopyÚupload_fileobjÚdownload_fileobj)r   Úinject_attributer	   r
   r   r   r   ©Zclass_attributesÚkwargs© r   ú3/tmp/pip-unpacked-wheel-7h_bjh9e/boto3/s3/inject.pyÚinject_s3_transfer_methods   s      ÿr   c                 K   sX   t  | dt¡ t  | dt¡ t  | dt¡ t  | dt¡ t  | dt¡ t  | dt¡ d S )NÚloadr	   r
   r   r   r   )r   r   Úbucket_loadÚbucket_upload_fileÚbucket_download_fileÚbucket_copyÚbucket_upload_fileobjÚbucket_download_fileobjr   r   r   r   Úinject_bucket_methods"   s$      ÿ  ÿ  ÿr   c                 K   sJ   t  | dt¡ t  | dt¡ t  | dt¡ t  | dt¡ t  | dt¡ d S r   )r   r   Úobject_upload_fileÚobject_download_fileÚobject_copyÚobject_upload_fileobjÚobject_download_fileobjr   r   r   r   Úinject_object_methods1   s"      ÿ  ÿ  ÿr!   c                 K   s   t  | dt¡ d S )Nr   )r   r   Úobject_summary_loadr   r   r   r   Úinject_object_summary_methods?   s    r#   c              
   O   s‚   i | j _z8| j j ¡ }|d D ]}|d | jkr|| j _ q>qW n< tk
r| } z|j di ¡ d¡dksl‚ W 5 d}~X Y nX dS )z]
    Calls s3.Client.list_buckets() to update the attributes of the Bucket
    resource.
    ZBucketsÚNameÚErrorZCodeZAccessDeniedN)ÚmetaÚdataÚclientZlist_bucketsÚnamer   ÚresponseÚget)ÚselfÚargsr   r*   Zbucket_dataÚer   r   r   r   C   s    
r   c                 O   s8   | j jj| j| jd�}d|kr,| d¡|d< || j _dS )za
    Calls s3.Client.head_object to update the attributes of the ObjectSummary
    resource.
    )ÚBucketÚKeyZContentLengthÚSizeN)r&   r(   Zhead_objectÚbucket_nameÚkeyÚpopr'   )r,   r-   r   r*   r   r   r   r"   \   s     ÿr"   Nc              
   C   s6   t | |ƒ�"}|j|||||d�W  5 Q R £ S Q R X dS )aW  Upload a file to an S3 object.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        s3.meta.client.upload_file('/tmp/hello.txt', 'mybucket', 'hello.txt')

    Similar behavior as S3Transfer's upload_file() method,
    except that parameters are capitalized. Detailed examples can be found at
    :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.

    :type Filename: str
    :param Filename: The path to the file to upload.

    :type Bucket: str
    :param Bucket: The name of the bucket to upload to.

    :type Key: str
    :param Key: The name of the key to upload to.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed upload arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the upload.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        transfer.
    )ÚfilenameÚbucketr3   Ú
extra_argsÚcallbackN)r   r	   )r,   ÚFilenamer/   r0   Ú	ExtraArgsÚCallbackÚConfigÚtransferr   r   r   r	   i   s    %ûr	   c              
   C   s6   t | |ƒ�"}|j|||||d�W  5 Q R £ S Q R X dS )ap  Download an S3 object to a file.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        s3.meta.client.download_file('mybucket', 'hello.txt', '/tmp/hello.txt')

    Similar behavior as S3Transfer's download_file() method,
    except that parameters are capitalized. Detailed examples can be found at
    :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.

    :type Bucket: str
    :param Bucket: The name of the bucket to download from.

    :type Key: str
    :param Key: The name of the key to download from.

    :type Filename: str
    :param Filename: The path to the file to download to.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed download arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the download.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        transfer.
    )r6   r3   r5   r7   r8   N)r   r
   )r,   r/   r0   r9   r:   r;   r<   r=   r   r   r   r
   ˜   s    %ûr
   c                 C   s   | j jj|| j||||d�S )a  Upload a file to an S3 object.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        s3.Bucket('mybucket').upload_file('/tmp/hello.txt', 'hello.txt')

    Similar behavior as S3Transfer's upload_file() method,
    except that parameters are capitalized. Detailed examples can be found at
    :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.

    :type Filename: str
    :param Filename: The path to the file to upload.

    :type Key: str
    :param Key: The name of the key to upload to.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed upload arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the upload.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        transfer.
    ©r9   r/   r0   r:   r;   r<   )r&   r(   r	   r)   )r,   r9   r0   r:   r;   r<   r   r   r   r   Ç   s    "úr   c                 C   s   | j jj| j|||||d�S )a  Download an S3 object to a file.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        s3.Bucket('mybucket').download_file('hello.txt', '/tmp/hello.txt')

    Similar behavior as S3Transfer's download_file() method,
    except that parameters are capitalized. Detailed examples can be found at
    :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.

    :type Key: str
    :param Key: The name of the key to download from.

    :type Filename: str
    :param Filename: The path to the file to download to.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed download arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the download.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        transfer.
    ©r/   r0   r9   r:   r;   r<   )r&   r(   r
   r)   )r,   r0   r9   r:   r;   r<   r   r   r   r   ó   s    "úr   c                 C   s   | j jj|| j| j|||d�S )a½  Upload a file to an S3 object.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        s3.Object('mybucket', 'hello.txt').upload_file('/tmp/hello.txt')

    Similar behavior as S3Transfer's upload_file() method,
    except that parameters are capitalized. Detailed examples can be found at
    :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.

    :type Filename: str
    :param Filename: The path to the file to upload.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed upload arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the upload.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        transfer.
    r>   )r&   r(   r	   r2   r3   ©r,   r9   r:   r;   r<   r   r   r   r     s    úr   c                 C   s   | j jj| j| j||||d�S )aÎ  Download an S3 object to a file.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        s3.Object('mybucket', 'hello.txt').download_file('/tmp/hello.txt')

    Similar behavior as S3Transfer's download_file() method,
    except that parameters are capitalized. Detailed examples can be found at
    :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.

    :type Filename: str
    :param Filename: The path to the file to download to.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed download arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the download.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        transfer.
    r?   )r&   r(   r
   r2   r3   r@   r   r   r   r   H  s    úr   c              
   C   sh   d}|dk	rt |ƒg}|}	|	dkr(tƒ }	t| |	ƒ�,}
|
j||||||d�}| ¡ W  5 Q R £ S Q R X dS )aÏ  Copy an object from one S3 location to another.

    This is a managed transfer which will perform a multipart copy in
    multiple threads if necessary.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        copy_source = {
            'Bucket': 'mybucket',
            'Key': 'mykey'
        }
        s3.meta.client.copy(copy_source, 'otherbucket', 'otherkey')

    :type CopySource: dict
    :param CopySource: The name of the source bucket, key name of the
        source object, and optional version ID of the source object. The
        dictionary format is:
        ``{'Bucket': 'bucket', 'Key': 'key', 'VersionId': 'id'}``. Note
        that the ``VersionId`` key is optional and may be omitted.

    :type Bucket: str
    :param Bucket: The name of the bucket to copy to

    :type Key: str
    :param Key: The name of the key to copy to

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed download arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the copy.

    :type SourceClient: botocore or boto3 Client
    :param SourceClient: The client to be used for operation that
        may happen at the source object. For example, this client is
        used for the head_object that determines the size of the copy.
        If no client is provided, the current client is used as the client
        for the source object.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        copy.
    N)Zcopy_sourcer6   r3   r7   ÚsubscribersZsource_client)r   r   r   r   Úresult)r,   Ú
CopySourcer/   r0   r:   r;   ÚSourceClientr<   rA   ÚconfigÚmanagerÚfuturer   r   r   r   q  s     :
úr   c              	   C   s   | j jj|| j|||||d�S )a§  Copy an object from one S3 location to an object in this bucket.

    This is a managed transfer which will perform a multipart copy in
    multiple threads if necessary.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        copy_source = {
            'Bucket': 'mybucket',
            'Key': 'mykey'
        }
        bucket = s3.Bucket('otherbucket')
        bucket.copy(copy_source, 'otherkey')

    :type CopySource: dict
    :param CopySource: The name of the source bucket, key name of the
        source object, and optional version ID of the source object. The
        dictionary format is:
        ``{'Bucket': 'bucket', 'Key': 'key', 'VersionId': 'id'}``. Note
        that the ``VersionId`` key is optional and may be omitted.

    :type Key: str
    :param Key: The name of the key to copy to

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed download arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the copy.

    :type SourceClient: botocore or boto3 Client
    :param SourceClient: The client to be used for operation that
        may happen at the source object. For example, this client is
        used for the head_object that determines the size of the copy.
        If no client is provided, the current client is used as the client
        for the source object.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        copy.
    ©rC   r/   r0   r:   r;   rD   r<   )r&   r(   r   r)   )r,   rC   r0   r:   r;   rD   r<   r   r   r   r   ¿  s    7ùr   c              	   C   s    | j jj|| j| j||||d�S )ap  Copy an object from one S3 location to this object.

    This is a managed transfer which will perform a multipart copy in
    multiple threads if necessary.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        copy_source = {
            'Bucket': 'mybucket',
            'Key': 'mykey'
        }
        bucket = s3.Bucket('otherbucket')
        obj = bucket.Object('otherkey')
        obj.copy(copy_source)

    :type CopySource: dict
    :param CopySource: The name of the source bucket, key name of the
        source object, and optional version ID of the source object. The
        dictionary format is:
        ``{'Bucket': 'bucket', 'Key': 'key', 'VersionId': 'id'}``. Note
        that the ``VersionId`` key is optional and may be omitted.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed download arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the copy.

    :type SourceClient: botocore or boto3 Client
    :param SourceClient: The client to be used for operation that
        may happen at the source object. For example, this client is
        used for the head_object that determines the size of the copy.
        If no client is provided, the current client is used as the client
        for the source object.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        copy.
    rH   )r&   r(   r   r2   r3   )r,   rC   r:   r;   rD   r<   r   r   r   r     s    4ùr   c              
   C   sx   t |dƒstdƒ‚d}|dk	r(t|ƒg}|}|dkr:tƒ }t| |ƒ�*}	|	j|||||d�}
|
 ¡ W  5 Q R £ S Q R X dS )a©  Upload a file-like object to S3.

    The file-like object must be in binary mode.

    This is a managed transfer which will perform a multipart upload in
    multiple threads if necessary.

    Usage::

        import boto3
        s3 = boto3.client('s3')

        with open('filename', 'rb') as data:
            s3.upload_fileobj(data, 'mybucket', 'mykey')

    :type Fileobj: a file-like object
    :param Fileobj: A file-like object to upload. At a minimum, it must
        implement the `read` method, and must return bytes.

    :type Bucket: str
    :param Bucket: The name of the bucket to upload to.

    :type Key: str
    :param Key: The name of the key to upload to.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed upload arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the upload.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        upload.
    ÚreadzFileobj must implement readN)Úfileobjr6   r3   r7   rA   )ÚhasattrÚ
ValueErrorr   r   r   ÚuploadrB   )r,   ÚFileobjr/   r0   r:   r;   r<   rA   rE   rF   rG   r   r   r   r   @  s"    )

ûr   c                 C   s   | j jj|| j||||d�S )a„  Upload a file-like object to this bucket.

    The file-like object must be in binary mode.

    This is a managed transfer which will perform a multipart upload in
    multiple threads if necessary.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        bucket = s3.Bucket('mybucket')

        with open('filename', 'rb') as data:
            bucket.upload_fileobj(data, 'mykey')

    :type Fileobj: a file-like object
    :param Fileobj: A file-like object to upload. At a minimum, it must
        implement the `read` method, and must return bytes.

    :type Key: str
    :param Key: The name of the key to upload to.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed upload arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the upload.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        upload.
    ©rN   r/   r0   r:   r;   r<   )r&   r(   r   r)   )r,   rN   r0   r:   r;   r<   r   r   r   r     s    'úr   c                 C   s   | j jj|| j| j|||d�S )aW  Upload a file-like object to this object.

    The file-like object must be in binary mode.

    This is a managed transfer which will perform a multipart upload in
    multiple threads if necessary.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        bucket = s3.Bucket('mybucket')
        obj = bucket.Object('mykey')

        with open('filename', 'rb') as data:
            obj.upload_fileobj(data)

    :type Fileobj: a file-like object
    :param Fileobj: A file-like object to upload. At a minimum, it must
        implement the `read` method, and must return bytes.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed upload arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the upload.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        upload.
    rO   )r&   r(   r   r2   r3   ©r,   rN   r:   r;   r<   r   r   r   r   °  s    %úr   c              
   C   sx   t |dƒstdƒ‚d}|dk	r(t|ƒg}|}|dkr:tƒ }t| |ƒ�*}	|	j|||||d�}
|
 ¡ W  5 Q R £ S Q R X dS )aÕ  Download an object from S3 to a file-like object.

    The file-like object must be in binary mode.

    This is a managed transfer which will perform a multipart download in
    multiple threads if necessary.

    Usage::

        import boto3
        s3 = boto3.client('s3')

        with open('filename', 'wb') as data:
            s3.download_fileobj('mybucket', 'mykey', data)

    :type Bucket: str
    :param Bucket: The name of the bucket to download from.

    :type Key: str
    :param Key: The name of the key to download from.

    :type Fileobj: a file-like object
    :param Fileobj: A file-like object to download into. At a minimum, it must
        implement the `write` method and must accept bytes.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed download arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the download.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        download.
    ÚwritezFileobj must implement writeN)r6   r3   rJ   r7   rA   )rK   rL   r   r   r   ÚdownloadrB   )r,   r/   r0   rN   r:   r;   r<   rA   rE   rF   rG   r   r   r   r   ß  s"    )

ûr   c                 C   s   | j jj| j|||||d�S )a¬  Download an object from this bucket to a file-like-object.

    The file-like object must be in binary mode.

    This is a managed transfer which will perform a multipart download in
    multiple threads if necessary.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        bucket = s3.Bucket('mybucket')

        with open('filename', 'wb') as data:
            bucket.download_fileobj('mykey', data)

    :type Fileobj: a file-like object
    :param Fileobj: A file-like object to download into. At a minimum, it must
        implement the `write` method and must accept bytes.

    :type Key: str
    :param Key: The name of the key to download from.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed download arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the download.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        download.
    ©r/   r0   rN   r:   r;   r<   )r&   r(   r   r)   )r,   r0   rN   r:   r;   r<   r   r   r   r     s    'úr   c                 C   s   | j jj| j| j||||d�S )at  Download this object from S3 to a file-like object.

    The file-like object must be in binary mode.

    This is a managed transfer which will perform a multipart download in
    multiple threads if necessary.

    Usage::

        import boto3
        s3 = boto3.resource('s3')
        bucket = s3.Bucket('mybucket')
        obj = bucket.Object('mykey')

        with open('filename', 'wb') as data:
            obj.download_fileobj(data)

    :type Fileobj: a file-like object
    :param Fileobj: A file-like object to download into. At a minimum, it must
        implement the `write` method and must accept bytes.

    :type ExtraArgs: dict
    :param ExtraArgs: Extra arguments that may be passed to the
        client operation. For allowed download arguments see
        boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.

    :type Callback: function
    :param Callback: A method which takes a number of bytes transferred to
        be periodically called during the download.

    :type Config: boto3.s3.transfer.TransferConfig
    :param Config: The transfer configuration to be used when performing the
        download.
    rS   )r&   r(   r   r2   r3   rP   r   r   r   r    O  s    %úr    )NNN)NNN)NNN)NNN)NNN)NNN)NNNN)NNNN)NNNN)NNN)NNN)NNN)NNN)NNN)NNN)Zbotocore.exceptionsr   Zboto3r   Zboto3.s3.transferr   r   r   r   r   r   r!   r#   r   r"   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r   r   Ú<module>   sŽ   
     ÿ
0     ÿ
0     ÿ
-     ÿ
-     ÿ
*     ÿ
.    ø
R    ù
E    ú
@     ÿ
@     ÿ
2     ÿ
0     ÿ
@     ÿ
2     ÿ