B
    zkF[O£  ã               @   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d3dd „Zd4d!d"„Zd5d#d$„Zd6d&d'„Zd7d(d)„Zd*d+„ Zd,d-„ ZdS )8Ú
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ƒ‚dS )zBUncallable constructor on abstract base StorageUri class.
        z0Attempt to instantiate abstract StorageUri classN)r   )Úself© r   ú/lib/python3.7/site-packages/boto/storage_uri.pyÚ__init__6   s    zStorageUri.__init__c             C   s   | j S )z%Returns string representation of URI.)Úuri)r   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@   s    zStorageUri.equalsc             C   s*   |d kr&t d t d||f d¡¡ƒ‚d S )NÚ
zÉAttempt 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ÚtextwrapZwrap)r   ZrespÚlevelr
   r   r   r   Úcheck_responseD   s    
zStorageUri.check_responsec             C   s*   t t| ƒtƒr&| js&td|| jf ƒ‚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   s*   t t| ƒtƒr&| js&td|| jf ƒ‚d S )Nz%s on object-less URI (%s))r   r   r   Úobject_namer   r
   )r   r   r   r   r   Ú_check_object_uriQ   s    zStorageUri._check_object_uric          	   K   s8   x2|D ]*}|| rt j d||t|| ƒf ¡ qW 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|kr*| j|d< | |¡ | js
| j| jkrX| j| j | _n²| jdkrŽddlm	} |||f|Ž| _| j| j| j< n|| jdkrÚddl
m} ddlm} |ƒ |d	< |||f|Ž| _| j| j| j< n0| jd
krüd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)ÚOrdinaryCallingFormatZcalling_formatÚfile)ÚFileConnectionzUnrecognized scheme "%s")ÚdictÚconnection_argsÚhasattrr"   ÚupdateÚ
connectionÚschemeÚprovider_poolZboto.s3.connectionr$   Zboto.gs.connectionr&   r'   Zboto.file.connectionr)   r   Údebug)	r   Zaccess_key_idZsecret_access_keyÚkwargsr+   r$   r&   r'   r)   r   r   r   Úconnect]   s:    









zStorageUri.connectc             C   s"   t t| ƒtƒo | jd k	p | jd k	S )N)r   r   r   Ú
version_idÚ
generation)r   r   r   r   Úhas_version—   s    
zStorageUri.has_versionFc             C   s(   |   d¡ |  ||¡}| | j|||¡S )NÚ
delete_key)r   Ú
get_bucketr7   r   )r   ÚvalidateÚheadersr4   Ú	mfa_tokenÚbucketr   r   r   r7   œ   s    
zStorageUri.delete_keyÚ c             C   sH   |   d¡ | j|d}|r4dd„ |j|||dD ƒS |j|||dS d S )NÚlist_bucket)r:   c             s   s   | ]}t |tƒs|V  qd S )N)Ú
isinstancer   )Ú.0Úvr   r   r   ú	<genexpr>¨   s    z)StorageUri.list_bucket.<locals>.<genexpr>)ÚprefixÚ	delimiterr:   )r   r8   Zlist_versionsÚlist)r   rC   rD   r:   Zall_versionsr<   r   r   r   r>   £   s    

zStorageUri.list_bucketc             C   s   |   ||¡}| |¡S )N)r8   Úget_all_keys)r   r9   r:   rC   r<   r   r   r   rF   ¯   s    zStorageUri.get_all_keysc             C   s6   |   d¡ |  ¡ }| | j||¡}|  |d| j¡ |S )Nr8   r<   )r   r3   r8   r   r   r
   )r   r9   r:   Úconnr<   r   r   r   r8   ³   s
    
zStorageUri.get_bucketc             C   s:   |   d¡ |  ||¡}| | j||¡}|  |d| j¡ |S )NÚget_keyÚkey)r   r8   rH   r   r   r
   )r   r9   r:   r4   r<   rI   r   r   r   rH   º   s
    
zStorageUri.get_keyc             C   s"   |   d¡ |  ||¡}| | j¡S )NÚnew_key)r   r8   rJ   r   )r   r9   r:   r<   r   r   r   rJ   Á   s    
zStorageUri.new_keyc             C   sD   |   d¡ | jddd |  d |¡}|  |d| j¡ |j|||dS )NrH   F)r9   rI   )r4   )r   r!   rH   r   r
   Úget_contents_to_file)r   Úfpr:   r4   rI   r   r   r   Úget_contents_to_streamÆ   s
    
