o
    ȷeO                     @   sx   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 d dlmZ G dd de	Z
G dd de
ZG d	d
 d
e
ZdS )    N)DeleteMarkerBotoClientError)InvalidUriErrorc                   @   s   e Zd ZdZdZdZi Zdd Zdd Zdd Z	d	d
 Z
dd Zdd Zdd Zd.ddZdd Z		d/ddZ		d0ddZd1ddZd2ddZd1dd Zd2d!d"Zd.d#d$Z	%			d3d&d'Z		d4d(d)Zd*d+ Zd,d- ZdS )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).
    Nc                 C   s   t d)zBUncallable constructor on abstract base StorageUri class.
        z0Attempt to instantiate abstract StorageUri classr   self r	   G/var/www/ideatree/venv/lib/python3.10/site-packages/boto/storage_uri.py__init__6   s   zStorageUri.__init__c                 C   s   | j S )z%Returns string representation of URI.urir   r	   r	   r
   __repr__<   s   zStorageUri.__repr__c                 C   s   | j |j kS )z#Returns true if two URIs are equal.r   )r   r   r	   r	   r
   equals@      zStorageUri.equalsc                 C   s*   |d u rt dtd||f dd S )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   )r   jointextwrapwrap)r   resplevelr   r	   r	   r
   check_responseD   s   
zStorageUri.check_responsec                 C   .   t t| tr| jstd|| jf d S d S )Nz%s on bucket-less URI (%s))
issubclasstypeBucketStorageUribucket_namer   r   r   function_namer	   r	   r
   _check_bucket_uriL   s
   zStorageUri._check_bucket_uric                 C   r   )Nz%s on object-less URI (%s))r   r   r   object_namer   r   r   r	   r	   r
   _check_object_uriQ   s
   zStorageUri._check_object_uric              	   K   s4   |D ]}|| rt jd||t|| f  qd S )Nz$Warning: %s ignores argument: %s=%s
)sysstderrwritestr)r   r   argsargr	   r	   r
   _warn_about_argsV   s   zStorageUri._warn_about_argsc           	      K   s   t | jpd}t| drd|vr| j|d< || | js| j| jv r+| j| j | _n]| jdkrHddlm	} |||fi || _| j| j| j< n@| jdkrpddl
m} ddlm} | |d	< |||fi || _| j| j| j< n| jd
krddlm} || | _ntd| j | j| j_| jS )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<boto.gs.connection.AWSAuthConnection>}
        @return: A connection to storage service provider of the given URI.
        r	   suppress_consec_slashess3r   )S3Connectiongs)GSConnection)OrdinaryCallingFormatcalling_formatfile)FileConnectionzUnrecognized scheme "%s")dictconnection_argshasattrr*   update
connectionschemeprovider_poolboto.s3.connectionr,   boto.gs.connectionr.   r/   boto.file.connectionr2   r   debug)	r   access_key_idsecret_access_keykwargsr4   r,   r.   r/   r2   r	   r	   r
   connect]   sF   







zStorageUri.connectc                 C   s"   t t| to| jd up| jd uS N)r   r   r   
version_id
generationr   r	   r	   r
   has_version   s   
zStorageUri.has_versionFc                 C   s(   |  d | ||}|| j|||S )N
delete_key)r"   
get_bucketrF   r!   r   validateheadersrC   	mfa_tokenbucketr	   r	   r
   rF      
   
zStorageUri.delete_key c                 C   sD   |  d | j|d}|rdd |j|||dD S |j|||dS )Nlist_bucketrJ   c                 s   s    | ]
}t |ts|V  qd S rB   )
isinstancer   ).0vr	   r	   r
   	<genexpr>   s    z)StorageUri.list_bucket.<locals>.<genexpr>)prefix	delimiterrJ   )r    rG   list_versionslist)r   rU   rV   rJ   all_versionsrL   r	   r	   r
   rO      s   


