U
    W+d7                    @   sz  d dl Z d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dl m!Z! d dl"m#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.m/Z/m0Z0m1Z1 G dd de2Z3dddddgZ4G dd de2Z5dS )     N)handler)	ResultSet)BotoClientError)PolicyCannedACLStringsGrant)Key)Prefix)DeleteMarker)MultiPartUpload)CompleteMultiPartUpload)MultiDeleteResult)ErrorBucketListResultSetVersionedBucketListResultSetMultiPartUploadListResultSet)	Lifecycle)Tags)CORSConfiguration)BucketLogging)website)defaultdict)BytesIOsixStringIOurllibc                   @   sl   e Zd Zedd Zded< ded< ded< d	ed
< ded< ded< ded< ded< ded< edd ZdS )S3WebsiteEndpointTranslatec                   C   s   dS )Nzs3-website-us-east-1 r    r    r    2/tmp/pip-unpacked-wheel-dlxw5sjy/boto/s3/bucket.py<lambda>:       z#S3WebsiteEndpointTranslate.<lambda>zs3-website-eu-west-1z	eu-west-1zs3-website.eu-central-1zeu-central-1zs3-website-us-west-1z	us-west-1zs3-website-us-west-2z	us-west-2zs3-website-sa-east-1z	sa-east-1zs3-website-ap-northeast-1zap-northeast-1zs3-website-ap-southeast-1zap-southeast-1zs3-website-ap-southeast-2zap-southeast-2zs3-website.cn-north-1z
cn-north-1c                 C   s
   | j | S N)trans_region)selfregr    r    r!   translate_regionE   s    z+S3WebsiteEndpointTranslate.translate_regionN)__name__
__module____qualname__r   r%   classmethodr(   r    r    r    r!   r   8   s   r   READWRITEREAD_ACPZ	WRITE_ACPZFULL_CONTROLc                   @   s
  e Zd ZdZdZdZdZdZddefddZ	d	d
 Z
dd Zdd Zdd Zdd Zdd ZdddZdddZdd ZdddZddd Zdd!d"Zdd#d$Zdd%d&Zd'd( Zdd)d*Zdd+d,Zd-d. Zdd/d0Zdd1d2Zdd5d6Zdd7d8Zdd9d:Z dd;d<Z!dd>d?Z"dd@dAZ#ddBdCZ$ddEdFZ%ddGdHZ&ddIdJZ'ddKdLZ(ddMdNZ)ddOdPZ*ddQdRZ+ddSdTZ,ddUdVZ-ddWdXZ.ddYdZZ/dd[d\Z0dd]d^Z1dd_d`Z2ddadbZ3ddcddZ4ddfdgZ5ddhdiZ6ddjdkZ7ddldmZ8ddndoZ9ddpdqZ:ddrdsZ;ddtduZ<ddvdwZ=ddxdyZ>ddzd{Z?dd|d}Z@dd~dZAdddZBdd ZCdddZDdddZEdddZFdddZGdddZHdddZIdddZJdddZKdddZLdddZMdddZNdddZOdddZPdddZQdddZRdddZSdddZTdS )Bucketz.http://acs.amazonaws.com/groups/s3/LogDeliveryz<?xml version="1.0" encoding="UTF-8"?>
       <RequestPaymentConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
         <Payer>%s</Payer>
       </RequestPaymentConfiguration>z<?xml version="1.0" encoding="UTF-8"?>
       <VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
         <Status>%s</Status>
         <MfaDelete>%s</MfaDelete>
       </VersioningConfiguration>z<Status>([A-Za-z]+)</Status>z"<MfaDelete>([A-Za-z]+)</MfaDelete>Nc                 C   s   || _ || _|| _d S r$   )name
connection	key_class)r&   r2   r1   r3   r    r    r!   __init__^   s    zBucket.__init__c                 C   s
   d| j  S )Nz<Bucket: %s>)r1   r&   r    r    r!   __repr__c   s    zBucket.__repr__c                 C   s   t t| S r$   )iterr   r5   r    r    r!   __iter__f   s    zBucket.__iter__c                 C   s   |  |d k	S r$   get_keyr&   key_namer    r    r!   __contains__i   s    zBucket.__contains__c                 C   s   d S r$   r    )r&   r1   attrsr2   r    r    r!   startElementl   s    zBucket.startElementc                 C   s0   |dkr|| _ n|dkr || _nt| || d S )NNameZCreationDate)r1   Zcreation_datesetattr)r&   r1   valuer2   r    r    r!   
endElemento   s
    zBucket.endElementc                 C   s
   || _ dS )a
  
        Set the Key class associated with this bucket.  By default, this
        would be the boto.s3.key.Key class but if you want to subclass that
        for some reason this allows you to associate your new class with a
        bucket so that when you call bucket.new_key() or when you get a listing
        of keys in the bucket you will get an instances of your key class
        rather than the default.

        :type key_class: class
        :param key_class: A subclass of Key that can be more specific
        N)r3   )r&   r3   r    r    r!   set_key_classw   s    zBucket.set_key_classc                 C   s   | j ||dS )z
        Deprecated: Please use get_key method.

        :type key_name: string
        :param key_name: The name of the key to retrieve

        :rtype: :class:`boto.s3.key.Key`
        :returns: A Key object from this bucket.
        headersr9   )r&   r<   rF   r    r    r!   lookup   s    
zBucket.lookupTc                 C   s   |dkr&|s|s|rt d| |S g }|r<|d|  |rnt|D ]"\}}|d|tj|f  qJ| |||\}	}
|	S )a  
        Check to see if a particular key exists within the bucket.  This
        method uses a HEAD request to check for the existence of the key.
        Returns: An instance of a Key object or None

        :param key_name: The name of the key to retrieve
        :type key_name: string

        :param headers: The headers to send when retrieving the key
        :type headers: dict

        :param version_id:
        :type version_id: string

        :param response_headers: A dictionary containing HTTP
            headers/values that will override any headers associated
            with the stored object in the response.  See
            http://goo.gl/EWOPb for details.
        :type response_headers: dict

        :param validate: Verifies whether the key exists. If ``False``, this
            will not hit the service, constructing an in-memory object.
            Default is ``True``.
        :type validate: bool

        :rtype: :class:`boto.s3.key.Key`
        :returns: A Key object from this bucket.
        Fz=When providing 'validate=False', no other params are allowed.versionId=%s%s=%s)	r   new_keyappendr   	iteritemsr   parsequote_get_key_internal)r&   r<   rF   
version_idresponse_headersvalidatequery_args_lZrkrvkeyrespr    r    r!   r:      s    
zBucket.get_keyc           
      C   s   d |pd }| jjd| j|||d}|  |jd dkr| | }| jj}tj	