z!StorageUri.get_contents_to_streamé
   c
             C   sd   |   d¡ |  d |¡}
|  |
d| j¡ |	rH|
j|||||||||	d	 n|
 ||||||||¡ d S )NrK   rI   )Ú	hash_algs)r   rH   r   r
   rK   )r   rL   r:   ÚcbÚnum_cbÚtorrentr4   Zres_download_handlerZresponse_headersrO   rI   r   r   r   rK   Í   s    

zStorageUri.get_contents_to_filec             C   s8   |   d¡ |  ||¡}|  |d| j¡ | |||||¡S )NÚget_contents_as_stringrI   )r   rH   r   r
   rS   )r   r9   r:   rP   rQ   rR   r4   rI   r   r   r   rS   Þ   s
    
z!StorageUri.get_contents_as_stringc             C   s$   |   ¡ }|jj}|  |d| j¡ |S )NÚ	acl_class)r3   ÚproviderrT   r   r
   )r   rG   rT   r   r   r   rT   æ   s    zStorageUri.acl_classc             C   s$   |   ¡ }|jj}|  |d| j¡ |S )NÚcanned_acls)r3   rU   rV   r   r
   )r   rG   rV   r   r   r   rV   ì   s    zStorageUri.canned_acls)NN)FNNN)r=   r=   NF)FNN)FN)FNN)FN)NN)NNrN   FNNNN)FNNrN   FN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r.   r+   r0   r	   r   r   r   r   r   r!   r3   r6   r7   r>   rF   r8   rH   rJ   rM   rK   rS   rT   rV   r   r   r   r   r       s<   
: 
 





   
 
r   c            	   @   s^  e Zd ZdZdZeg ƒZd„dd„Zd	d
„ Zdd„ Z	dd„ Z
d…dd„Zd†dd„Zdd„ Zdd„ Zd‡dd„Zdˆdd„Zd‰dd„ZdŠdd„Zd‹dd „ZdŒd!d"„Zdd#d$„ZdŽd%d&„Zdd'd(„Zdd)d*„Zd‘d+d,„Zd’d-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$d“dDdE„Z%d”dFdG„Z&d•dHdI„Z'dJdK„ Z(d–dLdM„Z)d—dNdO„Z*d˜dPdQ„Z+d™dRdS„Z,dšdTdU„Z-d›dVdW„Z.dœdXdY„Z/dd[d\„Z0džd]d^„Z1dŸd_d`„Z2d dbdc„Z3d¡ddde„Z4d¢dfdg„Z5d£dhdi„Z6d¤djdk„Z7d¥dldm„Z8d¦dndo„Z9d§dpdq„Z:d¨drds„Z;d©dtdu„Z<dªdvdw„Z=d«dxdy„Z>d¬dzd{„Z?d­d|d}„Z@d®d~d„ZAd¯d€d„ZBd°d‚dƒ„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"|| _|| _|| _|o8t|ƒ| _|	| _	t
| jƒpRt
|ƒ| _|  ¡  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)r/   r   r   r1   r+   r"   r4   Úintr5   Ú	is_latestÚboolÚis_version_specificÚ_build_uri_strings)
r   r/   r   r   r1   r+   r"   r4   r5   r]   r   r   r   r	   ü   s    $zBucketStorageUri.__init__c             C   s˜   | j rn| jrnd| j| j | jf | _| jr<d| j| jf | _n| jrTd| j| jf | _| jrd| j| _q”| j| _n&| j rˆd| j| j f | _nd| j | _d S )Nz
%s://%s/%sz%s#%sz%s://%s/z%s://)	r   r   r/   Zversionless_urir5   Zversion_specific_urir4   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 )Nr4   r5   r]   Úmd5)Ú_update_from_valuesÚgetattr)r   rI   r   r   r   Ú_update_from_key@  s
    


z!BucketStorageUri._update_from_keyc             C   s$   || _ || _|| _|  ¡  || _d S )N)r4   r5   r]   r`   ra   )r   r4   r5   r]   ra   r   r   r   rb   G  s
    z$BucketStorageUri._update_from_valuesc             C   st   |   d¡ |  ||¡}|  ¡ jdkr>|j| j||p6| jd}n"|  ¡ jdkr`|j| j|| jd}|  |d| j	¡ |S )NrH   Úaws)r4   Úgoogle)r5   rI   )
r   r8   Úget_providerÚnamerH   r   r4   r5   r   r
   )r   r9   r:   r4   r<   rI   r   r   r   rH   N  s    