zStorageUri.list_bucketc                 C   s   |  ||}||S rB   )rG   get_all_keys)r   rI   rJ   rU   rL   r	   r	   r
   rZ      s   
zStorageUri.get_all_keysc                 C   s6   |  d |  }|| j||}| |d| j |S )NrG   rL   )r    rA   rG   r   r   r   )r   rI   rJ   connrL   r	   r	   r
   rG      s
   
zStorageUri.get_bucketc                 C   s:   |  d | ||}|| j||}| |d| j |S )Nget_keykey)r"   rG   r\   r!   r   r   r   rI   rJ   rC   rL   r]   r	   r	   r
   r\      s
   
zStorageUri.get_keyc                 C   s"   |  d | ||}|| jS )Nnew_key)r"   rG   r_   r!   r   rI   rJ   rL   r	   r	   r
   r_         
zStorageUri.new_keyc                 C   sD   |  d | jddd | d |}| |d| j |j|||dS )Nr\   F)rI   r]   rC   )r"   r)   r\   r   r   get_contents_to_file)r   fprJ   rC   r]   r	   r	   r
   get_contents_to_stream   s
   
z!StorageUri.get_contents_to_stream
   c
                 C   sf   |  d | d |}
| |
d| j |	r%|
j|||||||||	d	 d S |
|||||||| d S )Nrc   r]   )	hash_algs)r"   r\   r   r   rc   )r   rd   rJ   cbnum_cbtorrentrC   res_download_handlerresponse_headersrg   r]   r	   r	   r
   rc      s   

zStorageUri.get_contents_to_filec                 C   s8   |  d | ||}| |d| j ||||||S )Nget_contents_as_stringr]   )r"   r\   r   r   rm   )r   rI   rJ   rh   ri   rj   rC   r]   r	   r	   r
   rm      s   
z!StorageUri.get_contents_as_stringc                 C   $   |   }|jj}| |d| j |S )N	acl_class)rA   providerro   r   r   )r   r[   ro   r	   r	   r
   ro         zStorageUri.acl_classc                 C   rn   )Ncanned_acls)rA   rp   rr   r   r   )r   r[   rr   r	   r	   r
   rr      rq   zStorageUri.canned_aclsNNFNNN)rN   rN   NFFNNFN)NNrf   FNNNN)FNNrf   FN)__name__
__module____qualname____doc__r7   r4   r9   r   r   r   r   r    r"   r)   rA   rE   rF   rO   rZ   rG   r\   r_   re   rc   rm   ro   rr   r	   r	   r	   r
   r       sF    
:








r   c                   @   s  e Zd ZdZdZeg Z			dddZd	d
 Zdd Z	dd Z
dddZ		dddZdd Zdd ZdddZdddZdddZdddZddd Zdd!d"Zdd#d$Z		dd%d&Z		dd'd(Z		dd)d*Z		dd+d,Zdd-d.Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Z d;d< Z!d=d> Z"d?d@ Z#dAdB Z$		ddDdEZ%ddFdGZ&ddHdIZ'dJdK Z(		ddLdMZ)		ddNdOZ*ddPdQZ+		ddRdSZ,		ddTdUZ-		ddVdWZ.		ddXdYZ/			dd[d\Z0			dd]d^Z1		dd_d`Z2		a		ddbdcZ3		ddddeZ4ddfdgZ5ddhdiZ6		ddjdkZ7ddldmZ8ddndoZ9ddpdqZ:	ddrdsZ;ddtduZ<ddvdwZ=		ddxdyZ>ddzd{Z?		dd|d}Z@dd~dZA		dddZBdddZCdS )r   z
    StorageUri subclass that handles bucket storage providers.
    Callers should instantiate this class by calling boto.storage_uri().
    /Nr   TFc
           
      C   sb   || _ || _|| _|| _|r|| _|| _|| _|ot|| _|	| _	t