|j||_tjD ] }|||j| dd< qf|d}	|	rt|d|_nd	|_||_|| || || || ||  ||fS |jd
krd |fS | jj|j|jdd S )N&HEADrF   
query_argsd      -_zcontent-lengthr   i   )joinr2   make_requestr1   readstatusr3   providerbotoutilsZget_aws_metadatamsgmetadatar   Zbase_fields	getheader__dict__lowerreplaceintsizehandle_version_headershandle_encryption_headersZhandle_restore_headersZhandle_storage_class_headerhandle_addl_headers
getheadersstorage_response_errorreason)
r&   r<   rF   rS   rZ   responsekrd   fieldclenr    r    r!   rO      s>    






  zBucket._get_key_internalr_   c                 C   s   t | |||||dS )a  
        List key objects within a bucket.  This returns an instance of an
        BucketListResultSet that automatically handles all of the result
        paging, etc. from S3.  You just need to keep iterating until
        there are no more results.

        Called with no arguments, this will return an iterator object across
        all keys within the bucket.

        The Key objects returned by the iterator are obtained by parsing
        the results of a GET on the bucket, also known as the List Objects
        request.  The XML returned by this request contains only a subset
        of the information about each key.  Certain metadata fields such
        as Content-Type and user metadata are not available in the XML.
        Therefore, if you want these additional metadata fields you will
        have to do a HEAD request on the Key in the bucket.

        :type prefix: string
        :param prefix: allows you to limit the listing to a particular
            prefix.  For example, if you call the method with
            prefix='/foo/' then the iterator will only cycle through
            the keys that begin with the string '/foo/'.

        :type delimiter: string
        :param delimiter: can be used in conjunction with the prefix
            to allow you to organize and browse your keys
            hierarchically. See http://goo.gl/Xx63h for more details.

        :type marker: string
        :param marker: The "marker" of where you are in the result set

        :param encoding_type: Requests Amazon S3 to encode the response and
            specifies the encoding method to use.

            An object key can contain any Unicode character; however, XML 1.0
            parser cannot parse some characters, such as characters with an
            ASCII value from 0 to 10. For characters that are not supported in
            XML 1.0, you can add this parameter to request that Amazon S3
            encode the keys in the response.

            Valid options: ``url``
        :type encoding_type: string

        :rtype: :class:`boto.s3.bucketlistresultset.BucketListResultSet`
        :return: an instance of a BucketListResultSet that handles paging, etc
        encoding_typer   )r&   prefix	delimitermarkerrF   rz   r    r    r!   list   s    0zBucket.listc              	   C   s   t | ||||||dS )a  
        List version objects within a bucket.  This returns an
        instance of an VersionedBucketListResultSet that automatically
        handles all of the result paging, etc. from S3.  You just need
        to keep iterating until there are no more results.  Called
        with no arguments, this will return an iterator object across
        all keys within the bucket.

        :type prefix: string
        :param prefix: allows you to limit the listing to a particular
            prefix.  For example, if you call the method with
            prefix='/foo/' then the iterator will only cycle through
            the keys that begin with the string '/foo/'.

        :type delimiter: string
        :param delimiter: can be used in conjunction with the prefix
            to allow you to organize and browse your keys
            hierarchically. See:

            http://aws.amazon.com/releasenotes/Amazon-S3/213

            for more details.

        :type key_marker: string
        :param key_marker: The "marker" of where you are in the result set

        :param encoding_type: Requests Amazon S3 to encode the response and
            specifies the encoding method to use.

            An object key can contain any Unicode character; however, XML 1.0
            parser cannot parse some characters, such as characters with an
            ASCII value from 0 to 10. For characters that are not supported in
            XML 1.0, you can add this parameter to request that Amazon S3
            encode the keys in the response.

            Valid options: ``url``
        :type encoding_type: string

        :rtype: :class:`boto.s3.bucketlistresultset.BucketListResultSet`
        :return: an instance of a BucketListResultSet that handles paging, etc
        ry   r   )r&   r{   r|   
key_markerversion_id_markerrF   rz   r    r    r!   list_versions  s    + zBucket.list_versionsc                 C   s   t | ||||dS )a  
        List multipart upload objects within a bucket.  This returns an
        instance of an MultiPartUploadListResultSet that automatically
        handles all of the result paging, etc. from S3.  You just need
        to keep iterating until there are no more results.

        :type key_marker: string
        :param key_marker: The "marker" of where you are in the result set

        :type upload_id_marker: string
        :param upload_id_marker: The upload identifier

        :param encoding_type: Requests Amazon S3 to encode the response and
            specifies the encoding method to use.

            An object key can contain any Unicode character; however, XML 1.0
            parser cannot parse some characters, such as characters with an
            ASCII value from 0 to 10. For characters that are not supported in
            XML 1.0, you can add this parameter to request that Amazon S3
            encode the keys in the response.

            Valid options: ``url``
        :type encoding_type: string

        :rtype: :class:`boto.s3.bucketlistresultset.MultiPartUploadListResultSet`
        :return: an instance of a BucketListResultSet that handles paging, etc
        ry   r   )r&   r   upload_id_markerrF   rz   r    r    r!   list_multipart_uploadsM  s
    zBucket.list_multipart_uploadsc                 C   s   g }|r| | t| dd dD ]\}}|d kr8q&|dd}|dkrPd}t|tjtjf snt|}t|tjs|	d}|r&| d	t