zBucketStorageUri.get_keyc             C   sf   |   d¡ |  ||¡}|  ¡ jdkr@|p,| j}| | j|||¡S |  ¡ jdkrb|j| j|| jdS d S )Nr7   re   rf   )r5   )r   r8   rg   rh   r4   r7   r   r5   )r   r9   r:   r4   r;   r<   r   r   r   r7   Z  s    


zBucketStorageUri.delete_keyc             C   s$   |   d¡ t| j| j|| j| jdS )zºInstantiate 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   r1   r"   )r   r   r/   r   r1   r"   )r   Únew_namer   r   r   ri   f  s
    

z#BucketStorageUri.clone_replace_namec          
   C   sn   |   d¡ d}d}d}t|dƒr&|j}t|dƒr6|j}t|dƒrF|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_keyNFr4   r5   r]   )r   r   r1   r"   r4   r5   r]   )r   r,   r4   r5   r]   r   rU   Zget_provider_namer<   rh   r1   r"   )r   rI   r4   r5   r]   r   r   r   rk   s  s&    



z"BucketStorageUri.clone_replace_keyc             C   sn   |   d¡ |  ||¡}| jpd}|  ¡ jdkrH|p6| j}| |||¡}n|j||| jd}|  |d| j	¡ |S )zreturns a bucket's aclÚget_aclr=   re   )r5   Úacl)
r   r8   r   rg   rh   r4   rl   r5   r   r
   )r   r9   r:   r4   r<   Úkey_namerm   r   r   r   rl     s    


zBucketStorageUri.get_aclc             C   s4   |   d¡ |  ||¡}| |¡}|  |d| j¡ |S )z%returns a bucket's default object aclÚget_def_aclrm   )r   r8   ro   r   r
   )r   r9   r:   r<   rm   r   r   r   ro   Ÿ  s
    

zBucketStorageUri.get_def_aclc             C   s4   |   d¡ |  ||¡}| |¡}|  |d| j¡ |S )zreturns a bucket's CORS XMLÚget_corsÚcors)r   r8   rp   r   r
   )r   r9   r:   r<   rq   r   r   r   rp   §  s
    

zBucketStorageUri.get_corsc             C   sB   |   d¡ |  ||¡}| jdkr.| ||¡ n| | ¡ |¡ dS )z#sets or updates a bucket's CORS XMLz	set_cors r#   N)r   r8   r/   Úset_corsZto_xml)r   rq   r9   r:   r<   r   r   r   rr   ¯  s
    

zBucketStorageUri.set_corsc             C   s    |   d¡ |  ||¡}| |¡S )NÚget_location)r   r8   rs   )r   r9   r:   r<   r   r   r   rs   ¸  s    
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   r/   Ú
ValueErrorr8   rt   )r   r9   r:   r<   r   r   r   rt   ½  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   r/   ru   r8   rv   )r   Ústorage_classr9   r:   r<   r   r   r   rv   Ç  s    


z"BucketStorageUri.set_storage_classc             C   s(   |   d¡ |  ||¡}| || j||¡S )NÚget_subresource)r   r8   rx   r   )r   Úsubresourcer9   r:   r4   r<   r   r   r   rx   Ò  s    
z BucketStorageUri.get_subresourcec             C   s–   |   d¡ | jdkr"td| j ƒ‚| jr`|r4tdƒ‚|  ||¡}|  |d| j¡ | |||¡ n2| jr„|  	||¡}| ||||¡ nt
d| j ƒ‚d S )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=TruerI   z-add_group_email_grant() on bucket-less URI %s)r   r/   ru   r   rH   r   r
   rz   r   r8   r   )r   Ú
permissionÚemail_addressÚ	recursiver9   r:   rI   r<   r   r   r   rz   Ù  s     



z&BucketStorageUri.add_group_email_grantc             C   sZ   |   d¡ | js.|  ||¡}| ||||¡ n(|  ||¡}|  |d| j¡ | ||¡ d S )NÚadd_email_grantrI   )r   r   r8   r~   rH   r   r
   )r   r{   r|   r}   r9   r:   r<   rI   r   r   r   r~   î  s    

z BucketStorageUri.add_email_grantc             C   sZ   |   d¡ | js.|  ||¡}| ||||¡ n(|  ||¡}|  |d| j¡ | ||¡ d S )NÚadd_user_grantrI   )r   r   r8   r   rH   r   r
   )r   r{   Zuser_idr}   r9   r:   r<   rI   r   r   r   r   ú  s    