| jp)t
|| _|   dS )a  Instantiate 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)r8   r   r!   r=   r4   r*   rC   intrD   	is_latestboolis_version_specific_build_uri_strings)
r   r8   r   r!   r=   r4   r*   rC   rD   r}   r	   r	   r
   r      s   $zBucketStorageUri.__init__c                 C   s   | j r9| jr9d| j| j | jf | _| jrd| j| jf | _n| jr*d| j| jf | _| jr3| j| _d S | j| _d S | j rGd| j| j f | _d S d| j | _d S )Nz
%s://%s/%sz%s#%sz%s://%s/z%s://)	r   r!   r8   versionless_urirD   version_specific_urirC   r   r   r   r	   r	   r
   r   -  s$   

z#BucketStorageUri._build_uri_stringsc              	   C   s4   |  t|dd t|dd t|dd t|dd  d S )NrC   rD   r}   md5)_update_from_valuesgetattr)r   r]   r	   r	   r
   _update_from_key@  s   



z!BucketStorageUri._update_from_keyc                 C   s$   || _ || _|| _|   || _d S rB   )rC   rD   r}   r   r   )r   rC   rD   r}   r   r	   r	   r
   r   G  s
   
z$BucketStorageUri._update_from_valuesc                 C   st   |  d | ||}|  jdkr|j| j||p| jd}n|  jdkr0|j| j|| jd}| |d| j	 |S )Nr\   awsrb   googlerD   r]   )
r"   rG   get_providernamer\   r!   rC   rD   r   r   r^   r	   r	   r
   r\   N  s   


zBucketStorageUri.get_keyc                 C   sf   |  d | ||}|  jdkr |p| j}|| j|||S |  jdkr1|j| j|| jdS d S )NrF   r   r   r   )r"   rG   r   r   rC   rF   r!   rD   rH   r	   r	   r
   rF   Z  s   


zBucketStorageUri.delete_keyc                 C   s$   |  d t| j| j|| j| jdS )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)r   r!   r=   r*   )r    r   r8   r   r=   r*   r   new_namer	   r	   r
   r   f  s   

z#BucketStorageUri.clone_replace_namec              
   C   sn   |  d d}d}d}t|dr|j}t|dr|j}t|dr#|j}t|j |jj	|j	| j
| j|||dS )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_keyNFrC   rD   r}   )r   r!   r=   r*   rC   rD   r}   )r    r5   rC   rD   r}   r   rp   get_provider_namerL   r   r=   r*   )r   r]   rC   rD   r}   r	   r	   r
   r   s  s(   



z"BucketStorageUri.clone_replace_keyc                 C   sn   |  d | ||}| jpd}|  jdkr$|p| j}||||}n	|j||| jd}| |d| j	 |S )zreturns a bucket's aclget_aclrN   r   r   acl)
r    rG   r!   r   r   rC   r   rD   r   r   )r   rI   rJ   rC   rL   key_namer   r	   r	   r
   r     s   


zBucketStorageUri.get_aclc                 C   4   |  d | ||}||}| |d| j |S )z%returns a bucket's default object aclget_def_aclr   )r    rG   r   r   r   )r   rI   rJ   rL   r   r	   r	   r
   r     
   

zBucketStorageUri.get_def_aclc                 C   r   )zreturns a bucket's CORS XMLget_corscors)r    rG   r   r   r   )r   rI   rJ   rL   r   r	   r	   r
   r     r   zBucketStorageUri.get_corsc                 C   sD   |  d | ||}| jdkr||| dS || | dS )z#sets or updates a bucket's CORS XMLz	set_cors r+   N)r    rG   r8   set_corsto_xml)r   r   rI   rJ   rL   r	   r	   r
   r     s
   