j|t
j|f  q&d
|S )Nc                 S   s   | d S )Nr   r    )xr    r    r!   r"   v  r#   z,Bucket._get_all_query_args.<locals>.<lambda>)rU   r^   r]   maxkeyszmax-keysutf-8rI   rW   )rK   sorteditemsrl   
isinstancer   string_typesbinary_type	text_typeencoder   rM   rN   r`   )r&   paramsinitial_query_stringpairsrU   rB   r    r    r!   _get_all_query_argsp  s&    





zBucket._get_all_query_argsc           
      K   s   | j ||d}| jjd| j||d}| }tj| |jdkr|t	|}t
|| }	t|tsj|d}tj||	 |S | jj|j|j|d S )N)r   GETrY      r   )r   r2   ra   r1   rb   re   logdebugrc   r   r   
XmlHandlerr   bytesr   xmlsaxparseStringrd   rs   rt   )
r&   Zelement_mapr   rF   r   rZ   ru   bodyrshr    r    r!   _get_all  s,    


  zBucket._get_allc                 C   s"   |D ]}||krt d| qdS )z
        Checks that all named arguments are in the specified list of names.

        :type kwargs: dict
        :param kwargs: Dictionary of kwargs to validate.

        :type names: list
        :param names: List of possible named arguments.
        zInvalid argument "%s"!N)	TypeError)r&   kwargsnameskwargr    r    r!   validate_kwarg_names  s    
zBucket.validate_kwarg_namesc              	   K   s8   |  |ddddddg | jd| jfdtfgd	|f|S )
a  
        A lower-level method for listing contents of a bucket.  This
        closely models the actual S3 API and requires you to manually
        handle the paging of results.  For a higher-level method that
        handles the details of paging for you, you can use the list
        method.

        :type max_keys: int
        :param max_keys: The maximum number of keys to retrieve

        :type prefix: string
        :param prefix: The prefix of the keys you want to retrieve

        :type marker: string
        :param marker: The "marker" of where you are in the result set

        :type delimiter: string
        :param delimiter: If this optional, Unicode string parameter
            is included with your request, then keys that contain the
            same string between the prefix and the first occurrence of
            the delimiter will be rolled up into a single result
            element in the CommonPrefixes collection. These rolled-up
            keys are not returned elsewhere in the response.

        :param encoding_type: Requests Amazon S3 to encode the response and
            specifies the encoding method to use.

            An object key can contain any Unicode character; however, XML 1.0
            parser cannot parse some characters, such as characters with an
            ASCII value from 0 to 10. For characters that are not supported in
            XML 1.0, you can add this parameter to request that Amazon S3
            encode the keys in the response.

            Valid options: ``url``
        :type encoding_type: string

        :rtype: ResultSet
        :return: The result from S3 listing the keys requested

        r   max_keysr{   r}   r|   rz   ZContentsCommonPrefixesr_   )r   r   r3   r	   r&   rF   r   r    r    r!   get_all_keys  s    )  zBucket.get_all_keysc                 K   s0   |  | | jd| jfdtfdtfgd|f|S )ah  
        A lower-level, version-aware method for listing contents of a
        bucket.  This closely models the actual S3 API and requires
        you to manually handle the paging of results.  For a
        higher-level method that handles the details of paging for
        you, you can use the list method.

        :type max_keys: int
        :param max_keys: The maximum number of keys to retrieve

        :type prefix: string
        :param prefix: The prefix of the keys you want to retrieve

        :type key_marker: string
        :param key_marker: The "marker" of where you are in the result set
            with respect to keys.

        :type version_id_marker: string
        :param version_id_marker: The "marker" of where you are in the result
            set with respect to version-id's.

        :type delimiter: string
        :param delimiter: If this optional, Unicode string parameter
            is included with your request, then keys that contain the
            same string between the prefix and the first occurrence of
            the delimiter will be rolled up into a single result
            element in the CommonPrefixes collection. These rolled-up
            keys are not returned elsewhere in the response.

        :param encoding_type: Requests Amazon S3 to encode the response and
            specifies the encoding method to use.

            An object key can contain any Unicode character; however, XML 1.0
            parser cannot parse some characters, such as characters with an
            ASCII value from 0 to 10. For characters that are not supported in
            XML 1.0, you can add this parameter to request that Amazon S3
            encode the keys in the response.

            Valid options: ``url``
        :type encoding_type: string

        :rtype: ResultSet
        :return: The result from S3 listing the keys requested
        Versionr   r
   versions) validate_get_all_versions_paramsr   r3   r	   r
   r   r    r    r!   get_all_versions  s    -
 zBucket.get_all_versionsc              
   C   s   |  |dddddddg dS )	z
        Validate that the parameters passed to get_all_versions are valid.
        Overridden by subclasses that allow a different set of parameters.

        :type params: dict
        :param params: Parameters to validate.
        r   r   r{   r   r   r|   rz   N)r   )r&   r   r    r    r!   r     s       z'Bucket.validate_get_all_versions_paramsc              	   K   s6   |  |ddddddg | jdtfdtfgd	|f|S )
a~  
        A lower-level, version-aware method for listing active
        MultiPart uploads for a bucket.  This closely models the
        actual S3 API and requires you to manually handle the paging
        of results.  For a higher-level method that handles the
        details of paging for you, you can use the list method.

        :type max_uploads: int
        :param max_uploads: The maximum number of uploads to retrieve.
            Default value is 1000.

        :type key_marker: string
        :param key_marker: Together with upload_id_marker, this
            parameter specifies the multipart upload after which
            listing should begin.  If upload_id_marker is not
            specified, only the keys lexicographically greater than
            the specified key_marker will be included in the list.

            If upload_id_marker is specified, any multipart uploads
            for a key equal to the key_marker might also be included,
            provided those multipart uploads have upload IDs
            lexicographically greater than the specified
            upload_id_marker.

        :type upload_id_marker: string
        :param upload_id_marker: Together with key-marker, specifies
            the multipart upload after which listing should begin. If
            key_marker is not specified, the upload_id_marker
            parameter is ignored.  Otherwise, any multipart uploads
            for a key equal to the key_marker might be included in the
            list only if they have an upload ID lexicographically
            greater than the specified upload_id_marker.

        :type encoding_type: string
        :param encoding_type: Requests Amazon S3 to encode the response and
            specifies the encoding method to use.

            An object key can contain any Unicode character; however, XML 1.0
            parser cannot parse some characters, such as characters with an
            ASCII value from 0 to 10. For characters that are not supported in
            XML 1.0, you can add this parameter to request that Amazon S3
            encode the keys in the response.

            Valid options: ``url``

        :type delimiter: string
        :param delimiter: Character you use to group keys.
            All keys that contain the same string between the prefix, if
            specified, and the first occurrence of the delimiter after the
            prefix are grouped under a single result element, CommonPrefixes.
            If you don't specify the prefix parameter, then the substring
            starts at the beginning of the key. The keys that are grouped
            under CommonPrefixes result element are not returned elsewhere
            in the response.

        :type prefix: string
        :param prefix: Lists in-progress uploads only for those keys that
            begin with the specified prefix. You can use prefixes to separate
            a bucket into different grouping of keys. (You can think of using
            prefix to make groups in the same way you'd use a folder in a
            file system.)

        :rtype: ResultSet
        :return: The result from S3 listing the uploads requested

        Zmax_uploadsr   r   rz   r|   r{   ZUploadr   uploads)r   r   r   r	   r   r    r    r!   get_all_multipart_uploads  s    C
  
 z Bucket.get_all_multipart_uploadsc                 C   s   |st d| | |S )z
        Creates a new key

        :type key_name: string
        :param key_name: The name of the key to create

        :rtype: :class:`boto.s3.key.Key` or subclass
        :returns: An instance of the newly created key object
        Empty key names are not allowed)
ValueErrorr3   r;   r    r    r!   rJ   e  s    
zBucket.new_keyr   Fc              	   C   s   | j j||| j||||dS )N)rF   
force_httprQ   expires_in_absolute)r2   generate_urlr1   )r&   Z
expires_inmethodrF   r   rQ   r   r    r    r!   r   s  s    zBucket.generate_urlc                    sB   t | tjjd fdd}||r>q4S )a  
        Deletes a set of keys using S3's Multi-object delete API. If a
        VersionID is specified for that key then that version is removed.
        Returns a MultiDeleteResult Object, which contains Deleted
        and Error elements for each key you ask to delete.

        :type keys: list
        :param keys: A list of either key_names or (key_name, versionid) pairs
            or a list of Key instances.

        :type quiet: boolean
        :param quiet: In quiet mode the response includes only keys
            where the delete operation encountered an error. For a
            successful deletion, the operation does not return any
            information about the delete in the response body.

        :type mfa_token: tuple or list of strings
        :param mfa_token: A tuple or list consisting of the serial
            number from the MFA device and the current value of the
            six-digit token associated with the device.  This value is
            required anytime you are deleting versioned objects from a
            bucket that has the MFADelete option on the bucket.

        :returns: An instance of MultiDeleteResult
        deletec                    s  | pi } d}|d7 }r |d7 }d}|dk r0zt  }W n tk
rT   Y q0Y nX t|tjrl|}d }nt|trt|dkr|\}}njt|tst|tr|j	r|j	}|j
}nBt|tr|j	}d}nt|}d}d	}t|||d
}j| q$|d7 }|dtjj| 7 }|r&|d| 7 }|d7 }q$|d7 }|dkrFdS |d}t|}	tj|	}
|
d | d< d| d< rd| j< jjdj	| |d}| }|jdkrt }t|t!s|d}tj"|| |dkS #|j|j$|d S )Nz&<?xml version="1.0" encoding="UTF-8"?>z<Delete>z<Quiet>true</Quiet>r   i  r\   ZPrefixSkippedZInvalidArgumentz0Invalid. No delete action taken for this object.)codemessage   z<Object><Key>%s</Key>z<VersionId>%s</VersionId>z	</Object>z	</Delete>Fr   Content-MD5text/xmlContent-Type POST)rF   rZ   datar   )%nextStopIterationr   r   r   tuplelenr   r
   r1   rP   r	   reprr   errorsrK   r   r   saxutilsescaper   r   re   rf   compute_md5r`   