zBucketStorageUri.add_user_grantc             C   s   |   d¡ |  |¡}| |¡S )Nzlist_grants )r   r8   Úlist_grants)r   r:   r<   r   r   r   r€     s    

zBucketStorageUri.list_grantsc             C   s   dS )z3Returns True if this URI names a file or directory.Fr   )r   r   r   r   Úis_file_uri
  s    zBucketStorageUri.is_file_uric             C   s   dS )z2Returns True if this URI names a bucket or object.Tr   )r   r   r   r   Úis_cloud_uri  s    zBucketStorageUri.is_cloud_uric             C   s   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   s
   t | jƒS )z0Returns True if this URI names a file or object.)r^   r   )r   r   r   r   Únames_singleton  s    z BucketStorageUri.names_singletonc             C   s   dS )z+Returns True if this URI names a directory.Fr   )r   r   r   r   Únames_directory  s    z BucketStorageUri.names_directoryc             C   s   t | j ƒS )z*Returns True if this URI names a provider.)r^   r   )r   r   r   r   Únames_provider"  s    zBucketStorageUri.names_providerc             C   s   t | jƒot | j ƒS )z(Returns True if this URI names a bucket.)r^   r   r   )r   r   r   r   Únames_bucket&  s    zBucketStorageUri.names_bucketc             C   s   dS )z&Returns True if this URI names a file.Fr   )r   r   r   r   Ú
names_file*  s    zBucketStorageUri.names_filec             C   s   |   ¡ S )z)Returns True if this URI names an object.)r„   )r   r   r   r   Únames_object.  s    zBucketStorageUri.names_objectc             C   s   dS )z8Returns True if this URI represents input/output stream.Fr   )r   r   r   r   Ú	is_stream2  s    zBucketStorageUri.is_streamr=   c             C   sF   |   d¡ |  ¡ }| jdkr0| | j||||¡S | | j|||¡S d S )Nzcreate_bucket r%   )r   r3   r/   Úcreate_bucketr   )r   r:   ÚlocationÚpolicyrw   rG   r   r   r   r‹   6  s    

zBucketStorageUri.create_bucketc             C   s    |   d¡ |  ¡ }| | j|¡S )NÚdelete_bucket)r   r3   rŽ   r   )r   r:   rG   r   r   r   rŽ   B  s    
zBucketStorageUri.delete_bucketc             C   s   |   ¡ }| |¡S )N)r3   Úget_all_buckets)r   r:   rG   r   r   r   r   G  s    z BucketStorageUri.get_all_bucketsc             C   s"   |   ¡ }|j}|  |d| j¡ |S )NrU   )r3   rU   r   r
   )r   rG   rU   r   r   r   rg   K  s    zBucketStorageUri.get_providerc       	      C   sb   |   d¡ |p| jpd}|  ||¡}| jrD|j|||| j||d n|pL| j}| ||||¡ dS )zSets or updates a bucket's ACL.Úset_aclr=   )r5   Úif_generationÚif_metagenerationN)r   r   r8   r5   r   r4   )	r   Ú
acl_or_strrn   r9   r:   r4   r‘   r’   r<   r   r   r   r   Q  s    


zBucketStorageUri.set_aclc       	      C   sd   |   d¡ |p| jpd}|  ||¡}| jrD|j|||| j||d n|pL| j}|j||||d dS )z2Sets or updates a bucket's ACL with an XML string.Úset_xml_aclr=   )r5   r‘   r’   )r4   N)r   r   r8   r5   r”   r4   )	r   Ú	xmlstringrn   r9   r:   r4   r‘   r’   r<   r   r   r   r”   _  s    



zBucketStorageUri.set_xml_aclc             C   s"   |   d¡ |  ||¡ ||¡ dS )zASets or updates a bucket's default object ACL with an XML string.Úset_def_xml_aclN)r   r8   r–   )r   r•   r9   r:   r   r   r   r–   n  s    
z BucketStorageUri.set_def_xml_aclc             C   s"   |   d¡ |  ||¡ ||¡ dS )z.Sets or updates a bucket's default object ACL.Úset_def_aclN)r   r8   r—   )r   r“   r9   r:   r4   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_acl)r4   rI   N)r   r!   rH   r   r
   r˜   )r   Úacl_strr9   r:   r4   rI   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 rI   N)r   rH   r   r
   Úset_def_canned_acl)r   r™   r9   r:   r4   rI   r   r   r   rš   ‚  s    