zBucketStorageUri.set_corsc                 C       |  d | ||}||S )Nget_location)r    rG   r   r`   r	   r	   r
   r        

zBucketStorageUri.get_locationc                 C   s8   |  d | jdkrtd| j | ||}||S )Nget_storage_classr-   z.get_storage_class() not supported for %s URIs.)r    r8   
ValueErrorrG   r   r`   r	   r	   r
   r     s   


z"BucketStorageUri.get_storage_classc                 C   s>   |  d | jdkrtd| j | ||}||| dS )z!Updates a bucket's storage class.set_storage_classr-   z.set_storage_class() not supported for %s URIs.N)r    r8   r   rG   r   )r   storage_classrI   rJ   rL   r	   r	   r
   r     s   

z"BucketStorageUri.set_storage_classc                 C   s(   |  d | ||}||| j||S )Nget_subresource)r    rG   r   r!   )r   subresourcerI   rJ   rC   rL   r	   r	   r
   r     rM   z BucketStorageUri.get_subresourcec                 C   s   |  d | jdkrtd| j | jr1|rtd| ||}| |d| j |||| d S | jrD| 	||}||||| d S t
d| j )Nadd_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    r8   r   r!   r\   r   r   r   r   rG   r   )r   
permissionemail_address	recursiverI   rJ   r]   rL   r	   r	   r
   r     s&   


z&BucketStorageUri.add_group_email_grantc                 C   \   |  d | js| ||}||||| d S | ||}| |d| j ||| d S )Nadd_email_grantr]   )r    r!   rG   r   r\   r   r   )r   r   r   r   rI   rJ   rL   r]   r	   r	   r
   r     s   

z BucketStorageUri.add_email_grantc                 C   r   )Nadd_user_grantr]   )r    r!   rG   r   r\   r   r   )r   r   user_idr   rI   rJ   rL   r]   r	   r	   r
   r     s   
zBucketStorageUri.add_user_grantc                 C   s   |  d | |}||S )Nzlist_grants )r    rG   list_grantsr   rJ   rL   r	   r	   r
   r     s   


zBucketStorageUri.list_grantsc                 C      dS )3Returns True if this URI names a file or directory.Fr	   r   r	   r	   r
   is_file_uri
     zBucketStorageUri.is_file_uric                 C   r   )2Returns True if this URI names a bucket or object.Tr	   r   r	   r	   r
   is_cloud_uri  r   zBucketStorageUri.is_cloud_uric                 C      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!   r   r	   r	   r
   names_container  s   z BucketStorageUri.names_containerc                 C   
   t | jS )z0Returns True if this URI names a file or object.r   r   r	   r	   r
   names_singleton     
z BucketStorageUri.names_singletonc                 C   r   z+Returns True if this URI names a directory.Fr	   r   r	   r	   r
   names_directory  r   z BucketStorageUri.names_directoryc                 C   r   )*Returns True if this URI names a provider.)r~   r   r   r	   r	   r
   names_provider"  r   zBucketStorageUri.names_providerc                 C   s   t | jo
t | j S )(Returns True if this URI names a bucket.)r~   r   r!   r   r	   r	   r
   names_bucket&  s   zBucketStorageUri.names_bucketc                 C   r   )&Returns True if this URI names a file.Fr	   r   r	   r	   r
   
names_file*  r   zBucketStorageUri.names_filec                 C      |   S ))Returns True if this URI names an object.r   r   r	   r	   r
   names_object.     zBucketStorageUri.names_objectc                 C   r   )z8Returns True if this URI represents input/output stream.Fr	   r   r	   r	   r
   	is_stream2  r   zBucketStorageUri.is_streamrN   c                 C   sB   |  d |  }| jdkr|| j||||S || j|||S )Nzcreate_bucket r-   )r    rA   r8   create_bucketr   )r   rJ   locationpolicyr   r[   r	   r	   r
   r   6  s   

zBucketStorageUri.create_bucketc                 C   s    |  d |  }|| j|S )Ndelete_bucket)r    rA   r   r   r   rJ   r[   r	   r	   r
   r   B  s   
zBucketStorageUri.delete_bucketc                 C   s   |   }||S rB   )rA   get_all_bucketsr   r	   r	   r
   r   G  s   