mfa_headerr2   ra   rb   rc   r   r   r   r   rs   rt   )hdrsr   countrU   r<   rP   r   r   errorfpmd5ru   r   r   Zikeys	mfa_tokenrd   rZ   quietresultr&   r    r!   delete_keys2  sv    






z(Bucket.delete_keys.<locals>.delete_keys2)r7   r   r2   rd   )r&   keysr   r   rF   r   r    r   r!   delete_keys|  s    =zBucket.delete_keysc                 C   s    |st d| j||||ddS )a  
        Deletes a key from the bucket.  If a version_id is provided,
        only that version of the key will be deleted.

        :type key_name: string
        :param key_name: The key name to delete

        :type version_id: string
        :param version_id: The version ID (optional)

        :type mfa_token: tuple or list of strings
        :param mfa_token: A tuple or list consisting of the serial
            number from the MFA device and the current value of the
            six-digit token associated with the device.  This value is
            required anytime you are deleting versioned objects from a
            bucket that has the MFADelete option on the bucket.

        :rtype: :class:`boto.s3.key.Key` or subclass
        :returns: A key object holding information on what was
            deleted.  The Caller can see if a delete_marker was
            created or removed and what version_id the delete created
            or removed.
        r   N)rF   rP   r   rS   )r   _delete_key_internal)r&   r<   rF   rP   r   r    r    r!   