z#BucketStorageUri.set_def_canned_aclc             C   s.   |   d¡ |  ||¡}| ||| j||¡ d S )NÚset_subresource)r   r8   r›   r   )r   ry   Úvaluer9   r:   r4   r<   r   r   r   r›   ‹  s    
z BucketStorageUri.set_subresourcerN   c	          
   C   sn   |   d¡ | j|d}	| jdkrH|r0tj d¡ |	 |||||||¡}
n|	 ||||||||¡}
|  |	¡ |
S )NÚset_contents_from_string)r:   r%   z^Warning: GCS does not support reduced_redundancy; argument ignored by set_contents_from_string)r   rJ   r/   r   r   r   r   rd   )r   Úsr:   ÚreplacerP   rQ   r   ra   Úreduced_redundancyrI   Úresultr   r   r   r   ’  s    


z)BucketStorageUri.set_contents_from_stringc             C   sŽ   |   d¡ | j|d}| jdkrV|j|||||||||	|
d
}|
r€|  d |
jd |¡ n*| jd|
d |j|||||||||	d	}|  |¡ |S )NÚset_contents_from_file)r:   r%   )ÚsizeÚrewindÚres_upload_handler)r¥   )r£   r¤   )r   rJ   r/   r¢   rb   r5   r!   rd   )r   rL   r:   rŸ   rP   rQ   r   ra   r£   r¤   r¥   rI   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   rJ   r¦   rd   )	r   rL   r:   rŸ   rP   r   r    Z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 dS )zReturns newly created key.Úcopy_keyF)r9   r:   )
Únew_key_nameÚsrc_bucket_nameÚsrc_key_nameÚmetadatarw   Úpreserve_aclÚencrypt_keyr:   Ú
query_argsÚsrc_generation)
r©   rª   r«   r¬   Úsrc_version_idrw   r­   r®   r:   r¯   N)r   r8   r¨   r   )r   rª   r«   r¬   r±   rw   r­   r®   r:   r¯   r°   Z
dst_bucketr   r   r   r¨   Ä  s     
zBucketStorageUri.copy_keyc             C   s*   |   d¡ |  ||¡}|j|||d d S )NÚenable_logging)r:   )r   r8   r²   )r   Ztarget_bucketZtarget_prefixr9   r:   r4   r<   r   r   r   r²   Û  s    
zBucketStorageUri.enable_loggingc             C   s&   |   d¡ |  ||¡}|j|d d S )NÚdisable_logging)r:   )r   r8   r³   )r   r9   r:   r4   r<   r   r   r   r³   á  s    
z BucketStorageUri.disable_loggingc             C   s"   |   d¡ |  ||¡}|j|dS )NÚget_logging_config)r:   )r   r8   r´   )r   r9   r:   r4   r<   r   r   r   r´   æ  s    
z#BucketStorageUri.get_logging_configc             C   s<   |   d¡ |  ||¡}|s*|s*| |¡ n| |||¡ d S )NÚset_website_config)r   r8   Zdelete_website_configurationZconfigure_website)r   Zmain_page_suffixZ	error_keyr9   r:   r<   r   r   r   rµ   ë  s
    