z BucketStorageUri.get_all_bucketsc                 C   s"   |   }|j}| |d| j |S )Nrp   )rA   rp   r   r   )r   r[   rp   r	   r	   r
   r   K  s   zBucketStorageUri.get_providerc           	      C   sd   |  d |p| jpd}| ||}| jr#|j|||| j||d dS |p'| j}||||| dS )zSets or updates a bucket's ACL.set_aclrN   rD   if_generationif_metagenerationN)r    r!   rG   rD   r   rC   )	r   
acl_or_strr   rI   rJ   rC   r   r   rL   r	   r	   r
   r   Q  s   



zBucketStorageUri.set_aclc           	      C   sf   |  d |p| jpd}| ||}| jr#|j|||| j||d dS |p'| j}|j||||d dS )z2Sets or updates a bucket's ACL with an XML string.set_xml_aclrN   r   rb   N)r    r!   rG   rD   r   rC   )	r   	xmlstringr   rI   rJ   rC   r   r   rL   r	   r	   r
   r   _  s   





zBucketStorageUri.set_xml_aclc                 C   "   |  d | |||| dS )zASets or updates a bucket's default object ACL with an XML string.set_def_xml_aclN)r    rG   r   )r   r   rI   rJ   r	   r	   r
   r   n  s   
z BucketStorageUri.set_def_xml_aclc                 C   r   )z.Sets or updates a bucket's default object ACL.set_def_aclN)r    rG   r   )r   r   rI   rJ   rC   r	   r	   r
   r   s  s   
zBucketStorageUri.set_def_aclc                 C   sD   |  d | jd|d | ||}| |d| j ||| dS )z>Sets or updates a bucket's acl to a predefined (canned) value.set_canned_aclrb   r]   N)r"   r)   r\   r   r   r   r   acl_strrI   rJ   rC   r]   r	   r	   r
   r   y  s
   
zBucketStorageUri.set_canned_aclc                 C   s8   |  d | ||}| |d| j |||| dS )zXSets or updates a bucket's default object acl to a predefined
           (canned) value.zset_def_canned_acl r]   N)r    r\   r   r   set_def_canned_aclr   r	   r	   r
   r     s   
z#BucketStorageUri.set_def_canned_aclc                 C   s.   |  d | ||}|||| j|| d S )Nset_subresource)r    rG   r   r!   )r   r   valuerI   rJ   rC   rL   r	   r	   r
   r     s
   
z BucketStorageUri.set_subresourcerf   c	              
   C   sn   |  d | j|d}	| jdkr$|rtjd |	|||||||}
n|	||||||||}
| |	 |
S )Nset_contents_from_stringrP   r-   z^Warning: GCS does not support reduced_redundancy; argument ignored by set_contents_from_string)r"   r_   r8   r#   r$   r%   r   r   )r   srJ   replacerh   ri   r   r   reduced_redundancyr]   resultr	   r	   r
   r     s   


z)BucketStorageUri.set_contents_from_stringc                 C   s   |  d | j|d}| jdkr+|j|||||||||	|
d
}|
r*| d |
jd | n| jd|
d |j|||||||||	d	}| | |S )Nset_contents_from_filerP   r-   )sizerewindres_upload_handler)r   )r   r   )r"   r_   r8   r   r   rD   r)   r   )r   rd   rJ   r   rh   ri   r   r   r   r   r   r]   r   r	   r	   r
   r     s*   



z'BucketStorageUri.set_contents_from_filec           	      C   s:   |  d | d|}|j||||||d}| | |S )Nset_contents_from_streamF)r   r   )r"   r_   r   r   )	r   rd   rJ   r   rh   r   r   dst_keyr   r	   r	   r
   r     s   