delete_key  s    zBucket.delete_keyc                 C   s   |pg }| j j}|r"|d|  d|p.d }|rL|s<i }d|||j< | j jd| j|||d}| }	|jdkr|	|j|j
|	n,| | }
||
_|
| |
|  |
S d S )NrH   rW   r   DELETErY      )r2   rd   rK   r`   r   ra   r1   rb   rc   rs   rt   r3   ro   rq   rr   )r&   r<   rF   rP   r   rS   rd   rZ   ru   r   rv   r    r    r!   r     s0    
 

zBucket._delete_key_internalSTANDARDc                 C   s  |	pi }	| j j}tj|}|rP| j|kr0| }n| j j|d|	d}|j||	d}|r^d|	|j< d|t	j
|f }|r|d| 7 }t||	|j< |jr|r||	|j< |dk	rd|	|j< tj|	||}	n|
sd	|	|j< | j jd
| j||	|
d}| }|jdkr| |}t|| }t|ts.|d}tj|| t|drZ||j|j ||!| |"|#  |r| $|| |S |%|j|j&|dS )a  
        Create a new key in the bucket by copying another existing key.

        :type new_key_name: string
        :param new_key_name: The name of the new key

        :type src_bucket_name: string
        :param src_bucket_name: The name of the source bucket

        :type src_key_name: string
        :param src_key_name: The name of the source key

        :type src_version_id: string
        :param src_version_id: The version id for the key.  This param
            is optional.  If not specified, the newest version of the
            key will be copied.

        :type metadata: dict
        :param metadata: Metadata to be associated with new key.  If
            metadata is supplied, it will replace the metadata of the
            source key being copied.  If no metadata is supplied, the
            source key's metadata will be copied to the new key.

        :type storage_class: string
        :param storage_class: The storage class of the new key.  By
            default, the new key will use the standard storage class.
            Possible values are: STANDARD | REDUCED_REDUNDANCY

        :type preserve_acl: bool
        :param preserve_acl: If True, the ACL from the source key will
            be copied to the destination key.  If False, the
            destination key will have the default ACL.  Note that
            preserving the ACL in the new key object will require two
            additional API calls to S3, one to retrieve the current
            ACL and one to set that ACL on the new object.  If you
            don't care about the ACL, a value of False will be
            significantly more efficient.

        :type encrypt_key: bool
        :param encrypt_key: If True, the new copy of the object will
            be encrypted on the server-side by S3 and will be stored
            in an encrypted form while at rest in S3.

        :type headers: dict
        :param headers: A dictionary of header name/value pairs.

        :type query_args: string
        :param query_args: A string of additional querystring arguments
            to append to the request

        :rtype: :class:`boto.s3.key.Key` or subclass
        :returns: An instance of the newly created key object
        F)rR   rF   rE   AES256z%s/%sz?versionId=%sNZREPLACECOPYPUTrY   r   r   r   )'r2   rd   re   rf   Zget_utf8_valuer1   Z
get_bucketget_xml_aclserver_side_encryption_headerr   rM   rN   strZcopy_source_headerstorage_class_headerZmetadata_directive_header
merge_metara   rb   rc   rJ   r   r   r   r   r   r   r   r   hasattrZstorage_copy_errorZCodeMessagero   rq   rr   set_xml_aclrs   rt   )r&   Znew_key_nameZsrc_bucket_nameZsrc_key_namerh   Zsrc_version_idZstorage_classZpreserve_aclencrypt_keyrF   rZ   rd   Z
src_bucketaclsrcru   r   rU   r   r    r    r!   copy_key  s^    9
  







 zBucket.copy_keyc                 C   s   |t kst|r ||| jjj< n| jjj|i}d}|rB|d| 7 }| jjd| j|||d}| }|jdkr| jj	|j|j
|d S )Nr   &versionId=%sr   rY   r   )r   AssertionErrorr2   rd   
acl_headerra   r1   rb   rc   rs   rt   r&   Zacl_strr<   rF   rP   rZ   ru   r   r    r    r!   set_canned_acl|  s$     
  zBucket.set_canned_aclc                 C   sX   d}|r|d| 7 }| j jd| j|||d}| }|jdkrT| j j|j|j||S )Nr   r   r   rZ   rF   r   r2   ra   r1   rb   rc   rd   rs   rt   )r&   r<   rF   rP   rZ   ru   r   r    r    r!   r     s    
  zBucket.get_xml_aclr   c                 C   sj   |r|d| 7 }t |ts$|d}| jjd| j||||d}| }|jdkrf| jj	|j|j
|d S )Nr   r   r   r   rZ   rF   r   r   r   r   r2   ra   r1   rb   rc   rd   rs   rt   r   r    r    r!   r     s     


  zBucket.set_xml_aclc                 C   s4   t |tr | | ||| n| |||| d S r$   )r   r   r   to_xmlr   )r&   Z
acl_or_strr<   rF   rP   r    r    r!   set_acl  s    
  zBucket.set_aclc           	      C   s   d}|r|d| 7 }| j jd| j|||d}| }|jdkrxt| }t|| }t|t	sf|
d}tj|| |S | j j|j|j|d S )Nr   r   r   r   r   r   )r2   ra   r1   rb   rc   r   r   r   r   r   r   r   r   r   rd   rs   rt   )	r&   r<   rF   rP   rZ   ru   r   policyr   r    r    r!   get_acl  s(    


  zBucket.get_aclc           	      C   sz   |st d|}|r |d| 7 }t|ts4|d}| jjd| j||||d}| }|jdkrv| jj	
|j|j|dS )a  
        Set a subresource for a bucket or key.

        :type subresource: string
        :param subresource: The subresource to set.

        :type value: string
        :param value: The value of the subresource.

        :type key_name: string
        :param key_name: The key to operate on, or None to operate on the
            bucket.

        :type headers: dict
        :param headers: Additional HTTP headers to include in the request.

        :type src_version_id: string
        :param src_version_id: Optional. The version id of the key to
            operate on. If not specified, operate on the newest
            version.
        z,set_subresource called with subresource=Noner   r   r   r   r   N)r   r   r   r   r2   ra   r1   rb   rc   rd   rs   rt   )	r&   subresourcerB   r<   rF   rP   rZ   ru   r   r    r    r!   set_subresource  s&    


  zBucket.set_subresourcec                 C   sd   |st d|}|r |d| 7 }| jjd| j|||d}| }|jdkr`| jj|j|j||S )a~  
        Get a subresource for a bucket or key.

        :type subresource: string
        :param subresource: The subresource to get.

        :type key_name: string
        :param key_name: The key to operate on, or None to operate on the
            bucket.

        :type headers: dict
        :param headers: Additional HTTP headers to include in the request.

        :type src_version_id: string
        :param src_version_id: Optional. The version id of the key to
            operate on. If not specified, operate on the newest
            version.

        :rtype: string
        :returns: The value of the subresource.
        z,get_subresource called with subresource=Noner   r   r   r   )	r   r2   ra   r1   rb   rc   rd   rs   rt   )r&   r   r<   rF   rP   rZ   ru   r   r    r    r!   get_subresource  s"    
  zBucket.get_subresourcec                 C   s2   | j d|d |r.| D ]}| j d|j|d qd S )Nzpublic-readrE   )r   r1   )r&   	recursiverF   rU   r    r    r!   make_public  s    zBucket.make_publicc                 C   sd   |t kr| jjd| | j|d}|j|| | j||d |r`| D ]}|j|||d qJdS )a!  
        Convenience method that provides a quick way to add an email grant
        to a bucket. This method retrieves the current ACL, creates a new
        grant based on the parameters passed in, adds that grant to the ACL
        and then PUT's the new ACL back to S3.

        :type permission: string
        :param permission: The permission being granted. Should be one of:
            (READ, WRITE, READ_ACP, WRITE_ACP, FULL_CONTROL).

        :type email_address: string
        :param email_address: The email address associated with the AWS
            account your are granting the permission to.

        :type recursive: boolean
        :param recursive: A boolean value to controls whether the
            command will apply the grant to all keys within the bucket
            or not.  The default value is False.  By passing a True
            value, the call will iterate through all keys in the
            bucket and apply the same grant to each key.  CAUTION: If
            you have a lot of keys, this could take a long time!
        Unknown Permission: %srE   N)S3Permissionsr2   rd   storage_permissions_errorr   r   add_email_grantr   )r&   
permissionZemail_addressr   rF   r   rU   r    r    r!   r     s    zBucket.add_email_grantc                 C   sj   |t kr| jjd| | j|d}|jj|||d | j||d |rf| D ]}|j||||d qNdS )a  
        Convenience method that provides a quick way to add a canonical
        user grant to a bucket.  This method retrieves the current ACL,
        creates a new grant based on the parameters passed in, adds that
        grant to the ACL and then PUT's the new ACL back to S3.

        :type permission: string
        :param permission: The permission being granted. Should be one of:
            (READ, WRITE, READ_ACP, WRITE_ACP, FULL_CONTROL).

        :type user_id: string
        :param user_id:     The canonical user id associated with the AWS
            account your are granting the permission to.

        :type recursive: boolean
        :param recursive: A boolean value to controls whether the
            command will apply the grant to all keys within the bucket
            or not.  The default value is False.  By passing a True
            value, the call will iterate through all keys in the
            bucket and apply the same grant to each key.  CAUTION: If
            you have a lot of keys, this could take a long time!

        :type display_name: string
        :param display_name: An option string containing the user's
            Display Name.  Only required on Walrus.
        r   rE   )display_name)rF   r   N)r   r2   rd   r   r   r   add_user_grantr   )r&   r   Zuser_idr   rF   r   r   rU   r    r    r!   r   :  s    

zBucket.add_user_grantc                 C   s   | j |d}|jjS NrE   )r   r   grants)r&   rF   r   r    r    r!   list_grantsb  s    zBucket.list_grantsc                 C   s~   | j jd| j|dd}| }|jdkrdt| }t|| }t|t	sP|
d}tj|| |jS | j j|j|j|dS )z
        Returns the LocationConstraint for the bucket.

        :rtype: str
        :return: The LocationConstraint for the bucket or the empty
            string if no constraint was specified when bucket was created.
        r   locationrY   r   r   N)r2   ra   r1   rb   rc   r   r   r   r   r   r   r   r   r   ZLocationConstraintrd   rs   rt   )r&   rF   ru   r   r   r   r    r    r!   get_locationf  s"    


  zBucket.get_locationc                 C   s`   |}t |ts|d}| jjd| j|d|d}| }|jdkrFdS | jj	|j|j