z#BucketStorageUri.set_website_configc             C   s    |   d¡ |  ||¡}| |¡S )NÚget_website_config)r   r8   Zget_website_configuration)r   r9   r:   r<   r   r   r   r¶   ô  s    
z#BucketStorageUri.get_website_configc             C   s    |   d¡ |  d|¡}| |¡S )NÚget_versioning_configF)r   r8   Zget_versioning_status)r   r:   r<   r   r   r   r·   ù  s    
z&BucketStorageUri.get_versioning_configc             C   s"   |   d¡ |  d|¡}| ||¡S )NÚconfigure_versioningF)r   r8   r¸   )r   Zenabledr:   r<   r   r   r   r¸   þ  s    
z%BucketStorageUri.configure_versioningc             C   s   |   d¡j||||dS )NF)r:   )rH   Zset_remote_metadata)r   Zmetadata_plusZmetadata_minusr­   r:   r   r   r   Úset_metadata  s    zBucketStorageUri.set_metadatac             C   sX   |   d¡ g }x&|D ]}| | ¡ ¡ |j|d _qW |  ¡ j|||d| _|  ¡  | S )NÚcomposeéÿÿÿÿ)Úcontent_typer:   )r   ÚappendrJ   r5   rº   r`   )r   Z
componentsr¼   r:   Zcomponent_keysZsurir   r   r   rº   
  s    

zBucketStorageUri.composec             C   s4   |   d¡ |  ||¡}| |¡}|  |d| j¡ |S )z+Returns a bucket's lifecycle configuration.Úget_lifecycle_configZ	lifecycle)r   r8   r¾   r   r
   )r   r9   r:   r<   Úlifecycle_configr   r   r   r¾     s
    

z%BucketStorageUri.get_lifecycle_configc             C   s&   |   d¡ |  ||¡}| ||¡ dS )z3Sets or updates a bucket's lifecycle configuration.Úconfigure_lifecycleN)r   r8   rÀ   )r   r¿   r9   r:   r<   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   r/   ru   r8   rÁ   )r   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_paysr:   N)r   r/   ru   r8   rÂ   )r   rÃ   r9   r:   r<   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.)r:   )r   r/   ru   r8   rÄ   )r   r9   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_namer:   N)r   r8   rÅ   )r   rÆ   r9   r:   r<   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))r:   )r   r   r
   r8   rH   r^   )r   r:   r<   rI   r   r   r   ÚexistsK  s
    
zBucketStorageUri.exists)NNr   NTNNF)FNN)FNNN)FNN)FN)FN)FN)FN)FN)FN)FNN)FFN)FFN)FFN)N)Nr=   NN)N)N)r=   FNNNN)r=   FNNNN)FN)FNN)FNN)FNN)FNN)NTNrN   NNF)	NTNrN   NNNFN)NTNNF)NNr§   FFNNN)NFNN)FNN)FNN)NNFN)FN)N)N)N)NN)FN)FN)N)FFN)FN)NFN)N)DrW   rX   rY   rZ   ÚdelimÚsetZcapabilitiesr	   r`   rd   rb   rH   r7   ri   rk   rl   ro   rp   rr   rs   rt   rv   rx   rz   r~   r   r€   r   r‚   rƒ   r„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   rŽ   r   rg   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¶     
/
 




	



 
 
 
 


 


 
 

 
 
 
 
  
  
 
	   
 


 






 

	 


 
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.
        r(   r=   zfile://N)r/   r   r   r
   r1   Ústream)r   r   r1   rŠ   r   r   r   r	   ^  s    
zFileStorageUri.__init__c             C   s   t || j| jƒS )z¶Instantiate a FileStorageUri from the current FileStorageUri,
        but replacing the object_name.

        @type new_name: string
        @param new_name: new object name
        )rÊ   r1   rË   )r   rj   r   r   r   ri   r  s    z!FileStorageUri.clone_replace_namec             C   s   dS )z3Returns True if this URI names a file or directory.Tr   )r   r   r   r   r   {  s    zFileStorageUri.is_file_uric             C   s   dS )z2Returns True if this URI names a bucket or object.Fr   )r   r   r   r   r‚     s    zFileStorageUri.is_cloud_uric             C   s   |   ¡ S )z5Returns True if this URI names a directory or bucket.)r…   )r   r   r   r   rƒ   ƒ  s    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„   ‡  s    zFileStorageUri.names_singletonc             C   s   | j r
dS tj | j¡S )z+Returns True if this URI names a directory.F)rË   ÚosÚpathÚisdirr   )r   r   r   r   r…   ‹  s    zFileStorageUri.names_directoryc             C   s   dS )z*Returns True if this URI names a provider.Fr   )r   r   r   r   r†   ‘  s    zFileStorageUri.names_providerc             C   s   dS )z(Returns True if this URI names a bucket.Fr   )r   r   r   r   r‡   •  s    zFileStorageUri.names_bucketc             C   s   |   ¡ S )z&Returns True if this URI names a file.)r„   )r   r   r   r   rˆ   ™  s    zFileStorageUri.names_filec             C   s   dS )z)Returns True if this URI names an object.Fr   )r   r   r   r   r‰     s    zFileStorageUri.names_objectc             C   s
   t | jƒS )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)rH   Úclose)r   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   Z_headers_not_usedr   r   r   rÇ   «  s    zFileStorageUri.exists)F)N)rW   rX   rY   rZ   rÌ   ÚseprÈ   r	   ri   r   r‚   rƒ   r„   r…   r†   r‡   rˆ   r‰   rŠ   rÏ   rÇ   r   r   r   r   rÊ   T  s    
	rÊ   )ZbotorÌ   r   r   Zboto.s3.deletemarkerr   Zboto.exceptionr   r   Úobjectr   r   rÊ   r   r   r   r   Ú<module>   s    T    e