o ckF[O@sxddlZddlZddlZddlZddlmZddlmZddlmZGddde Z Gddde Z Gd d d e Z dS) N) DeleteMarkerBotoClientError)InvalidUriErrorc@seZdZdZdZdZiZddZddZddZ d d Z d d Z d dZ ddZ d.ddZddZ  d/ddZ  d0ddZd1ddZd2ddZd1dd Zd2d!d"Zd.d#d$Z %   d3d&d'Z  d4d(d)Zd*d+Zd,d-ZdS)5 StorageUriz Base class for representing storage provider-independent bucket and object name with a shorthand URI-like syntax. This is an abstract class: the constructor cannot be called (throws an exception if you try). NcCstd)zBUncallable constructor on abstract base StorageUri class. z0Attempt to instantiate abstract StorageUri classrselfr 2/usr/lib/python3/dist-packages/boto/storage_uri.py__init__6szStorageUri.__init__cCs|jS)z%Returns string representation of URI.urirr r r __repr__<szStorageUri.__repr__cCs |j|jkS)z#Returns true if two URIs are equal.r )rr r r r equals@ zStorageUri.equalscCs*|durtdtd||fddS)N zAttempt to get %s for "%s" failed. This can happen if the URI refers to a non-existent object or if you meant to operate on a directory (e.g., leaving off -R option on gsutil cp, mv, or ls of a bucket)P)rjointextwrapwrap)rresplevelr r r r check_responseDs zStorageUri.check_responsecC.tt|tr|jstd||jfdSdS)Nz%s on bucket-less URI (%s)) issubclasstypeBucketStorageUri bucket_namerr r function_namer r r _check_bucket_uriLs  zStorageUri._check_bucket_uricCr)Nz%s on object-less URI (%s))rrr object_namerr rr r r _check_object_uriQs zStorageUri._check_object_uric Ks4|D]}||rtjd||t||fqdS)Nz$Warning: %s ignores argument: %s=%s )sysstderrwritestr)rrargsargr r r _warn_about_argsVszStorageUri._warn_about_argsc Ks t|jpd}t|drd|vr|j|d<|||js|j|jvr+|j|j|_n]|jdkrHddlm }|||fi||_|j|j|j<n@|jdkrpddl m }ddlm }||d <|||fi||_|j|j|j<n|jd krdd l m}|||_ntd |j|j|j_|jS) a Opens a connection to appropriate provider, depending on provider portion of URI. Requires Credentials defined in boto config file (see boto/pyami/config.py). @type storage_uri: StorageUri @param storage_uri: StorageUri specifying a bucket or a bucket+object @rtype: L{AWSAuthConnection} @return: A connection to storage service provider of the given URI. r suppress_consec_slashess3r) S3Connectiongs) GSConnection)OrdinaryCallingFormatcalling_formatfile)FileConnectionzUnrecognized scheme "%s")dictconnection_argshasattrr*update connectionscheme provider_poolboto.s3.connectionr,boto.gs.connectionr.r/boto.file.connectionr2rdebug) r access_key_idsecret_access_keykwargsr4r,r.r/r2r r r connect]sF             zStorageUri.connectcCs"tt|to|jdup|jduSN)rrr version_id generationrr r r has_versions zStorageUri.has_versionFcCs(|d|||}||j|||S)N delete_key)r" get_bucketrFr!rvalidateheadersrC mfa_tokenbucketr r r rF   zStorageUri.delete_keycCsD|d|j|d}|rdd|j|||dDS|j|||dS)N list_bucketrJcss|] }t|ts|VqdSrB) isinstancer).0vr r r sz)StorageUri.list_bucket..)prefix delimiterrJ)r rG list_versionslist)rrUrVrJ all_versionsrLr r r rOs    zStorageUri.list_bucketcCs|||}||SrB)rG get_all_keys)rrIrJrUrLr r r rZs  zStorageUri.get_all_keyscCs6|d|}||j||}||d|j|S)NrGrL)r rArGrrr )rrIrJconnrLr r r rGs zStorageUri.get_bucketcCs:|d|||}||j||}||d|j|S)Nget_keykey)r"rGr\r!rr rrIrJrCrLr]r r r r\s  zStorageUri.get_keycCs"|d|||}||jS)Nnew_key)r"rGr_r!rrIrJrLr r r r_   zStorageUri.new_keycCsD|d|jddd|d|}||d|j|j|||dS)Nr\F)rIr]rC)r"r)r\rr get_contents_to_file)rfprJrCr]r r r get_contents_to_streams  z!StorageUri.get_contents_to_stream c Csf|d|d|} || d|j| r%| j||||||||| d dS| ||||||||dS)Nrcr]) hash_algs)r"r\rr rc) rrdrJcbnum_cbtorrentrCres_download_handlerresponse_headersrgr]r r r rcs   zStorageUri.get_contents_to_filecCs8|d|||}||d|j||||||S)Nget_contents_as_stringr])r"r\rr rm)rrIrJrhrirjrCr]r r r rms   z!StorageUri.get_contents_as_stringcC$|}|jj}||d|j|S)N acl_class)rAproviderrorr )rr[ror r r rozStorageUri.acl_classcCrn)N canned_acls)rArprrrr )rr[rrr r r rrrqzStorageUri.canned_aclsNNFNNN)rNrNNFFNNFN)NNrfFNNNN)FNNrfFN)__name__ __module__ __qualname____doc__r7r4r9r rrrr r"r)rArErFrOrZrGr\r_rercrmrorrr r r r r sF :        rc@seZdZdZdZegZ   dddZd d Zd d Z d dZ dddZ  dddZ ddZ ddZdddZdddZdddZdddZddd Zdd!d"Zdd#d$Z  dd%d&Z  dd'd(Z  dd)d*Z  dd+d,Zdd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Z d;d<Z!d=d>Z"d?d@Z#dAdBZ$  ddDdEZ%ddFdGZ&ddHdIZ'dJdKZ(  ddLdMZ)  ddNdOZ*ddPdQZ+  ddRdSZ,  ddTdUZ-  ddVdWZ.  ddXdYZ/   dd[d\Z0   dd]d^Z1  dd_d`Z2  a  ddbdcZ3  ddddeZ4ddfdgZ5ddhdiZ6  ddjdkZ7ddldmZ8ddndoZ9ddpdqZ: ddrdsZ;ddtduZddzd{Z?  dd|d}Z@dd~dZA  dddZBdddZCdS)rz StorageUri subclass that handles bucket storage providers. Callers should instantiate this class by calling boto.storage_uri(). /NrTFc Csb||_||_||_||_|r||_||_||_|ot||_| |_ t |jp)t ||_ | dS)aInstantiate a BucketStorageUri from scheme,bucket,object tuple. @type scheme: string @param scheme: URI scheme naming the storage provider (gs, s3, etc.) @type bucket_name: string @param bucket_name: bucket name @type object_name: string @param object_name: object name, excluding generation/version. @type debug: int @param debug: debug level to pass in to connection (range 0..2) @type connection_args: map @param connection_args: optional map containing args to be passed to {S3,GS}Connection constructor (e.g., to override https_connection_factory). @param suppress_consec_slashes: If provided, controls whether consecutive slashes will be suppressed in key paths. @param version_id: Object version id (S3-specific). @param generation: Object generation number (GCS-specific). @param is_latest: boolean indicating that a versioned object is the current version After instantiation the components are available in the following fields: scheme, bucket_name, object_name, version_id, generation, is_latest, versionless_uri, version_specific_uri, uri. Note: If instantiated without version info, the string representation for a URI stays versionless; similarly, if instantiated with version info, the string representation for a URI stays version-specific. If you call one of the uri.set_contents_from_xyz() methods, a specific object version will be created, and its version-specific URI string can be retrieved from version_specific_uri even if the URI was instantiated without version info. N) r8rr!r=r4r*rCintrD is_latestboolis_version_specific_build_uri_strings) rr8rr!r=r4r*rCrDr}r r r r s$ zBucketStorageUri.__init__cCs|jr9|jr9d|j|j|jf|_|jrd|j|jf|_n |jr*d|j|jf|_|jr3|j|_dS|j|_dS|jrGd|j|jf|_dSd|j|_dS)Nz %s://%s/%sz%s#%sz%s://%s/z%s://) rr!r8versionless_urirDversion_specific_urirCrr rr r r r-s$     z#BucketStorageUri._build_uri_stringsc Cs4|t|ddt|ddt|ddt|dddS)NrCrDr}md5)_update_from_valuesgetattr)rr]r r r _update_from_key@s     z!BucketStorageUri._update_from_keycCs$||_||_||_|||_dSrB)rCrDr}rr)rrCrDr}rr r r rGs  z$BucketStorageUri._update_from_valuescCst|d|||}|jdkr|j|j||p|jd}n|jdkr0|j|j||jd}||d|j |S)Nr\awsrbgooglerDr]) r"rG get_providernamer\r!rCrDrr r^r r r r\Ns    zBucketStorageUri.get_keycCsf|d|||}|jdkr |p|j}||j|||S|jdkr1|j|j||jdSdS)NrFrrr)r"rGrrrCrFr!rDrHr r r rFZs     zBucketStorageUri.delete_keycCs$|dt|j|j||j|jdS)zInstantiate a BucketStorageUri from the current BucketStorageUri, but replacing the object_name. @type new_name: string @param new_name: new object name clone_replace_name)rr!r=r*)r rr8rr=r*rnew_namer r r rfs  z#BucketStorageUri.clone_replace_namec Csn|dd}d}d}t|dr|j}t|dr|j}t|dr#|j}t|j|jj |j |j |j |||dS)a)Instantiate a BucketStorageUri from the current BucketStorageUri, by replacing the object name with the object name and other metadata found in the given Key object (including generation). @type key: Key @param key: key for the new StorageUri to represent clone_replace_keyNFrCrDr})rr!r=r*rCrDr}) r r5rCrDr}rrpget_provider_namerLrr=r*)rr]rCrDr}r r r rss(    z"BucketStorageUri.clone_replace_keycCsn|d|||}|jpd}|jdkr$|p|j}||||}n |j|||jd}||d|j |S)zreturns a bucket's aclget_aclrNrracl) r rGr!rrrCrrDrr )rrIrJrCrLkey_namerr r r rs    zBucketStorageUri.get_aclcC4|d|||}||}||d|j|S)z%returns a bucket's default object acl get_def_aclr)r rGrrr )rrIrJrLrr r r r   zBucketStorageUri.get_def_aclcCr)zreturns a bucket's CORS XMLget_corscors)r rGrrr )rrIrJrLrr r r rrzBucketStorageUri.get_corscCsD|d|||}|jdkr|||dS|||dS)z#sets or updates a bucket's CORS XMLz set_cors r+N)r rGr8set_corsto_xml)rrrIrJrLr r r rs   zBucketStorageUri.set_corscC |d|||}||S)N get_location)r rGrr`r r r r   zBucketStorageUri.get_locationcCs8|d|jdkrtd|j|||}||S)Nget_storage_classr-z.get_storage_class() not supported for %s URIs.)r r8 ValueErrorrGrr`r r r rs    z"BucketStorageUri.get_storage_classcCs>|d|jdkrtd|j|||}|||dS)z!Updates a bucket's storage class.set_storage_classr-z.set_storage_class() not supported for %s URIs.N)r r8rrGr)r storage_classrIrJrLr r r rs   z"BucketStorageUri.set_storage_classcCs(|d|||}|||j||S)Nget_subresource)r rGrr!)r subresourcerIrJrCrLr r r rrMz BucketStorageUri.get_subresourcecCs|d|jdkrtd|j|jr1|rtd|||}||d|j||||dS|jrD| ||}|||||dSt d|j)Nadd_group_email_grantr-z2add_group_email_grant() not supported for %s URIs.zDadd_group_email_grant() on key-ful URI cannot specify recursive=Truer]z-add_group_email_grant() on bucket-less URI %s) r r8rr!r\rr rrrGr)r permission email_address recursiverIrJr]rLr r r rs&     z&BucketStorageUri.add_group_email_grantcC\|d|js|||}|||||dS|||}||d|j|||dS)Nadd_email_grantr])r r!rGrr\rr )rrrrrIrJrLr]r r r rs    z BucketStorageUri.add_email_grantcCr)Nadd_user_grantr])r r!rGrr\rr )rruser_idrrIrJrLr]r r r rs   zBucketStorageUri.add_user_grantcCs|d||}||S)Nz list_grants )r rG list_grantsrrJrLr r r rs   zBucketStorageUri.list_grantscCdS)3Returns True if this URI names a file or directory.Fr rr r r is_file_uri zBucketStorageUri.is_file_uricCr)2Returns True if this URI names a bucket or object.Tr rr r r is_cloud_urirzBucketStorageUri.is_cloud_uricC t|j S)z Returns True if this URI names a directory or bucket. Will return False for bucket subdirs; providing bucket subdir semantics needs to be done by the caller (like gsutil does). r~r!rr r r names_containers z BucketStorageUri.names_containercC t|jS)z0Returns True if this URI names a file or object.rrr r r names_singleton z BucketStorageUri.names_singletoncCrz+Returns True if this URI names a directory.Fr rr r r names_directoryrz BucketStorageUri.names_directorycCr)*Returns True if this URI names a provider.)r~rrr r r names_provider"rzBucketStorageUri.names_providercCst|jo t|j S)(Returns True if this URI names a bucket.)r~rr!rr r r names_bucket&szBucketStorageUri.names_bucketcCr)&Returns True if this URI names a file.Fr rr r r names_file*rzBucketStorageUri.names_filecC|S))Returns True if this URI names an object.rrr r r names_object.zBucketStorageUri.names_objectcCr)z8Returns True if this URI represents input/output stream.Fr rr r r is_stream2rzBucketStorageUri.is_streamrNcCsB|d|}|jdkr||j||||S||j|||S)Nzcreate_bucket r-)r rAr8 create_bucketr)rrJlocationpolicyrr[r r r r6s  zBucketStorageUri.create_bucketcCs |d|}||j|S)N delete_bucket)r rArrrrJr[r r r rBs zBucketStorageUri.delete_bucketcCs|}||SrB)rAget_all_bucketsrr r r rGs z BucketStorageUri.get_all_bucketscCs"|}|j}||d|j|S)Nrp)rArprr )rr[rpr r r rKszBucketStorageUri.get_providerc Csd|d|p |jp d}|||}|jr#|j||||j||ddS|p'|j}|||||dS)zSets or updates a bucket's ACL.set_aclrNrD if_generationif_metagenerationN)r r!rGrDrrC) r acl_or_strrrIrJrCrrrLr r r rQs    zBucketStorageUri.set_aclc Csf|d|p |jp d}|||}|jr#|j||||j||ddS|p'|j}|j||||ddS)z2Sets or updates a bucket's ACL with an XML string. set_xml_aclrNrrbN)r r!rGrDrrC) r xmlstringrrIrJrCrrrLr r r r_s      zBucketStorageUri.set_xml_aclcC"|d|||||dS)zASets or updates a bucket's default object ACL with an XML string.set_def_xml_aclN)r rGr)rrrIrJr r r rns z BucketStorageUri.set_def_xml_aclcCr)z.Sets or updates a bucket's default object ACL. set_def_aclN)r rGr)rrrIrJrCr r r rss zBucketStorageUri.set_def_aclcCsD|d|jd|d|||}||d|j|||dS)z>Sets or updates a bucket's acl to a predefined (canned) value.set_canned_aclrbr]N)r"r)r\rr rracl_strrIrJrCr]r r r rys  zBucketStorageUri.set_canned_aclcCs8|d|||}||d|j||||dS)zXSets or updates a bucket's default object acl to a predefined (canned) value.zset_def_canned_acl r]N)r r\rr set_def_canned_aclrr r r rs  z#BucketStorageUri.set_def_canned_aclcCs.|d|||}||||j||dS)Nset_subresource)r rGrr!)rrvaluerIrJrCrLr r r rs  z BucketStorageUri.set_subresourcerfc Csn|d|j|d} |jdkr$|rtjd| |||||||} n | ||||||||} || | S)Nset_contents_from_stringrPr-z^Warning: GCS does not support reduced_redundancy; argument ignored by set_contents_from_string)r"r_r8r#r$r%rr) rsrJreplacerhrirrreduced_redundancyr]resultr r r rs     z)BucketStorageUri.set_contents_from_stringc Cs|d|j|d} |jdkr+| j||||||||| | d } | r*|d| jd|n|jd| d| j||||||||| d } || | S)Nset_contents_from_filerPr-)sizerewindres_upload_handler)r)rr)r"r_r8rrrDr)r) rrdrJrrhrirrrrrr]rr r r rs*     z'BucketStorageUri.set_contents_from_filec Cs:|d|d|}|j||||||d}|||S)Nset_contents_from_streamF)rr)r"r_rr) rrdrJrrhrrdst_keyrr r r rs    z)BucketStorageUri.set_contents_from_streamSTANDARDc Cs\|d|jd|d} | r| j|j|||||||| | d S| j|j||||||||| d S)zReturns newly created key.copy_keyF)rIrJ) new_key_namesrc_bucket_name src_key_namemetadatar preserve_acl encrypt_keyrJ query_argssrc_generation) rrrrsrc_version_idrrrrJr)r"rGrr!) rrrrrrrrrJrr dst_bucketr r r rs$ zBucketStorageUri.copy_keycCs*|d|||}|j|||ddS)Nenable_loggingrP)r rGr)r target_bucket target_prefixrIrJrCrLr r r rs  zBucketStorageUri.enable_loggingcCs&|d|||}|j|ddS)Ndisable_loggingrP)r rGrrrIrJrCrLr r r rs  z BucketStorageUri.disable_loggingcCs"|d|||}|j|dS)Nget_logging_configrP)r rGrrr r r rraz#BucketStorageUri.get_logging_configcCs>|d|||}|s|s||dS||||dS)Nset_website_config)r rGdelete_website_configurationconfigure_website)rmain_page_suffix error_keyrIrJrLr r r rs  z#BucketStorageUri.set_website_configcCr)Nget_website_config)r rGget_website_configurationr`r r r rrz#BucketStorageUri.get_website_configcCs |d|d|}||S)Nget_versioning_configF)r rGget_versioning_statusrr r r rrz&BucketStorageUri.get_versioning_configcCs"|d|d|}|||S)Nconfigure_versioningF)r rGr)renabledrJrLr r r rraz%BucketStorageUri.configure_versioningcCs|dj||||dS)NFrP)r\set_remote_metadata)r metadata_plusmetadata_minusrrJr r r set_metadatas zBucketStorageUri.set_metadatacCsT|dg}|D]}|||j|d_q |j|||d|_||S)Ncompose) content_typerJ)r"appendr_rDr r)r componentsr rJcomponent_keyssurir r r r  s zBucketStorageUri.composecCr)z+Returns a bucket's lifecycle configuration.get_lifecycle_config lifecycle)r rGrrr )rrIrJrLlifecycle_configr r r rrz%BucketStorageUri.get_lifecycle_configcCs&|d|||}|||dS)z3Sets or updates a bucket's lifecycle configuration.configure_lifecycleN)r rGr)rrrIrJrLr r r rs  z$BucketStorageUri.configure_lifecyclecCs8|d|jdkrtd|j|d|}||S)Nget_billing_configr-z/get_billing_config() not supported for %s URIs.F)r r8rrGrrr r r r$s    z#BucketStorageUri.get_billing_configcCs@|d|jdkrtd|j|||}|j||ddS)z1Sets or updates a bucket's billing configuration.configure_billingr-z.configure_billing() not supported for %s URIs.)requester_paysrJN)r r8rrGr)rrrIrJrLr r r r-s   z"BucketStorageUri.configure_billingcCs:|d|jdkrtd|j|||}|j|dS)z0Returns a GCS bucket's encryption configuration.get_encryption_configr-z2get_encryption_config() not supported for %s URIs.rP)r r8rrGrr`r r r r8s    z&BucketStorageUri.get_encryption_configcCs(|d|||}|j||ddS)z-Sets a GCS bucket's encryption configuration.set_encryption_config)default_kms_key_namerJN)r rGr)rrrIrJrLr r r rCs   z&BucketStorageUri.set_encryption_configcCs6|js td|j||}|j|j|d}t|S)z8Returns True if the object exists or False if it doesn'tzexists on object-less URI (%s)rP)r!rr rGr\r~)rrJrLr]r r r existsKs  zBucketStorageUri.exists)NNrNTNNFrurtrv)FFNrB)NrNNN)rNFNNNN)NTNrfNNF) NTNrfNNNFN)NTNNF)NNrFFNNN)NFNN)NNFNrs)NFN)Drwrxryrzdelimset capabilitiesr rrrr\rFrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r rrrrrrrr r r r rs 1                                         rc@seZdZdZejZd ddZddZddZ d d Z d d Z d dZ ddZ ddZddZddZddZddZddZd!ddZdS)"FileStorageUriz StorageUri subclass that handles files in the local file system. Callers should instantiate this class by calling boto.storage_uri(). See file/README about how we map StorageUri operations onto a file system. FcCs,d|_d|_||_d||_||_||_dS)aInstantiate a FileStorageUri from a path name. @type object_name: string @param object_name: object name @type debug: boolean @param debug: whether to enable debugging on this StorageUri After instantiation the components are available in the following fields: uri, scheme, bucket_name (always blank for this "anonymous" bucket), object_name. r1rNzfile://N)r8rr!r r=stream)rr!r=rr r r r ^s    zFileStorageUri.__init__cCst||j|jS)zInstantiate a FileStorageUri from the current FileStorageUri, but replacing the object_name. @type new_name: string @param new_name: new object name )rr=r rr r r rrsz!FileStorageUri.clone_replace_namecCr)rTr rr r r r{rzFileStorageUri.is_file_uricCr)rFr rr r r rrzFileStorageUri.is_cloud_uricCr)z5Returns True if this URI names a directory or bucket.)rrr r r rrzFileStorageUri.names_containercCs | S)zs   Te