B -<`@fã@s ddlmZddlmZddlmZmZddlmZddlmZdd„Z dd „Z d d „Z d d „Z dd„Z dd„Zd1dd„Zd2dd„Zd3dd„Zd4dd„Zd5dd„Zd6dd„Zd7dd „Zd8d!d"„Zd9d#d$„Zd:d%d&„Zd;d'd(„Zdd-d.„Zd?d/d0„ZdS)@é)Ú ClientError)Úcreate_transfer_manager)ÚTransferConfigÚ S3Transfer)ÚProgressCallbackInvoker)ÚutilscKsJt |dt¡t |dt¡t |dt¡t |dt¡t |dt¡dS)NÚ upload_fileÚ download_fileÚcopyÚupload_fileobjÚdownload_fileobj)rÚinject_attributerr r r r )Úclass_attributesÚkwargs©rú6/tmp/pip-target-7cdyy134/lib/python/boto3/s3/inject.pyÚinject_s3_transfer_methodss rcKsXt |dt¡t |dt¡t |dt¡t |dt¡t |dt¡t |dt¡dS)NÚloadrr r r r )rr Ú bucket_loadÚbucket_upload_fileÚbucket_download_fileÚ bucket_copyÚbucket_upload_fileobjÚbucket_download_fileobj)rrrrrÚinject_bucket_methodss  rcKsJt |dt¡t |dt¡t |dt¡t |dt¡t |dt¡dS)Nrr r r r )rr Úobject_upload_fileÚobject_download_fileÚ object_copyÚobject_upload_fileobjÚobject_download_fileobj)rrrrrÚinject_object_methods*s  r cKst |dt¡dS)Nr)rr Úobject_summary_load)rrrrrÚinject_object_summary_methods5sr"c Os„i|j_y:|jj ¡}x(|dD]}|d|jkr ||j_Pq WWn<tk r~}z|j di¡ d¡dksn‚Wdd}~XYnXdS)z] Calls s3.Client.list_buckets() to update the attributes of the Bucket resource. ZBucketsÚNameÚErrorZCodeZ AccessDeniedN)ÚmetaÚdataÚclientZ list_bucketsÚnamerÚresponseÚget)ÚselfÚargsrr)Z bucket_dataÚerrrr9s   rcOs8|jjj|j|jd�}d|kr,| d¡|d<||j_dS)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,rr)rrrr!Qs r!Nc Cs*t||ƒ�}|j|||||d�SQRXdS)aü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 `. :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. :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Úbucketr2Ú extra_argsÚcallbackN)rr)r+ÚFilenamer.r/Ú ExtraArgsÚCallbackÚConfigÚtransferrrrr]s# rc Cs*t||ƒ�}|j|||||d�SQRXdS)aDownload 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 `. :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. :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. )r5r2r4r6r7N)rr )r+r.r/r8r9r:r;r<rrrr †s# r cCs|jjj||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 `. :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. :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. )r8r.r/r9r:r;)r%r'rr()r+r8r/r9r:r;rrrr¯s rcCs|jjj|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 `. :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. :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/r8r9r:r;)r%r'r r()r+r/r8r9r:r;rrrrÔs rcCs|jjj||j|j|||d�S)abUpload 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 `. :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. :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. )r8r.r/r9r:r;)r%r'rr1r2)r+r8r9r:r;rrrrùs rcCs|jjj|j|j||||d�S)aoDownload 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 `. :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. :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/r8r9r:r;)r%r'r r1r2)r+r8r9r:r;rrrrs rc Cs\d}|dk rt|ƒg}|} | dkr(tƒ} t|| ƒ� } | j||||||d�} |  ¡SQRXdS)aoCopy 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 :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_sourcer5r2r6Ú subscribersZ source_client)rrrr Úresult) r+Ú CopySourcer.r/r9r:Ú SourceClientr;r=ÚconfigÚmanagerÚfuturerrrr =s1  r c Cs|jjj||j|||||d�S)aGCopy 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 :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. )r?r.r/r9r:r@r;)r%r'r r()r+r?r/r9r:r@r;rrrr~s/ rc Cs |jjj||j|j||||d�S)aCopy 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 :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. )r?r.r/r9r:r@r;)r%r'r r1r2)r+r?r9r:r@r;rrrr²s- rc Cslt|dƒstdƒ‚d}|dk r(t|ƒg}|}|dkr:tƒ}t||ƒ�} | j|||||d�} |  ¡SQRXdS)aNUpload 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. :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. ÚreadzFileobj must implement readN)Úfileobjr5r2r6r=)ÚhasattrÚ ValueErrorrrrÚuploadr>) r+ÚFileobjr.r/r9r:r;r=rArBrCrrrr ås'    r cCs|jjj||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. :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. )rIr.r/r9r:r;)r%r'r r()r+rIr/r9r:r;rrrrs% rcCs|jjj||j|j|||d�S)aü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. :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. )rIr.r/r9r:r;)r%r'r r1r2)r+rIr9r:r;rrrrHs# rc Cslt|dƒstdƒ‚d}|dk r(t|ƒg}|}|dkr:tƒ}t||ƒ�} | j|||||d�} |  ¡SQRXdS)avDownload 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. :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. ÚwritezFileobj must implement writeN)r5r2rEr6r=)rFrGrrrÚdownloadr>) r+r.r/rIr9r:r;r=rArBrCrrrr ps'    r cCs|jjj|j|||||d�S)aMDownload 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. :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.r/rIr9r:r;)r%r'r r()r+r/rIr9r:r;rrrr©s% rcCs|jjj|j|j||||d�S)aDownload 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. :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.r/rIr9r:r;)r%r'r r1r2)r+rIr9r:r;rrrrÓs# r)NNN)NNN)NNN)NNN)NNN)NNN)NNNN)NNNN)NNNN)NNN)NNN)NNN)NNN)NNN)NNN)Zbotocore.exceptionsrZboto3.s3.transferrrrrZboto3rrrr r"rr!rr rrrrr rrr rrr rrrrrrÚ sH         ( ) % % " ! @ 3 2 8 ) ' 8 )