o ckF[7@stddlZddlmZddlmZddlmZddlmZmZm Z ddl m Z ddl m Z ddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ddl$Zddl%Zddl&Z'ddl(Z'ddl)Z)ddl*Z*ddl+m,Z,ddl-m.Z.m/Z/m0Z0m1Z1Gddde2Z3gdZ4Gddde2Z5dS)N)handler) ResultSet)BotoClientError)PolicyCannedACLStringsGrant)Key)Prefix) DeleteMarker)MultiPartUpload)CompleteMultiPartUpload)MultiDeleteResult)ErrorBucketListResultSetVersionedBucketListResultSetMultiPartUploadListResultSet) Lifecycle)Tags)CORSConfiguration) BucketLogging)website) defaultdict)BytesIOsixStringIOurllibc@sleZdZeddZded<ded<ded<d ed <d ed <d ed<ded<ded<ded<eddZdS)S3WebsiteEndpointTranslatecCsdS)Nzs3-website-us-east-1r r r 0/usr/lib/python3/dist-packages/boto/s3/bucket.py:sz#S3WebsiteEndpointTranslate.zs3-website-eu-west-1z eu-west-1zs3-website.eu-central-1z eu-central-1zs3-website-us-west-1z us-west-1zs3-website-us-west-2z us-west-2zs3-website-sa-east-1z sa-east-1zs3-website-ap-northeast-1zap-northeast-1zs3-website-ap-southeast-1zap-southeast-1zs3-website-ap-southeast-2zap-southeast-2zs3-website.cn-north-1z cn-north-1cCs |j|SN) trans_region)selfregr r r!translate_regionEs z+S3WebsiteEndpointTranslate.translate_regionN)__name__ __module__ __qualname__rr$ classmethodr'r r r r!r8s r)READWRITEREAD_ACP WRITE_ACP FULL_CONTROLc@sdeZdZdZdZdZdZdZddefddZ d d Z d d Z d dZ ddZ ddZddZdddZ  dddZddZ  dddZ  ddd Z   dd!d"Zdd#d$Z  dd%d&Zd'd(Zdd)d*Zdd+d,Zd-d.Zdd/d0Zdd1d2Z   4dd5d6Zdd7d8Z  dd9d:Z  dd;d<Z!  4 dd>d?Z"  dd@dAZ#ddBdCZ$  DddEdFZ%ddGdHZ&ddIdJZ'  ddKdLZ(  ddMdNZ)ddOdPZ* ddQdRZ+ 4 ddSdTZ,ddUdVZ-ddWdXZ.ddYdZZ/  dd[d\Z0dd]d^Z1dd_d`Z2ddadbZ3ddcddZ4ddfdgZ5 4 ddhdiZ6ddjdkZ7ddldmZ8ddndoZ9ddpdqZ:    ddrdsZ;ddtduZddzd{Z?dd|d}Z@dd~dZAdddZBddZCdddZDdddZEdddZFdddZGdddZHdddZIdddZJdddZK  4 4 dddZL dddZMdddZNdddZOdddZPdddZQdddZRdddZSdddZTdS)Bucketz.http://acs.amazonaws.com/groups/s3/LogDeliveryz %s z %s %s z([A-Za-z]+)z"([A-Za-z]+)NcCs||_||_||_dSr#)name connection key_class)r%r3r2r4r r r!__init__^s zBucket.__init__cCs d|jS)Nz )r2r%r r r!__repr__cs zBucket.__repr__cCs tt|Sr#)iterrr6r r r!__iter__fs zBucket.__iter__cCs||duSr#get_keyr%key_namer r r! __contains__iszBucket.__contains__cCsdSr#r )r%r2attrsr3r r r! startElementlszBucket.startElementcCs4|dkr ||_dS|dkr||_dSt|||dS)NName CreationDate)r2 creation_datesetattr)r%r2valuer3r r r! endElementos   zBucket.endElementcCs ||_dS)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)r4)r%r4r r r! set_key_classws zBucket.set_key_classcCs|j||dS)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. headersr:)r%r=rIr r r!lookups z Bucket.lookupTc Cs|dur|s |s |rtd||Sg}|r|d||r7t|D]\}}|d|tj|fq%||||\} } | 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) rnew_keyappendr iteritemsrparsequote_get_key_internal) r%r=rI version_idresponse_headersvalidate query_args_lrkrvkeyrespr r r!r;s  zBucket.get_keyc Csd|pd}|jjd|j|||d}||jddkry||}|jj}tj |j ||_ t jD]}|||j|dd<q3|d} | rTt|d|_nd |_||_||||||||||||fS|jd krd|fS|jj|j|jd ) N&HEADrI query_argsd-_zcontent-lengthri)joinr3 make_requestr2readstatusr4providerbotoutilsget_aws_metadatamsgmetadatar base_fields getheader__dict__lowerreplaceintsizehandle_version_headershandle_encryption_headershandle_restore_headershandle_storage_class_headerhandle_addl_headers getheadersstorage_response_errorreason) r%r=rIrVr^responsekrhfieldclenr r r!rRs:         zBucket._get_key_internalrccCst||||||dS)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 delimitermarkerrIrr r r!lists 0z Bucket.listc Cst|||||||dS)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 rr)r%rr key_markerversion_id_markerrIrr r r! list_versionss +zBucket.list_versionscCst|||||dS)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 rr)r%rupload_id_markerrIrr r r!list_multipart_uploadsMs zBucket.list_multipart_uploadscCsg}|r ||t|dddD]B\}}|durq|dd}|dkr(d}t|tjtjfs7t|}t|tjsB| d}|rU|d t j |t j |fqd |S) NcSs|dS)Nrr )xr r r!r"vsz,Bucket._get_all_query_args..)rYrbramaxkeyszmax-keysutf-8rLr[)rNsorteditemsrr isinstancer string_types binary_type text_typeencoderrPrQrd)r%paramsinitial_query_stringpairsrYrEr r r!_get_all_query_argsps(        zBucket._get_all_query_argsc Ks|j||d}|jjd|j||d}|}tj||jdkr>t |}t ||} t |t s5|d}tj|| |S|jj|j|j|)N)rGETr]r)rr3rer2rfrilogdebugrgrr XmlHandlerrbytesrxmlsax parseStringrhr{r|) r% element_maprrIrr^r}bodyrshr r r!_get_alls(       zBucket._get_allcCs"|D] }||vrtd|qdS)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. zInvalid argument "%s"!N) TypeError)r%kwargsnameskwargr r r!validate_kwarg_namess   zBucket.validate_kwarg_namescKs4||gd|jd|jfdtfgd|fi|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 )rmax_keysrrrrContentsCommonPrefixesrc)rrr4r r%rIrr r r! get_all_keyss) zBucket.get_all_keyscKs4|||jd|jfdtfdtfgd|fi|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 Versionrr versions) validate_get_all_versions_paramsrr4r r rr r r!get_all_versionss - zBucket.get_all_versionscCs||gddS)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. )rrrrrrrN)r)r%rr r r!rsz'Bucket.validate_get_all_versions_paramscKs2||gd|jdtfdtfgd|fi|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 ) max_uploadsrrrrrUploadruploads)rrr r rr r r!get_all_multipart_uploadssC z Bucket.get_all_multipart_uploadscCs|std|||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) ValueErrorr4r<r r r!rMes  zBucket.new_keyrFc Cs|jj|||j||||dS)N)rI force_httprTexpires_in_absolute)r3 generate_urlr2)r% expires_inmethodrIrrTrr r r!rss zBucket.generate_urlcsJt|tjjdfdd}||r# ||sS)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 deletecs|pi}d}|d7}r|d7}d}|dkrzt}Wn ty%Ynpwt|tjr1|}d}nEt|trAt|dkrA|\}}n5t|tsKt|trU|j rU|j }|j }n!t|t r`|j }d}nt |}d}d }t |||d }j|q|d 7}|d tjj|7}|r|d |7}|d7}|dks|d7}|dkrdS|d}t|} tj| } | d |d<d|d<rd|j<jjdj ||d} | } | jdkrt } t| t!s| d} tj"| | |dkS#| j| j$| )Nz&zztruerir` PrefixSkippedInvalidArgumentz0Invalid. No delete action taken for this object.)codemessagez%sz%sz z Fr Content-MD5text/xml Content-Type POST)rIr^datar)%next StopIterationrrrtuplelenrr r2rSr reprrerrorsrNrrsaxutilsescaperrrirj compute_md5rd mfa_headerr3rerfrgrrrrr{r|)hdrsrcountrYr=rSrrerrorfpmd5r}rrikeys mfa_tokenrhr^quietresultr%r r! delete_keys2sz               z(Bucket.delete_keys..delete_keys2)r8r r3rh)r%keysrrrIrr rr! delete_keys|s=zBucket.delete_keyscCs |std|j||||ddS)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. rN)rIrSrrV)r_delete_key_internal)r%r=rIrSrr r r! delete_keyszBucket.delete_keyc Cs|pg}|jj}|r|d|d|pd}|r&|si}d|||j<|jjd|j|||d}|} |jdkrD| |j|j | | |} || _| || || S)NrKr[rDELETEr])r3rhrNrdrrer2rfrgr{r|r4ruryrz) r%r=rIrSrrVrhr^r}rr~r r r!rs.   zBucket._delete_key_internalSTANDARDc Cs| pi} |jj} tj|}|r(|j|kr|} n |jj|d| d} | j|| d} |r/d| | j<d|t j |f}|rA|d|7}t || | j <| jrR|rR|| | j<|durdd| | j<tj| || } n| skd | | j<|jjd |j|| | d }|}|jd kr||}t||}t|ts|d }tj||t|dr| |j|j ||!||"|#|r|$| ||S| %|j|j&|)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)rUrIrHAES256z%s/%sz ?versionId=%sNREPLACECOPYPUTr]rrr)'r3rhrirjget_utf8_valuer2 get_bucket get_xml_aclserver_side_encryption_headerrrPrQstrcopy_source_headerstorage_class_headermetadata_directive_header merge_metarerfrgrMrrrrrrrrhasattrstorage_copy_errorCodeMessageruryrz set_xml_aclr{r|)r% new_key_namesrc_bucket_name src_key_namermsrc_version_id storage_class preserve_acl encrypt_keyrIr^rh src_bucketaclsrcr}rrYrr r r!copy_keysX9                zBucket.copy_keycCs|tvsJ|r|||jjj<n|jjj|i}d}|r!|d|7}|jjd|j|||d}|}|jdkrA|jj|j|j |dS)Nr &versionId=%srr]r) rr3rh acl_headerrer2rfrgr{r|r%acl_strr=rIrSr^r}rr r r!set_canned_acl|s    zBucket.set_canned_aclcCsXd}|r |d|7}|jjd|j|||d}|}|jdkr*|jj|j|j||S)Nrrrr^rIrr3rer2rfrgrhr{r|)r%r=rIrSr^r}rr r r!rs   zBucket.get_xml_aclrcCsj|r|d|7}t|ts|d}|jjd|j||||d}|}|jdkr3|jj |j|j |dS)Nrrrrr^rIr rrrr3rer2rfrgrhr{r|rr r r!rs     zBucket.set_xml_aclcCs6t|tr|||||dS|||||dSr#)rrrto_xmlr )r% acl_or_strr=rIrSr r r!set_acls  zBucket.set_aclc Csd}|r |d|7}|jjd|j|||d}|}|jdkrd S|jj | j| j |) 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. Enabled SuspendedDisabledrr versioningr rT) VersioningBodyr3rhrdrrer2rfrgr{r|) r%rE mfa_deleterrIvermfarrhr}r r r!configure_versionings*  zBucket.configure_versioningcCs|jjd|jd|d}|}t|tjs|d}tj ||j dkrIi}t |j|}|r7|d|d<t |j|}|rG|d|d<|S|jj|j |j|) 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. rrEr rrr Versioning MfaDelete)r3rer2rfrrrdecoderirrrgresearch VersionREgroup MFADeleteRErhr{r|)r%rIr}rdrHrIr r r!get_versioning_statuss&      zBucket.get_versioning_statuscCs|}t|}tj|}|duri}|d|d<d|d<|jjd|j|d|d}| }|j d kr7d S|jj |j |j |) 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. Nrrrrr lifecycler rT)rrrirjrr3rer2getvaluerfrgrhr{r|)r%lifecycle_configrIrrrr}rr r r!configure_lifecycle>s$     zBucket.configure_lifecyclecCs|jjd|jd|d}|}tj||jdkr6t}t ||}t |t s-| d}tj|||S|jj|j|j|)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. rrUr rr)r3rer2rfrirrrgrrrrrrrrrrhr{r|)r%rIr}rrUrr r r!get_lifecycle_configYs       zBucket.get_lifecycle_configcCN|jjd|jd|d}|}tj||jdkrdS|jj |j|j |)zF Removes all lifecycle configuration from the bucket. rrUr rT r3rer2rfrirrrgrhr{r|r<r r r!delete_lifecycle_configurationp    z%Bucket.delete_lifecycle_configurationcCst||||}|j||dS)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. rH)rWebsiteConfigurationset_website_configuration)r%suffix error_keyredirect_all_requests_to routing_rulesrIconfigr r r!configure_websites zBucket.configure_websitecC|j||dS)zn :type config: boto.s3.website.WebsiteConfiguration :param config: Configuration data rH)set_website_configuration_xmlr)r%rdrIr r r!r_s z Bucket.set_website_configurationcCsD|jjd|j|d|d}|}|jdkrdS|jj|j|j|)z Upload xml website configurationrrr rTr )r%rrIr}rr r r!rgs  z$Bucket.set_website_configuration_xmlcCs||dS)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_xmlr%rIr r r!get_website_configurationsz Bucket.get_website_configurationcCs2|j|d}t}t||}tj|||S)ziGet the website configuration as a :class:`boto.s3.website.WebsiteConfiguration` object. rH)get_website_configuration_xmlrr^rrrrr)r%rI config_xmlrdrr r r!get_website_configuration_objs  z$Bucket.get_website_configuration_objcCs6|j|d}tj}tj|d}||||fS)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 rHN)rkri jsonresponseElementrrP)r%rIrerr r r!rhs   z)Bucket.get_website_configuration_with_xmlcCsT|jjd|jd|d}|d}tj||jdkr(|jj |j|j ||S)z!Get raw website configuration xmlrrr rr) r3rer2rfrMrirrrgrhr{r|r<r r r!rks    z$Bucket.get_website_configuration_xmlcCrZ)zD Removes all website configuration from the bucket. rrr rTr[r<r r r!delete_website_configurations    z#Bucket.delete_website_configurationcCsH|jg}|t||d|jjdddd|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) r2rNrr'r'rdr3hostsplit)r%lr r r!get_website_endpoints" zBucket.get_website_endpointcCr:)z Returns the JSON policy associated with the bucket. The policy is returned as an uninterpreted JSON string. rrr rr r<r r r! get_policys   zBucket.get_policycCsN|jjd|j|d|d}|}|jdkr|jdkrdS|jj|j|j|)z Add or replace the JSON policy associated with the bucket. :type policy: str :param policy: The JSON policy as a string. rrr rrTr )r%rrIr}rr r r! set_policy+s  zBucket.set_policycCsN|jjd|jdd|d}|}|jdkr|jdkrdS|jj|j|j|)Nrz/?policyrr rrTr r<r r r! delete_policy=s  zBucket.delete_policycCs|t|}tj|}|duri}|d|d<d|d<|jjd|j|d|d}|}|j d kr3d S|jj |j |j |) 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. Nrrrrrcorsr rT) rrirjrr3rer2rVrfrgrhr{r|)r%cors_xmlrIrrr}rr r r! set_cors_xmlIs"     zBucket.set_cors_xmlcCs||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. )r}r)r% cors_configrIr r r!set_corscs zBucket.set_corscCsN|jjd|jd|d}|}tj||jdkr|S|jj |j|j |)zb Returns the current CORS configuration on the bucket as an XML document. rr{r rr[r<r r r! get_cors_xmlns    zBucket.get_cors_xmlcCs.||}t}t||}tj|||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. )rrrrrrr)r%rIrr{rr r r!get_cors}s  zBucket.get_corscCrZ)zA Removes all CORS configuration from the bucket. rr{r rTr[r<r r r! delete_corsr]zBucket.delete_corscCsd}|jj}|p i}|r|||j<|r|j} | rd|| <|r#d||j<|dur)i}tj|||jj}|jjd|j |||d} | } tj | | j dkrkt|} t| |} t| tsb| d} tj| | | S|jj| j | j| ) 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. rREDUCED_REDUNDANCYrNrr rr)r3rhrrrrirjrrer2rfrrrgr rrrrrrrrr{r|)r%r=rIreduced_redundancyrmrrr^rhrr}rrZrr r r!initiate_multipart_uploads@.         z Bucket.initiate_multipart_uploadc Csd|}|dur i}d|d<|jjd|j||||d}d}|d}|d d kr-d }tj||j d krn|snt |} t | |} t |tsN|d}tj|| ||} | || || j| _| j| _| S|jj|j |j|) z8 Complete a multipart upload operation. uploadId=%sNrrr)r^rIrFrzrTr)r3rer2rfrMfindrirrrgr rrrrrrrrr4rurvrS encryptedrhr{r|) r%r= upload_idxml_bodyrIr^r}contains_errorrrZrr~r r r!complete_multipart_uploads8        z Bucket.complete_multipart_uploadcCsXd|}|jjd|j|||d}|}tj||jdkr*|jj |j|j |dS)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. rrr rNr[)r%r=rrIr^r}rr r r!cancel_multipart_uploads   zBucket.cancel_multipart_uploadcCs|jj|j|dSr")r3 delete_bucketr2rir r r!r!z Bucket.deletecCsB||}t}t||}t|ts|d}tj |||S)Nr) get_xml_tagsrrrrrrrrr)r%rIr}tagsrr r r!get_tags$s    zBucket.get_tagscCr:)Nrtaggingr rr r<r r r!r-s   zBucket.get_xml_tagsrcCs|duri}tjt|}|d|d<d|d<t|ts"|d}|jjd|j |||d}| }|j dkrB|jj |j |j|d S) Nrrrrrrr rT)rirjrrrrrr3rer2rfrgrhr{r|)r%tag_strrIr^rr}rr r r! set_xml_tags8s$      zBucket.set_xml_tagscCrfr")rr)r%rrIr r r!set_tagsJrzBucket.set_tagscCrZ)Nrrr rTr[r<r r r! delete_tagsMs    zBucket.delete_tagsr#)NNNT)rcrcrcNN)rcrcrcrcNN)rcrcNN)rc)rcN)rNFNF)FNN)NNN)NNNN)NNrFFNN)rcNN)rcNNr)FN)r>N)NNNNN)NFNFN)Nr)Ur(r)r*r5r?rFrPrRrr5r7r9r>r@rFrGrJr;rRrrrrrrrrrrrMrrrrrr rrrrrrrrr r$r'r*r/r0r1r9r=rArJrTrXrYr\rer_rgrjrmrhrkrqrwrxryrzr}rrrrrrrrrrrrrr r r r!r1Ls   3& 3 0 #   03 J `    f     ' % " (       0    $  !       Q '   r1)6rirboto.resultsetrboto.exceptionr boto.s3.aclrrr boto.s3.keyrboto.s3.prefixr boto.s3.deletemarkerr boto.s3.multipartr r boto.s3.multideleter rboto.s3.bucketlistresultsetrrrboto.s3.lifecyclerboto.s3.taggingr boto.s3.corsrboto.s3.bucketloggingrboto.s3rboto.jsonresponse boto.utilsxml.saxrxml.sax.saxutilsrNbase64 collectionsr boto.compatrrrrobjectrrr1r r r r!s>