|dS )a  
        Set logging on a bucket directly to the given xml string.

        :type logging_str: unicode string
        :param logging_str: The XML for the bucketloggingstatus which
            will be set.  The string will be converted to utf-8 before
            it is sent.  Usually, you will obtain this XML from the
            BucketLogging object.

        :rtype: bool
        :return: True if ok or raises an exception.
        r   r   loggingr   r   TNr   )r&   Zlogging_strrF   r   ru   r    r    r!   set_xml_logging}  s    

 
  zBucket.set_xml_loggingc                 C   s0   t |tr|j}t|||d}| j| |dS )a-  
        Enable logging on a bucket.

        :type target_bucket: bucket or string
        :param target_bucket: The bucket to log to.

        :type target_prefix: string
        :param target_prefix: The prefix which should be prepended to the
            generated log files written to the target_bucket.

        :type grants: list of Grant objects
        :param grants: A list of extra permissions which will be granted on
            the log files which are created.

        :rtype: bool
        :return: True if ok or raises an exception.
        )targetr{   r  rE   )r   r0   r1   r   r  r   )r&   Ztarget_bucketZtarget_prefixr  rF   bloggingr    r    r!   enable_logging  s    
zBucket.enable_loggingc                 C   s   t  }| j| |dS )zx
        Disable logging on a bucket.

        :rtype: bool
        :return: True if ok or raises an exception.
        rE   )r   r  r   )r&   rF   r	  r    r    r!   disable_logging  s    zBucket.disable_loggingc                 C   sz   | j jd| jd|d}| }|jdkr`t }t|| }t|t	sN|
d}tj|| |S | j j|j|j|dS )z
        Get the logging status for this bucket.

        :rtype: :class:`boto.s3.bucketlogging.BucketLogging`
        :return: A BucketLogging object for this bucket.
        r   r  r   r   r   N)r2   ra   r1   rb   rc   r   r   r   r   r   r   r   r   r   rd   rs   rt   )r&   rF   ru   r   r	  r   r    r    r!   get_logging_status  s"     


  zBucket.get_logging_statusc                 C   sV   | j |d}tdd| jd}tdd| jd}|j| |j| | j||d dS )z
        Setup the current bucket as a logging target by granting the necessary
        permissions to the LogDelivery group to write log files to this bucket.
        rE   r.   Group)r   typeurir/   N)r   r   LoggingGroupr   Z	add_grantr   )r&   rF   r   Zg1Zg2r    r    r!   set_as_logging_target  s    zBucket.set_as_logging_targetc                 C   sF   | j jd| jd|d}| }|jdkr,|S | j j|j|j|d S )Nr   requestPaymentr   r   r   r&   rF   ru   r   r    r    r!   get_request_payment  s     
  zBucket.get_request_paymentBucketOwnerc                 C   sR   | j | }| jjd| j|d|d}| }|jdkr8dS | jj|j|j|d S )Nr   r  r   r   T)	BucketPaymentBodyr2   ra   r1   rb   rc   rd   rs   rt   )r&   ZpayerrF   r   ru   r    r    r!   set_request_payment  s    
 
  zBucket.set_request_paymentc           
      C   s   |r
d}nd}|rd}nd}| j ||f }|rN|s6i }| jj}d|||j< | jjd| j|d|d}	|	 }|	jdkr|d	S | jj	|	j|	j
|d
S )a  
        Configure versioning for this bucket.

        ..note:: This feature is currently in beta.

        :type versioning: bool
        :param versioning: A boolean indicating whether version is
            enabled (True) or disabled (False).

        :type mfa_delete: bool
        :param mfa_delete: A boolean indicating whether the
            Multi-Factor Authentication Delete feature is enabled
            (True) or disabled (False).  If mfa_delete is enabled then
            all Delete operations will require the token from your MFA
            device to be passed in the request.

        :type mfa_token: tuple or list of strings
        :param mfa_token: A tuple or list consisting of the serial
            number from the MFA device and the current value of the
            six-digit token associated with the device.  This value is
            required when you are changing the status of the MfaDelete
            property of the bucket.
        ZEnabledZ	SuspendedZDisabledr   r   
versioningr   r   TN)VersioningBodyr2   rd   r`   r   ra   r1   rb   rc   rs   rt   )
r&   r  Z
mfa_deleter   rF   vermfar   rd   ru   r    r    r!   configure_versioning  s0     
  zBucket.configure_versioningc                 C   s   | j jd| jd|d}| }t|tjs4|d}tj	
| |jdkri }t| j|}|rn|d|d< t| j|}|r|d|d< |S | j j|j|j|d	S )
a  
        Returns the current status of versioning on the bucket.

        :rtype: dict
        :returns: A dictionary containing a key named 'Versioning'
            that can have a value of either Enabled, Disabled, or
            Suspended. Also, if MFADelete has ever been enabled on the
            bucket, the dictionary will contain a key named
            'MFADelete' which will have a value of either Enabled or
            Suspended.
        r   r  r   r   r   r   Z
VersioningZ	MfaDeleteN)r2   ra   r1   rb   r   r   r   decodere   r   r   rc   research	VersionREgroupMFADeleteRErd   rs   rt   )r&   rF   ru   r   dr  r  r    r    r!   get_versioning_status  s,     

  zBucket.get_versioning_statusc                 C   s   |  }t|}tj|}|dkr(i }|d |d< d|d< | jjd| j| d|d}|	 }|j
d	krnd
S | jj|j
|j|dS )z
        Configure lifecycle for this bucket.

        :type lifecycle_config: :class:`boto.s3.lifecycle.Lifecycle`
        :param lifecycle_config: The lifecycle configuration you want
            to configure for this bucket.
        Nr   r   r   r   r   	lifecycler   r   T)r   r   re   rf   r   r2   ra   r1   getvaluerb   rc   rd   rs   rt   )r&   Zlifecycle_configrF   r   r   r   ru   r   r    r    r!   configure_lifecycle>  s(    
  zBucket.configure_lifecyclec                 C   s   | j jd| jd|d}| }tj| |jdkrlt }t	
|| }t|tsZ|d}tj|| |S | j j|j|j|dS )z
        Returns the current lifecycle configuration on the bucket.

        :rtype: :class:`boto.s3.lifecycle.Lifecycle`
        :returns: A LifecycleConfig object that describes all current
            lifecycle rules in effect for the bucket.
        r   r%  r   r   r   N)r2   ra   r1   rb   re   r   r   rc   r   r   r   r   r   r   r   r   r   rd   rs   rt   )r&   rF   ru   r   r%  r   r    r    r!   get_lifecycle_configY  s$     


  zBucket.get_lifecycle_configc                 C   sR   | j jd| jd|d}| }tj| |jdkr8dS | j j	|j|j
