B
    ?F[f                 @   s`   d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ G dd deZ	G dd	 d	eZ
d
S )    )Bucket)S3Connection)SubdomainCallingFormat)check_lowercase_bucketname)get_utf8_valuec               @   s   e Zd ZdZdZdS )LocationZUSEUN)__name__
__module____qualname__DEFAULTr    r   r   1lib/python3.7/site-packages/boto/gs/connection.pyr      s   r   c                   sb   e Zd ZdZdZddddddddedde ddf fdd	Zdejdd	fd
dZ	dddZ
  ZS )GSConnectionzstorage.googleapis.comz)Signature=%s&Expires=%d&GoogleAccessId=%sNTr   /c                s4   t t| j|||||||||	|
|||dt|d d S )NZgoogle)suppress_consec_slashes)superr   __init__r   )selfZgs_access_key_idZgs_secret_access_keyZ	is_secureZportproxyZ
proxy_portZ
proxy_userZ
proxy_passZhostdebugZhttps_connection_factoryZcalling_formatpathr   )	__class__r   r   r   %   s
    
zGSConnection.__init__ZSTANDARDc             C   s   t | |r*|r||| jj< n| jj|i}|s4tj}d| }|rJd| }nd}d||f }| jdt||t|d}	|	 }
|	jdkr| j	|	j|	j
|
|	jdkr| | |S | j|	j|	j
|
d	S )
a  
        Creates a new bucket. By default it's located in the USA. You can
        pass Location.EU to create bucket in the EU. You can also pass
        a LocationConstraint for where the bucket should be located, and
        a StorageClass describing how the data should be stored.

        :type bucket_name: string
        :param bucket_name: The name of the new bucket.

        :type headers: dict
        :param headers: Additional headers to pass along with the request to GCS.

        :type location: :class:`boto.gs.connection.Location`
        :param location: The location of the new bucket.

        :type policy: :class:`boto.gs.acl.CannedACLStrings`
        :param policy: A canned ACL policy that will be applied to the new key
                       in GCS.

        :type storage_class: string
        :param storage_class: Either 'STANDARD' or 'DURABLE_REDUCED_AVAILABILITY'.

        z+<LocationConstraint>%s</LocationConstraint>z<StorageClass>%s</StorageClass> z;<CreateBucketConfiguration>%s%s</CreateBucketConfiguration>ZPUT)headersdatai     N)r   ZproviderZ
acl_headerr   r   Zmake_requestr   readZstatusZstorage_create_errorreasonbucket_classZstorage_response_error)r   bucket_namer   locationZpolicyZstorage_classZlocation_elemZstorage_class_elemr   ZresponseZbodyr   r   r   create_bucket1   s4    



zGSConnection.create_bucketc             C   s"   |  | |}|r|j|dd |S )a  
        Retrieves a bucket by name.

        If the bucket does not exist, an ``S3ResponseError`` will be raised. If
        you are unsure if the bucket exists or not, you can use the
        ``S3Connection.lookup`` method, which will either return a valid bucket
        or ``None``.

        :type bucket_name: string
        :param bucket_name: The name of the bucket

        :type headers: dict
        :param headers: Additional headers to pass along with the request to
            AWS.

        :type validate: boolean
        :param validate: If ``True``, it will try to fetch all keys within the
            given bucket. (Default: ``True``)
        r   )Zmaxkeys)r   Zget_all_keys)r   r    Zvalidater   Zbucketr   r   r   
get_bucketj   s    zGSConnection.get_bucket)TN)r	   r
   r   ZDefaultHostZQueryStringr   r   r   r   r"   r#   __classcell__r   r   )r   r   r       s   7r   N)Zboto.gs.bucketr   Zboto.s3.connectionr   r   r   Z
boto.utilsr   objectr   r   r   r   r   r   <module>   s   