z)BucketStorageUri.set_contents_from_streamSTANDARDc                 C   s\   |  d | jd|d}|
r|j| j||||||||	|
d
S |j| j|||||||||	d
S )zReturns newly created key.copy_keyF)rI   rJ   )
new_key_namesrc_bucket_namesrc_key_namemetadatar   preserve_aclencrypt_keyrJ   
query_argssrc_generation)
r   r   r   r   src_version_idr   r   r   rJ   r   )r"   rG   r   r!   )r   r   r   r   r   r   r   r   rJ   r   r   
dst_bucketr	   r	   r
   r     s$   
zBucketStorageUri.copy_keyc                 C   s*   |  d | ||}|j|||d d S )Nenable_loggingrP   )r    rG   r   )r   target_buckettarget_prefixrI   rJ   rC   rL   r	   r	   r
   r     s   
zBucketStorageUri.enable_loggingc                 C   s&   |  d | ||}|j|d d S )Ndisable_loggingrP   )r    rG   r   r   rI   rJ   rC   rL   r	   r	   r
   r     s   
z BucketStorageUri.disable_loggingc                 C   s"   |  d | ||}|j|dS )Nget_logging_configrP   )r    rG   r   r   r	   r	   r
   r     ra   z#BucketStorageUri.get_logging_configc                 C   s>   |  d | ||}|s|s|| d S |||| d S )Nset_website_config)r    rG   delete_website_configurationconfigure_website)r   main_page_suffix	error_keyrI   rJ   rL   r	   r	   r
   r     s
   
z#BucketStorageUri.set_website_configc                 C   r   )Nget_website_config)r    rG   get_website_configurationr`   r	   r	   r
   r     r   z#BucketStorageUri.get_website_configc                 C   s    |  d | d|}||S )Nget_versioning_configF)r    rG   get_versioning_statusr   r	   r	   r
   r    r   z&BucketStorageUri.get_versioning_configc                 C   s"   |  d | d|}|||S )Nconfigure_versioningF)r    rG   r  )r   enabledrJ   rL   r	   r	   r
   r    ra   z%BucketStorageUri.configure_versioningc                 C   s   |  dj||||dS )NFrP   )r\   set_remote_metadata)r   metadata_plusmetadata_minusr   rJ   r	   r	   r
   set_metadata  s
   zBucketStorageUri.set_metadatac                 C   sT   |  d g }|D ]}||  |j|d _q	|  j|||d| _|   | S )Ncompose)content_typerJ   )r"   appendr_   rD   r
  r   )r   
componentsr  rJ   component_keyssurir	   r	   r
   r
  
  s   
zBucketStorageUri.composec                 C   r   )z+Returns a bucket's lifecycle configuration.get_lifecycle_config	lifecycle)r    rG   r  r   r   )r   rI   rJ   rL   lifecycle_configr	   r	   r
   r    r   z%BucketStorageUri.get_lifecycle_configc                 C   s&   |  d | ||}||| dS )z3Sets or updates a bucket's lifecycle configuration.configure_lifecycleN)r    rG   r  )r   r  rI   rJ   rL   r	   r	   r
   r    s   
z$BucketStorageUri.configure_lifecyclec                 C   s8   |  d | jdkrtd| j | d|}||S )Nget_billing_configr-   z/get_billing_config() not supported for %s URIs.F)r    r8   r   rG   r  r   r	   r	   r
   r  $  s   


z#BucketStorageUri.get_billing_configc                 C   s@   |  d | jdkrtd| j | ||}|j||d dS )z1Sets or updates a bucket's billing configuration.configure_billingr-   z.configure_billing() not supported for %s URIs.)requester_paysrJ   N)r    r8   r   rG   r  )r   r  rI   rJ   rL   r	   r	   r
   r  -  s   