|dS )zF
        Removes all lifecycle configuration from the bucket.
        r   r%  r   r   TNr2   ra   r1   rb   re   r   r   rc   rd   rs   rt   r  r    r    r!   delete_lifecycle_configurationp  s    
  z%Bucket.delete_lifecycle_configurationc                 C   s   t ||||}| j||dS )a  
        Configure this bucket to act as a website

        :type suffix: str
        :param suffix: Suffix that is appended to a request that is for a
            "directory" on the website endpoint (e.g. if the suffix is
            index.html and you make a request to samplebucket/images/
            the data that is returned will be for the object with the
            key name images/index.html).  The suffix must not be empty
            and must not include a slash character.

        :type error_key: str
        :param error_key: The object key name to use when a 4XX class
            error occurs.  This is optional.

        :type redirect_all_requests_to: :class:`boto.s3.website.RedirectLocation`
        :param redirect_all_requests_to: Describes the redirect behavior for
            every request to this bucket's website endpoint. If this value is
            non None, no other values are considered when configuring the
            website configuration for the bucket. This is an instance of
            ``RedirectLocation``.

        :type routing_rules: :class:`boto.s3.website.RoutingRules`
        :param routing_rules: Object which specifies conditions
            and redirects that apply when the conditions are met.

        rE   )r   WebsiteConfigurationset_website_configuration)r&   suffixZ	error_keyZredirect_all_requests_toZrouting_rulesrF   configr    r    r!   configure_website  s      zBucket.configure_websitec                 C   s   | j | |dS )zn
        :type config: boto.s3.website.WebsiteConfiguration
        :param config: Configuration data
        rE   )set_website_configuration_xmlr   )r&   r.  rF   r    r    r!   r,    s    
z Bucket.set_website_configurationc                 C   sH   | j jd| j|d|d}| }|jdkr.dS | j j|j|j|dS )z Upload xml website configurationr   r   r   r   TNr   )r&   r   rF   ru   r   r    r    r!   r0    s    
  z$Bucket.set_website_configuration_xmlc                 C   s   |  |d S )a  
        Returns the current status of website configuration on the bucket.

        :rtype: dict
        :returns: A dictionary containing a Python representation
            of the XML response from S3. The overall structure is:

        * WebsiteConfiguration

          * IndexDocument

            * Suffix : suffix that is appended to request that
              is for a "directory" on the website endpoint
            * ErrorDocument

              * Key : name of object to serve when an error occurs

        r   )"get_website_configuration_with_xmlr&   rF   r    r    r!   get_website_configuration  s    z Bucket.get_website_configurationc                 C   s2   | j |d}t }t|| }tj|| |S )ziGet the website configuration as a
        :class:`boto.s3.website.WebsiteConfiguration` object.
        rE   )get_website_configuration_xmlr   r+  r   r   r   r   r   )r&   rF   Z
config_xmlr.  r   r    r    r!   get_website_configuration_obj  s
    z$Bucket.get_website_configuration_objc                 C   s6   | j |d}tj }tj|d}|| ||fS )a  
        Returns the current status of website configuration on the bucket as
        unparsed XML.

        :rtype: 2-Tuple
        :returns: 2-tuple containing:

            1) A dictionary containing a Python representation                 of the XML response. The overall structure is:

              * WebsiteConfiguration

                * IndexDocument

                  * Suffix : suffix that is appended to request that                     is for a "directory" on the website endpoint

                  * ErrorDocument

                    * Key : name of object to serve when an error occurs


            2) unparsed XML describing the bucket's website configuration

        rE   N)r4  re   ZjsonresponseElementr   rM   )r&   rF   r   er   r    r    r!   r1    s
    

z)Bucket.get_website_configuration_with_xmlc                 C   sT   | j jd| jd|d}| d}tj| |jdkrP| j j	
|j|j||S )z!Get raw website configuration xmlr   r   r   r   r   )r2   ra   r1   rb   r  re   r   r   rc   rd   rs   rt   r  r    r    r!   r4    s     
  z$Bucket.get_website_configuration_xmlc                 C   sR   | j jd| jd|d}| }tj| |jdkr8dS | j j	|j|j