z"BucketStorageUri.configure_billingc                 C   s:   |  d | jdkrtd| j | ||}|j|dS )z0Returns a GCS bucket's encryption configuration.get_encryption_configr-   z2get_encryption_config() not supported for %s URIs.rP   )r    r8   r   rG   r  r`   r	   r	   r
   r  8  s   

z&BucketStorageUri.get_encryption_configc                 C   s(   |  d | ||}|j||d dS )z-Sets a GCS bucket's encryption configuration.set_encryption_config)default_kms_key_namerJ   N)r    rG   r  )r   r  rI   rJ   rL   r	   r	   r
   r  C  s
   

z&BucketStorageUri.set_encryption_configc                 C   s6   | j s
td| j | |}|j| j |d}t|S )z8Returns True if the object exists or False if it doesn'tzexists on object-less URI (%s)rP   )r!   r   r   rG   r\   r~   )r   rJ   rL   r]   r	   r	   r
   existsK  s
   
zBucketStorageUri.exists)NNr   NTNNFru   rt   rv   )FFNrB   )NrN   NN)rN   FNNNN)NTNrf   NNF)	NTNrf   NNNFN)NTNNF)NNr   FFNNN)NFNN)NNFNrs   )NFN)Drw   rx   ry   rz   delimsetcapabilitiesr   r   r   r   r\   rF   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   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      s    
1






	















	
	










	






	


r   c                   @   s   e Zd ZdZejZd ddZdd Zdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd!ddZdS )"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.
    Fc                 C   s,   d| _ d| _|| _d| | _|| _|| _dS )a  Instantiate 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.
        r1   rN   zfile://N)r8   r   r!   r   r=   stream)r   r!   r=   r   r	   r	   r
   r   ^  s   

zFileStorageUri.__init__c                 C   s   t || j| jS )zInstantiate a FileStorageUri from the current FileStorageUri,
        but replacing the object_name.

        @type new_name: string
        @param new_name: new object name
        )r  r=   r   r   r	   r	   r
   r   r  s   z!FileStorageUri.clone_replace_namec                 C   r   )r   Tr	   r   r	   r	   r
   r   {  r   zFileStorageUri.is_file_uric                 C   r   )r   Fr	   r   r	   r	   r
   r     r   zFileStorageUri.is_cloud_uric                 C   r   )z5Returns True if this URI names a directory or bucket.)r   r   r	   r	   r
   r     r   zFileStorageUri.names_containerc                 C   s
   |    S )z<Returns True if this URI names a file (or stream) or object.)r   r   r	   r	   r
   r     r   zFileStorageUri.names_singletonc                 C   s   | j rdS tj| jS r   )r   ospathisdirr!   r   r	   r	   r
   r     s   zFileStorageUri.names_directoryc                 C   r   )r   Fr	   r   r	   r	   r
   r     r   zFileStorageUri.names_providerc                 C   r   )r   Fr	   r   r	   r	   r
   r     r   zFileStorageUri.names_bucketc                 C   r   )r   r   r   r	   r	   r
   r     r   zFileStorageUri.names_filec                 C   r   )r   Fr	   r   r	   r	   r
   r     r   zFileStorageUri.names_objectc                 C   r   )zAReturns True if this URI represents input/output stream.
        )r~   r   r   r	   r	   r
   r     s   
zFileStorageUri.is_streamc                 C   s   |     dS )z$Closes the underlying file.
        N)r\   closer   r	   r	   r
   r$    s   zFileStorageUri.closeNc                 C   s   t j| jS )z6Returns True if the file exists or False if it doesn't)r!  r"  r  r!   )r   _headers_not_usedr	   r	   r
   r    s   zFileStorageUri.exists)FrB   )rw   rx   ry   rz   r!  sepr  r   r   r   r   r   r   r   r   r   r   r   r   r$  r  r	   r	   r	   r
   r  T  s"    
	r  )botor!  r#   r   boto.s3.deletemarkerr   boto.exceptionr   r   objectr   r   r  r	   r	   r	   r
   <module>   s    T    e