|dS )zD
        Removes all website configuration from the bucket.
        r   r   r   r   TNr)  r  r    r    r!   delete_website_configuration  s     
  z#Bucket.delete_website_configurationc                 C   sH   | j g}|t|   |d| jjddd  d|S )z
        Returns the fully qualified hostname to use is you want to access this
        bucket as a website.  This doesn't validate whether the bucket has
        been correctly configured as a website or not.
        .N)	r1   rK   r   r(   r  r`   r2   hostsplit)r&   lr    r    r!   get_website_endpoint  s    "zBucket.get_website_endpointc                 C   sF   | j jd| jd|d}| }|jdkr,|S | j j|j|j|dS )z
        Returns the JSON policy associated with the bucket.  The policy
        is returned as an uninterpreted JSON string.
        r   r   r   r   Nr   r  r    r    r!   
get_policy  s     
  zBucket.get_policyc                 C   sR   | j jd| j|d|d}| }|jdkr8|jdkr8dS | j j|j|j|dS )z
        Add or replace the JSON policy associated with the bucket.

        :type policy: str
        :param policy: The JSON policy as a string.
        r   r   r   r   r   TNr   )r&   r   rF   ru   r   r    r    r!   
set_policy+  s      zBucket.set_policyc                 C   sR   | j jd| jdd|d}| }|jdkr8|jdkr8dS | j j|j|j|d S )Nr   z/?policyr   r   r   r   Tr   r  r    r    r!   delete_policy=  s      zBucket.delete_policyc                 C   s   t |}tj|}|dkr i }|d |d< d|d< | jjd| j| d|d}| }|j	d	krfd
S | jj
|j	|j|dS )a  
        Set the CORS (Cross-Origin Resource Sharing) for a bucket.

        :type cors_xml: str
        :param cors_xml: The XML document describing your desired
            CORS configuration.  See the S3 documentation for details
            of the exact syntax required.
        Nr   r   r   r   r   corsr   r   T)r   re   rf   r   r2   ra   r1   r&  rb   rc   rd   rs   rt   )r&   Zcors_xmlrF   r   r   ru   r   r    r    r!   set_cors_xmlI  s&    	
  zBucket.set_cors_xmlc                 C   s   |  | S )a  
        Set the CORS for this bucket given a boto CORSConfiguration
        object.

        :type cors_config: :class:`boto.s3.cors.CORSConfiguration`
        :param cors_config: The CORS configuration you want
            to configure for this bucket.
        )rC  r   )r&   Zcors_configrF   r    r    r!   set_corsc  s    	zBucket.set_corsc                 C   sR   | j jd| jd|d}| }tj| |jdkr8|S | j j	|j|j
|dS )zb
        Returns the current CORS configuration on the bucket as an
        XML document.
        r   rB  r   r   Nr)  r  r    r    r!   get_cors_xmln  s     
  zBucket.get_cors_xmlc                 C   s.   |  |}t }t|| }tj|| |S )z
        Returns the current CORS configuration on the bucket.

        :rtype: :class:`boto.s3.cors.CORSConfiguration`
        :returns: A CORSConfiguration object that describes all current
            CORS rules in effect for the bucket.
        )rE  r   r   r   r   r   r   )r&   rF   r   rB  r   r    r    r!   get_cors}  s
    
zBucket.get_corsc                 C   sR   | j jd| jd|d}| }tj| |jdkr8dS | j j	|j|j
|dS )zA
        Removes all CORS configuration from the bucket.
        r   rB  r   r   TNr)  r  r    r    r!   delete_cors  s    
  zBucket.delete_corsc                 C   s   d}| j j}|pi }|r"|||j< |r8|j}	|	r8d||	< |rFd||j< |dkrRi }tj||| j j}| j jd| j	|||d}
|

 }tj| |
jdkrt| }t|| }t|ts|d}tj|| |S | j j|
j|
j|dS )	a  
        Start a multipart upload operation.

        .. note::

            Note: After you initiate multipart upload and upload one or more
            parts, you must either complete or abort multipart upload in order
            to stop getting charged for storage of the uploaded parts. Only
            after you either complete or abort multipart upload, Amazon S3
            frees up the parts storage and stops charging you for the parts
            storage.

        :type key_name: string
        :param key_name: The name of the key that will ultimately
            result from this multipart upload operation.  This will be
            exactly as the key appears in the bucket after the upload
            process has been completed.

        :type headers: dict
        :param headers: Additional HTTP headers to send and store with the
            resulting key in S3.

        :type reduced_redundancy: boolean
        :param reduced_redundancy: In multipart uploads, the storage
            class is specified when initiating the upload, not when
            uploading individual parts.  So if you want the resulting
            key to use the reduced redundancy storage class set this
            flag when you initiate the upload.

        :type metadata: dict
        :param metadata: Any metadata that you would like to set on the key
            that results from the multipart upload.

        :type encrypt_key: bool
        :param encrypt_key: If True, the new copy of the object will
            be encrypted on the server-side by S3 and will be stored
            in an encrypted form while at rest in S3.

        :type policy: :class:`boto.s3.acl.CannedACLStrings`
        :param policy: A canned ACL policy that will be applied to the
            new key (once completed) in S3.
        r   ZREDUCED_REDUNDANCYr   Nr   r   r   r   )r2   rd   r   r   r   re   rf   r   ra   r1   rb   r   r   rc   r   r   r   r   r   r   r   r   r   rs   rt   )r&   r<   rF   Zreduced_redundancyrh   r   r   rZ   rd   r   ru   r   rV   r   r    r    r!   initiate_multipart_upload  sD    .





  z Bucket.initiate_multipart_uploadc                 C   s   d| }|dkri }d|d< | j jd| j||||d}d}| d}|d	d
krZd}tj| |j	dkr|st
| }	t|	| }
t|ts|d}tj||
 | | }|| || |j|	_|j|	_|	S | j j|j	|j|dS )z8
        Complete a multipart upload operation.
        uploadId=%sNr   r   r   )rZ   rF   r   Fr   z<Error>r   Tr   )r2   ra   r1   rb   r  findre   r   r   rc   r   r   r   r   r   r   r   r   r   r3   ro   rp   rP   Z	encryptedrd   rs   rt   )r&   r<   	upload_idZxml_bodyrF   rZ   ru   Zcontains_errorr   rV   r   rv   r    r    r!   complete_multipart_upload  s>     




  z Bucket.complete_multipart_uploadc                 C   sX   d| }| j jd| j|||d}| }tj| |jdkrT| j j	|j|j
|dS )z
        To verify that all parts have been removed, so you don't get charged
        for the part storage, you should call the List Parts operation and
        ensure the parts list is empty.
        rI  r   r   r   Nr)  )r&   r<   rK  rF   rZ   ru   r   r    r    r!   cancel_multipart_upload  s    
  zBucket.cancel_multipart_uploadc                 C   s   | j j| j|dS r  )r2   Zdelete_bucketr1   r2  r    r    r!   r   !  s    zBucket.deletec                 C   sB   |  |}t }t|| }t|ts0|d}tj	|| |S )Nr   )
get_xml_tagsr   r   r   r   r   r   r   r   r   )r&   rF   ru   tagsr   r    r    r!   get_tags$  s    


zBucket.get_tagsc                 C   sF   | j jd| jd|d}| }|jdkr,|S | j j|j|j|d S )Nr   taggingr   r   r   r  r    r    r!   rN  -  s    
  zBucket.get_xml_tagsrQ  c                 C   s   |d kri }t jt|}|d |d< d|d< t|tsD|d}| jjd| j	|||d}|
 }|jdkr| jj|j|j|d	S )
Nr   r   r   r   r   r   r   r   T)re   rf   r   r   r   r   r   r2   ra   r1   rb   rc   rd   rs   rt   )r&   Ztag_strrF   rZ   r   ru   r   r    r    r!   set_xml_tags8  s(    


  zBucket.set_xml_tagsc                 C   s   | j | |dS r  )rR  r   )r&   rO  rF   r    r    r!   set_tagsJ  s    zBucket.set_tagsc                 C   sR   | j jd| jd|d}| }tj| |jdkr8dS | j j	|j|j
|d S )Nr   rQ  r   r   Tr)  r  r    r    r!   delete_tagsM  s    
  zBucket.delete_tags)N)NNNT)r_   r_   r_   NN)r_   r_   r_   r_   NN)r_   r_   NN)r_   )r_   N)N)N)N)N)r   NFNF)FNN)NNN)NNNN)NNr   FFNN)r_   NN)r_   NN)r_   NNr   )r_   NN)r_   NN)r_   NN)r_   NN)FN)FN)FNN)N)N)N)r_   NN)N)N)N)N)r  N)FNN)N)N)N)N)NNNNN)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)NFNFN)N)N)N)N)N)NrQ  )N)N)Ur)   r*   r+   r  r  r  r   r"  r   r4   r6   r8   r=   r?   rC   rD   rG   r:   rO   r~   r   r   r   r   r   r   r   r   r   rJ   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(  r*  r/  r,  r0  r3  r5  r1  r4  r8  r>  r?  r@  rA  rC  rD  rE  rF  rG  rH  rL  rM  r   rP  rN  rR  rS  rT  r    r    r    r!   r0   L   s  
    
3&  
3      
0     
#
  

0
3
J
     
	
`  
     
           
f  

  


  
'  
%
   
"    
(


    







    
0



    
$
	




!









      
Q 
'


	


r0   )6re   r   Zboto.resultsetr   Zboto.exceptionr   Zboto.s3.aclr   r   r   Zboto.s3.keyr   Zboto.s3.prefixr	   Zboto.s3.deletemarkerr
   Zboto.s3.multipartr   r   Zboto.s3.multideleter   r   Zboto.s3.bucketlistresultsetr   r   r   Zboto.s3.lifecycler   Zboto.s3.taggingr   Zboto.s3.corsr   Zboto.s3.bucketloggingr   Zboto.s3r   Zboto.jsonresponseZ
boto.utilsZxml.saxr   xml.sax.saxutilsr  base64collectionsr   Zboto.compatr   r   r   r   objectr   r   r0   r    r    r    r!   <module>   s<   